NexusFi: Find Your Edge


Home Menu

 





NT code problem


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one lincor with 4 posts (0 thanks)
    2. looks_two vegasfoster with 1 posts (0 thanks)
    3. looks_3 vvhg with 1 posts (0 thanks)
    4. looks_4 gregid with 1 posts (1 thanks)
    1. trending_up 1,792 views
    2. thumb_up 1 thanks given
    3. group 5 followers
    1. forum 8 posts
    2. attach_file 1 attachments




 
Search this Thread

NT code problem

  #1 (permalink)
lincor
Mt. Martha Victoria Australia
 
Posts: 6 since Oct 2012
Thanks Given: 6
Thanks Received: 1

Greetings. New to the forum, hello all. New to attempted scripting in NT as well.Trying to find a piece of code that will allow me to condense the many lines I have compiled, saying for example, && CCI (50) [0]<CCI (50) [1]...right up to say [20]. Have ordered the C# Dummies book, but not arrived yet. All help appreciated.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Increase in trading performance by 75%
The Elite Circle
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
27 thanks
Diary of a simple price action trader
26 thanks
Tao te Trade: way of the WLD
23 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
9 thanks
  #2 (permalink)
 vegasfoster 
las vegas
 
Experience: Intermediate
Platform: Sierra Chart
Broker: Velocity/IB
Trading: 6E
Posts: 1,145 since Feb 2010
Thanks Given: 304
Thanks Received: 844

Not 100% sure what you are specifically asking in relation to the CCI, but I think you want to know how to loop, something like for (C# Reference)

Reply With Quote
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



lincor View Post
Greetings. New to the forum, hello all. New to attempted scripting in NT as well.Trying to find a piece of code that will allow me to condense the many lines I have compiled, saying for example, && CCI (50) [0]<CCI (50) [1]...right up to say [20]. Have ordered the C# Dummies book, but not arrived yet. All help appreciated.

Why don't you post the code?

Highlight the code and then select "#" from the upper task bar.

With the information you have given us so far, nobody can help you.

Reply With Quote
  #4 (permalink)
 pawnbroker 
Cheltenham
 
Experience: Advanced
Platform: InvestorRT, NinjaTrader
Trading: ES
Posts: 54 since Jan 2012
Thanks Given: 8
Thanks Received: 107

I am new to C# and NinjaScript, but I think that you are looking for something like this.


 
Code
    public class MyCustomIndicator : Indicator
    {
        #region Variables
        // Wizard generated variables
            private int myInput0 = 1; // Default setting for MyInput0
        // User defined variables (add any user defined variables below)
		
		private double minCCI;
		
        #endregion


        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
           
			// Find the lowest value of the 50 period CCI over the last 20 bars
			// This won't change,so only calculate once to improve performance
			if (FirstTickOfBar)
			{
				minCCI = MIN(CCI(50), 20)[0];
			}
			
			// Test each new tick to see if a new low has been found
			if (CCI(50)[0] < minCCI)
			{
				Print("New low found in CCI");
			}
			
        }

Reply With Quote
  #5 (permalink)
lincor
Mt. Martha Victoria Australia
 
Posts: 6 since Oct 2012
Thanks Given: 6
Thanks Received: 1

Hi Pawnbroker,

Appreciate your efforts here !

Will try this tomorrow and let you know how it goes

best wishes

Lincor

Reply With Quote
  #6 (permalink)
lincor
Mt. Martha Victoria Australia
 
Posts: 6 since Oct 2012
Thanks Given: 6
Thanks Received: 1


Fat Tails View Post
Why don't you post the code?

Highlight the code and then select "#" from the upper task bar.

With the information you have given us so far, nobody can help you.

Not too sure how any of this works yet, the forum, and not sure of what you mean by '#' at the task bar Fat Tails, but have taken a snipp of the code and attached it.

So with my small amount of knowledge I know that this is redundant. I have to write a line for each of the look back periods, where I want the indicator to be clear of. In this case, the MACD at a certain setting, has to be clear of itself for 17 bars back. In other words, if this current bar is not the highest during the look back period...1 to 17....a line will not be drawn over price. Hope that helps ?

Attached Thumbnails
Click image for larger version

Name:	code example for BMF.JPG
Views:	110
Size:	52.6 KB
ID:	93359  
Reply With Quote
  #7 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623

You could use something like this:

 
Code
bool validFlag = true;
for (int i = 1; i <= 17; i++)
{
	if !(MACD(3, 10,16)[0] > MACD(3, 10,16)[i])
	{
		validFlag = false;
		break;
	}
}
if (validFlag == true)
{
	EnterLong();
}
PS. # is a button available for you when you post a message on the forum - it is in the same place that you have buttons for changing font, aligning etc.

Reply With Quote
Thanked by:
  #8 (permalink)
lincor
Mt. Martha Victoria Australia
 
Posts: 6 since Oct 2012
Thanks Given: 6
Thanks Received: 1


gregid View Post
You could use something like this:

 
Code
bool validFlag = true;
for (int i = 1; i <= 17; i++)
{
	if !(MACD(3, 10,16)[0] > MACD(3, 10,16)[i])
	{
		validFlag = false;
		break;
	}
}
if (validFlag == true)
{
	EnterLong();
}
PS. # is a button available for you when you post a message on the forum - it is in the same place that you have buttons for changing font, aligning etc.



Hi again Gregid. I tried your suggestion every which way, but the compiler just kept generating errors. Being new, I am assuming the 'bool validFlag and for(int" ...the first two lines, go in the initialize section of the editor. The 'if' statement goes under the 'OnBarUpdate' area. In a few months I'll look back and laugh, but for now, all help appreciated

Reply With Quote
  #9 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824


lincor View Post
Hi again Gregid. I tried your suggestion every which way, but the compiler just kept generating errors. Being new, I am assuming the 'bool validFlag and for(int" ...the first two lines, go in the initialize section of the editor. The 'if' statement goes under the 'OnBarUpdate' area. In a few months I'll look back and laugh, but for now, all help appreciated

The whole block goes into OnBarUpdate.
Posting a screenshot of the errors along with the code generating the errors makes finding the problem much easier.

vvhg

Hic Rhodos, hic salta.
Reply With Quote




Last Updated on November 21, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts