Adding Indicators to Strategies
<< Click to Display Table of Contents >> Adding Indicators to Strategies |
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
protected override void OnStateChange() |
To choose which panel you want your indicator plotted on you can use this code snippet into the State.DataLoaded state:
VOL().Panel = 2; |
To customize plot colors:
VOL().Plots[0].Brush = Brushes.Red; // Plots the VOL with a red plot |
To customize plot width:
VOL().Plots[0].Width = 4; // Plots the VOL bars with a width of 4 |
To customize the plot dash style:
VOL().Plots[0].DashStyleHelper = DashStyleHelper.Dash; |
To customize the plot style:
VOL().Plots[0].PlotStyle = PlotStyle.Bar; VOL().Plots[0].AutoWidth = true; |
To customize lines you can do it the same way as above.
RSI(14, 3).Lines[0].Value = 20; |
Remember, you need to use the AddChartIndicator() method to add your indicator if you wish to use any of the plot / line indicator customization examples.