Trailing stops and backtesting - futures io
futures io futures trading



Trailing stops and backtesting


Discussion in NinjaTrader

Updated
    1. trending_up 2,011 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. 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)

 
Search this Thread
 

Trailing stops and backtesting

(login for full post details)
  #1 (permalink)
Oslo,Norway
 
Experience: Intermediate
Platform: NinjaTrader
Trading: EUR/USD
 
ValutaTrader's Avatar
 
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");
}
}

Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
MACD line not plotting after change of plot order
NinjaTrader
Webinar: Finding your own way in trading w/Adam Grimes
The Elite Circle
Short Interest Ratio indicator?
ThinkOrSwim
Automating strategies on multiple charts with same symbol
TradeStation
COTbase for quant trading?
Elite Algorithmic NinjaTrader Trading
 
 
(login for full post details)
  #3 (permalink)
Oslo,Norway
 
Experience: Intermediate
Platform: NinjaTrader
Trading: EUR/USD
 
ValutaTrader's Avatar
 
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.

Follow me on Twitter Started this thread Reply With Quote
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.

Laserdan
Follow me on Twitter Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > Trailing stops and backtesting


Last Updated on February 29, 2012


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts