• 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

  • NinjaTrader_Jesse
    replied
    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, 07:16 AM.

    Leave a comment:


  • NinjaTrader_JoshP
    started a topic Adding Indicators to Strategies

    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, 06:36 AM.

Latest Posts

Collapse

Topics Statistics Last Post
Started by ptertich, Today, 07:56 AM
1 response
8 views
0 likes
Last Post NinjaTrader_ChrisL  
Started by aslane, Today, 08:24 AM
1 response
12 views
0 likes
Last Post NinjaTrader_ChrisL  
Started by Capablanca, Yesterday, 05:51 PM
1 response
11 views
0 likes
Last Post NinjaTrader_PaulH  
Started by jackt, Today, 07:43 AM
3 responses
13 views
0 likes
Last Post NinjaTrader_PatrickG  
Started by zachiatrist, Today, 07:11 AM
3 responses
9 views
0 likes
Last Post NinjaTrader_ChrisL  
Working...
X