Comments

Pages

How to Write a NinjaTrader Divergence Indicator

Posted by at 5:51 AM Read our previous post

Building Divergence Indicators on NinjaTrader
1. Divergence is a term that indicates when two assets or statistics that traditionally correlate in a certain way change from that common path. The indicator is the line that monitors this change and can be incorporated into a trading system, helping traders predict when and how to enter a trade. The first step is choose the two statistics that you want to test for divergence. These can be the price of assets but also other data such as volatility, beta and volume.
2. Once you have decided on the statistics you will use, back test them to determine the historic relationship. In the strategy analyzer, select the statistic (termed instruments) or group of statistics you will use. Then right click and select the back-test option on the menu. Select the more conservative default historical order fill-processing option.
3. After you have concluded the correlation of your assets, choose where you would like to enter and exit positions based on the divergence. This depends on how long you wish to keep the position. If you anticipate scalping or holding the position for a few seconds, minutes or hours, you will be looking for a much closer divergence, perhaps only a few percent. If you are long-term trader, wait for a divergence of 10 percent or greater to enter a position.
4. Finally, use NinjaScript to enter the paramaters you have developed for your indicator. To build the code, begin by opening a blank file and build a personalized variable for your parameter in the 'Variables' section. Then use the 'Properties' section to enter your specific statistics or assets and the actions you wish to take based on the divergence. Use the following code:[Description('Numbers of bars used for calculations')][GridCategory('Parameters')]public int Period{get { return period; }set { period = Math.Max(1, value); }}In the set line, define your value and then enter the parameters you decided upon in the previous step..

About