Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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:
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
// try
// {
if (CurrentBars[0] < 1)
return;
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.
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