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 burtoninlondon, Today, 12:38 AM
    0 responses
    5 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    14 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Yesterday, 07:51 PM
    0 responses
    13 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,983 views
    3 likes
    Last Post jhudas88  
    Working...
    X