Trading Articles
Article Categories
Article Tools
Trailing stops and backtesting
Updated February 29, 2012
trending_up
2,011 views
thumb_up
2 thanks given
group
2 followers
forum
3 posts
attach_file
0 attachments
Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
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 and simple.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Trailing stops and backtesting
(login for full post details)
#1 (permalink )
Oslo,Norway
Experience: Intermediate
Platform: NinjaTrader
Trading: EUR/USD
Posts: 66 since Apr 2011
Thanks: 4 given,
52
received
I am calling my trailing stop function on each bar. It only moves the stop level if my logic tells it to (i.e. a minimum profit level has been reached). My issue with NinjaTrader on this is that on back test the trailing stops do not seem to kick in. Any suggestions on whether this is by design or something I can change to make my logic work in backtest mode as well?
protected override void OnMarketData(MarketDataEventArgs e){
if (e.MarketDataType == MarketDataType.Last){
lastPrice = e.Price;
}
}
public void adjustStopLoss(){
if ( stopOrder != null )
CancelOrder(stopOrder);
double pointsProfit=Position.GetProfitLoss(lastPrice, PerformanceUnit.Points );
double tickProfit=pointsProfit/TickSize;
if ((tickProfit-TicksMinProfit)<=0)
return; // No need to set trailing stop if level not triggered. Default stop from order entry still remains.
if (Position.MarketPosition == MarketPosition.Short){
double stop = lastPrice+ (TicksTrailingSL*TickSize);
stopOrder=SubmitOrder(0, OrderAction.BuyToCover, OrderType.Stop, DefaultQuantity, stop, stop, "Exit", "ShortTrailStop");
}
if (Position.MarketPosition == MarketPosition.Long){
double stop = lastPrice - (TicksTrailingSL*TickSize);
stopOrder=SubmitOrder(0, OrderAction.Sell, OrderType.Stop, DefaultQuantity, stop, stop, "Exit", "LongTrailStop");
}
}
Can you help answer these questions from other members on futures io?
Best Threads (Most Thanked) in the last 7 days on futures io
(login for full post details)
#3 (permalink )
Oslo,Norway
Experience: Intermediate
Platform: NinjaTrader
Trading: EUR/USD
Posts: 66 since Apr 2011
Thanks: 4 given,
52
received
I may have figured this out myself. It seems to be the event
protected override void OnMarketData(MarketDataEventArgs e){
if (e.MarketDataType == MarketDataType.Last){
lastPrice = e.Price;
}
}
that is not triggered in back test , so lastPrice was not set. The strange thing was that for sell orders it seemed to work. Using latest Close does give the expected result however.
The following 2 users say Thank You to ValutaTrader for this post:
(login for full post details)
#4 (permalink )
North Carolina
Experience: Beginner
Platform: Ninja Trader
Broker: Ninja Trader Broker / Continuum
Trading: ES
Posts: 57 since Jun 2009
Thanks: 4 given,
57
received
You are correct. The OnMarketData event does not fire in backtest , only on live data.
Last Updated on February 29, 2012
Right now
Ongoing
Right now
March
Register to Attend
Elite only
Coming soon
April