Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by elirion, Yesterday, 09:32 PM
    0 responses
    6 views
    0 likes
    Last Post elirion
    by elirion
     
    Started by cre8able, Yesterday, 09:15 PM
    1 response
    8 views
    0 likes
    Last Post bltdavid  
    Started by cummish, Yesterday, 08:43 PM
    0 responses
    14 views
    0 likes
    Last Post cummish
    by cummish
     
    Started by Option Whisperer, Yesterday, 07:58 PM
    4 responses
    21 views
    0 likes
    Last Post Option Whisperer  
    Started by ETFVoyageur, 05-07-2024, 07:05 PM
    13 responses
    87 views
    0 likes
    Last Post ETFVoyageur  
    Working...
    X