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 lightsun47, Today, 03:51 PM
    0 responses
    5 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    8 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    44 views
    0 likes
    Last Post futtrader  
    Started by Option Whisperer, Today, 09:55 AM
    1 response
    14 views
    0 likes
    Last Post bltdavid  
    Started by port119, Today, 02:43 PM
    0 responses
    9 views
    0 likes
    Last Post port119
    by port119
     
    Working...
    X