Oslo,Norway
Experience: Intermediate
Platform: NinjaTrader
Trading: EUR/USD
Posts: 66 since Apr 2011
Thanks Given: 4
Thanks Received: 52
|
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");
}
}
|