NinjaScript > Educational Resources > Tips >

Adding Indicators to Strategies

Print this Topic Previous pageReturn to chapter overviewNext page

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.



To choose which panel you want your indicator plotted on you can use this code snippet into the Initialize() section:

VOLMA(20).Panel = 2;



To customize plot colors:

EMA(13).Plots[0].Pen.Color = Color.Blue;     // Plots the EMA as a blue line


To customize plot width:

EMA(13).Plots[0].Pen.Width = 2;     // Plots the EMA line with a width of 2


To customize the plot dash style:

RegressionChannel(60, 2).Plots[0].Pen.DashStyle = DashStyle.Dash;


To customize lines you can do it the same way as above.

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.