Spread3

This 3‐instrument indicator is an example that shows how to make multi‐instrument indicators. It can be modified for your own calculations, and to allow as many instruments as desired (code for a 4th instrument is included in the comments). It is heavily commented explaining its use.

The Indicator calculation contained is the summation of the price of each instrument multiplied by its "Qty" (which may be negative). Optionally, each instruments Contract Multiplier (Point Value) may be applied (which will plot the spread of the dollar values of the specified number of contracts).

The code contains synchronization methods which are used to synchronize multiple instruments to the primary chart instrument. This ensures that multi‐instrument calculations are always comparing bars which occurred at the same time. Synchronization is ensured in all cases (real time and historical, with CalculateOnBarClose == true or false). Lookbacks are also synchronized. It will scale to large numbers of instruments if CalculateOnBarClose == true.

In a multi‐instrument indicator, how to handle missing bars is an issue. This indicator has a parameter which selects between repeating the previous bar's output, and producing "no output" (but be warned that an instrument which produces "no output" should not be used as input to another indicator).

See also my "Index" indicator, which can plot spreads of any number of instruments.

Created By kdoren
NinjaTrader Version 7
File Size 9.8 KB
Create Date 09/27/2010
# of Downloads 1606

Importing to NinjaTrader 7 is Easy!

To import your 3rd party app or add-on to NinjaTrader, simply follow these 3 steps:

  1. Download the app or add-on file to your desktop
  2. From the NinjaTrader Control Center window, select the menu File > Utilities > Import NinjaScript
  3. Select the downloaded file from your desktop

Questions?

Visit the NinjaScript File Sharing discussion in the NinjaTrader user forum to interact with fellow traders and the NinjaTrader support team.