Hi All, I am new here, trying to create an indicator of spread (eg: mini NQ vs mini S&P) and looking for way to backtest it (if possible) in strategy analyzer, does any one here has similar experience before?
My code as below, so when spread (NQ points level - ES points level) / (Sum of both) is crossing the SMA, i will LONG NQ and Short ES with the proportionality around (137 NQ vs 100 ES). Indicator coding as below:
/// Called on each bar update event (incoming tick)
protected override void OnBarUpdate()
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close' with your own formula.
if (CurrentBars < 1)
I've done some spread arb stuff, mainly different months of futures contracts. I would have as a baseline a ratio of one instrument over the other. Then I would track the changes in that ratio and the number of standard deviations from the mean. If ratio was higher than "normal" then 1 of 2 things are happening
1) Instrument ONE is rising faster than TWO
2) Instrument TWO is dropping faster than ONE
Your approach is different. I don't know if it's better or worse than what I was doing. I eventually didn't do much more as I could see on the price charts on the back of the board rapidly adjust during these conditions, so I must not have been the only one with that idea. It might be something to consider if you are curious.
Once upon a time I played with spreads a lot in NT. I even had a spreader, like the commercial ones, except written for NT but abandoned it. There is an indicator in the Elite section called T4SpreadSym that will allow you calculate and plot the spread of two instruments, you might need to modify the formula a little but that part is trivial compared to the backtesting. When I attempted to backtest using the indicator as a plot I ended up with one side or the other but never the positions from both instruments. In the end I created two strategies, one inverse of the other, ran them both, and manually aggregated the results. It was a real pain in the butt. Ninja is not designed for spreading, even though it can be taught to execute them, plotting them is a whole different thing. The last idea I had was to create a custom bar type that would calculate the spread and then allow standard ninja charts to plot it but I never took it this far. I did, however, find a developer who was willing to do the work. If you are interested I could give you his contact details, I'm sure he would do the same for you but it was pricey.
The following user says Thank You to WolfieWolf for this post:
Thanks wolf, guess I shall move on first as just curious on how to backtest spread in Ninjatrader. Costing is a big concern for me at the moment, interesting on the spread you tested on different month. Look forward to talk to you again. cheers. Ryan