NexusFi: Find Your Edge


Home Menu

 





Spread-Backtesting


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one asddsa with 2 posts (0 thanks)
    2. looks_two Quick Summary with 1 posts (0 thanks)
    3. looks_3 shodson with 1 posts (0 thanks)
    4. looks_4 WolfieWolf with 1 posts (1 thanks)
    1. trending_up 2,159 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

Spread-Backtesting

  #1 (permalink)
asddsa
Malaysia
 
Posts: 2 since Oct 2013
Thanks Given: 2
Thanks Received: 0

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:



protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "SPREAD1"));
Add(new Plot(Color.FromKnownColor(KnownColor.ForestGreen), PlotStyle.Line, "SMASPREAD"));
Overlay = false;
Add(FirstInstrument,PeriodType.Day,1);
Add(SecondInstrument,PeriodType.Day,1);
}

/// <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;

if (BarsInProgress >= 1);
double FirstValue = (Closes[1][0]*Instruments[1].MasterInstrument.PointValue);
double SecondValue = (Closes[2][0]*Instruments[2].MasterInstrument.PointValue);
SPREAD1.Set(((SecondValue-FirstValue)*100)/(SecondValue+FirstValue));
SMASPREAD.Set(SMA(SPREAD1,SMAPERIOD)[0]);
// }
}


Thanks a lot in advance.
Ryan

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
32 thanks
Bigger Wins or Fewer Losses?
24 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #3 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


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.


asddsa View Post
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:



protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "SPREAD1"));
Add(new Plot(Color.FromKnownColor(KnownColor.ForestGreen), PlotStyle.Line, "SMASPREAD"));
Overlay = false;
Add(FirstInstrument,PeriodType.Day,1);
Add(SecondInstrument,PeriodType.Day,1);
}

/// <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;

if (BarsInProgress >= 1);
double FirstValue = (Closes[1][0]*Instruments[1].MasterInstrument.PointValue);
double SecondValue = (Closes[2][0]*Instruments[2].MasterInstrument.PointValue);
SPREAD1.Set(((SecondValue-FirstValue)*100)/(SecondValue+FirstValue));
SMASPREAD.Set(SMA(SPREAD1,SMAPERIOD)[0]);
// }
}


Thanks a lot in advance.
Ryan


Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
WolfieWolf's Avatar
 WolfieWolf 
Charlottetown, Prince Edward Island
 
Experience: Advanced
Platform: Ninja
Broker: Optimus - Rithmic
Trading: GC
Posts: 232 since Jul 2010
Thanks Given: 100
Thanks Received: 272

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.

/W

Reply With Quote
Thanked by:
  #5 (permalink)
asddsa
Malaysia
 
Posts: 2 since Oct 2013
Thanks Given: 2
Thanks Received: 0

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

Reply With Quote




Last Updated on January 6, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts