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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    649 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    370 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    109 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    574 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    576 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X