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 giulyko00, Today, 12:03 PM
    0 responses
    2 views
    0 likes
    Last Post giulyko00  
    Started by AttiM, 02-14-2024, 05:20 PM
    12 responses
    213 views
    0 likes
    Last Post DrakeiJosh  
    Started by cre8able, 02-11-2023, 05:43 PM
    3 responses
    238 views
    0 likes
    Last Post rhubear
    by rhubear
     
    Started by frslvr, 04-11-2024, 07:26 AM
    8 responses
    117 views
    1 like
    Last Post NinjaTrader_BrandonH  
    Started by stafe, 04-15-2024, 08:34 PM
    10 responses
    47 views
    0 likes
    Last Post stafe
    by stafe
     
    Working...
    X