• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding Indicators to Strategies

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

    Adding Indicators to Strategies

    Applies to: NinjaTrader 7

    When backtesting strategies it can be useful to add the indicators you use for calculations onto the chart to make it easier to check your strategy for accuracy. Instead of doing this step manually every time you run the strategy you can program it to automatically load the indicators for you.

    For example:

    To add a volume indicator to your charts you need to add this code snippet into the Initialize() section of your code.
    Code:
    Add(VOL());
    To choose which panel you want your indicator plotted on you can use this code snippet into the Initialize() section:
    Code:
    VOLMA(20).Panel = 2;
    Add(VOLMA(20));
    To customize plot colors:
    Code:
    EMA(13).Plots[0].Pen.Color = Color.Blue;     // Plots the EMA as a blue line
    To customize plot width:
    Code:
    EMA(13).Plots[0].Pen.Width = 2;     // Plots the EMA line with a width of 2
    To customize the plot dash style:
    Code:
    RegressionChannel(60, 2).Plots[0].Pen.DashStyle = DashStyle.Dash;
    To customize lines you can do it the same way as above.
    Code:
    RSI(14, 3).Lines[0].Value = 20;
    RSI(14, 3).Lines[0].Pen.Color = Color.Green;
    Remember, you need to use the Add() method to add your indicator if you wish to use any of plot/line indicator customizations.
    Last edited by NinjaTrader_Jesse; 06-03-2015, 07:36 AM.
    JoshNinjaTrader Customer Service

    #2
    Applies to: NinjaTrader 8

    When backtesting strategies it can be useful to add the indicators you use for calculations onto the chart to make it easier to check your strategy for accuracy. Instead of doing this step manually every time you run the strategy you can program it to automatically load the indicators for you.

    For example:

    To add a volume indicator to your charts you need to add this code snippet into the OnStateChange section of your code for the State: State.DataLoaded

    Code:
    protected override void OnStateChange()
    {
         if (State == State.DataLoaded)
         {
               AddChartIndicator(VOL());
         }
    }
    To choose which panel you want your indicator plotted on you can use this code snippet into the State.DataLoaded state:
    Code:
    VOL().Panel = 2;
    AddChartIndicator(VOL());
    To customize plot colors:
    Code:
    VOL().Plots[0].Brush = Brushes.Red;     // Plots the VOL with a red plot
    To customize plot width:
    Code:
    VOL().Plots[0].Width = 4;    // Plots the VOL bars with a width of 4
    To customize the plot dash style:
    Code:
    VOL().Plots[0].PlotStyle = PlotStyle.Dot;
    To customize lines you can do it the same way as above.
    Code:
    RSI(14, 3).Lines[0].Value = 20;
    RSI(14, 3).Lines[0].Brush = Brushes.Green;
    Remember, you need to use the AddChartIndicator() method to add your indicator if you wish to use any of plot/line indicator customizations.
    Last edited by NinjaTrader_Jesse; 03-15-2018, 08:16 AM.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Rednael90, Today, 07:22 AM
    0 responses
    8 views
    0 likes
    Last Post Rednael90  
    Started by dadarara, Today, 02:42 AM
    0 responses
    4 views
    0 likes
    Last Post dadarara  
    Started by TraderYoda, 10-17-2018, 09:06 AM
    14 responses
    168 views
    1 like
    Last Post TraderYoda  
    Started by Johnny Santiago, Yesterday, 09:31 PM
    0 responses
    8 views
    0 likes
    Last Post Johnny Santiago  
    Started by DarkCloudCover, Yesterday, 07:29 PM
    1 response
    29 views
    1 like
    Last Post TraderYoda  
    Working...
    X