Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to plot indicator for each strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to plot indicator for each strategy

    I looked through some other forum posts and the NinjaTrader documentation, but I cannot find an answer to this. My goal is to display both the hourly ([0]) and daily ([1]) moving average for the "mA" period. How do I display an indicator (SMA in this case) on the chart while optimizing with the Strategy Analyzer?

    Any help is appreciated! Thanks!

    Here's my code:
    Code:
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
    			Add(PeriodType.Day, 1);
    			Add(SMA(Closes[1],mA));
    			Add(SMA(Closes[0],mA));
    			SMA(Closes[1],mA).Plots[0].Pen.Color = Color.Blue;
            }
    
            protected override void OnBarUpdate()
            {			
    			if (BarsInProgress == 0) {						// Only operate on the hourly chart
    				if (Close[0] > SMA(BarsArray[1], mA)[0]) {		// uptrend indicator
    					if (Close[0] > SMA(mA)[0]) {				// long entry signal
    						EnterLong();
    					} else {
    						ExitLong();
    						ExitShort();
    					}
    				} else if (Close[0] < SMA(BarsArray[1],mA)[0]){	// downtrend indicator
    					if (Close[0] < SMA(mA)[0]) {					// short entry signal
    						EnterShort();
    					} else {
    						ExitLong();
    						ExitShort();
    					}
    				}
    			}
           	 }

    #2
    Hello MattR,
    Welcome to the forum.

    A strategy can plot data for the primary series only. You have to create/modify the indicator to plot data for additional dataseries. Heres a reference of multi time frame instruments


    Additionally you may also find this example useful
    When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability


    Please let me know if I can be of any further help.

    Regards,
    Joydeep.
    JoydeepNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    102 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    144 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    71 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    125 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    79 views
    0 likes
    Last Post PaulMohn  
    Working...
    X