Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Add() Inside a Strategy

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

    Using Add() Inside a Strategy

    I have these global variables in my class,

    Code:
    [COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]  private IDataSeries MAFunc = null;[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]  private int MAPeriod = 14;
    [/SIZE][/FONT][/COLOR]
    Inside my strategy parameters, I ask the user which of several MA indicators they would like to use. Then I use code like this inside Initialize() ...

    Code:
    [COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]  switch (MAType)[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]  {[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]     case MATypeIs.SMA:[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]         MAFunc = SMA(Input, MAPeriod);
    [/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]        break;[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]     case MATypeIs.EMA:[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]         MAFunc = EMA(Input, MAPeriod);[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]         break;
    [/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]    etc etc etc[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]  }[/SIZE][/FONT][/COLOR]


    In OnBarUpdate I like using MAFunc[0] to get the value of the user-specified MA for the most recent bar.

    And, I can also use MAFunc to calculate the slope of the MA over the last 8 bars,

    Code:
    [COLOR=#000000][FONT=HelveticaNeue-Light][SIZE=4]Slope(MAFunc, 8, 0);[/SIZE][/FONT][/COLOR]
    This all works quite well. MAFunc is a data series that represents whatever MA indicator the user selected in the parameters.

    Now comes the effort to make the strategy add the indicator to the chart for display.

    Code:
     
      Add(MAFunc);  // <-- adding this code doesn't work

    How do I display the indicator represented by MAFunc to the chart?


    #2
    Welcome to our forums here bltdavid and thanks for the post. Unfortunately we would expect that outcome, since only complete indicators could be Add() for visualization, not elements such as a single data series. As workaround on the regular charts you could look into this technique here - http://www.ninjatrader.com/support/f...ead.php?t=6651

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    66 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    149 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    162 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    99 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    286 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X