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.
    Josh P.NinjaTrader 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)
         {
               [B]AddChartIndicator(VOL());[/B]
         }
    }
    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 ScottWalsh, Today, 04:29 PM
    0 responses
    5 views
    0 likes
    Last Post ScottWalsh  
    Started by rtwave, 04-12-2024, 09:30 AM
    2 responses
    21 views
    0 likes
    Last Post rtwave
    by rtwave
     
    Started by tsantospinto, 04-12-2024, 07:04 PM
    5 responses
    69 views
    0 likes
    Last Post tsantospinto  
    Started by cre8able, Today, 03:20 PM
    0 responses
    7 views
    0 likes
    Last Post cre8able  
    Started by Fran888, 02-16-2024, 10:48 AM
    3 responses
    49 views
    0 likes
    Last Post Sam2515
    by Sam2515
     
    Working...
    X