NOTE: If you can't see the enlarged images, please right-click on each image and open in a new window tab
Hi, I haven't been able to get my strategy to move the BreakEven stop to order.AverageFillPrice +/- 7 ticks when the condition is met. In Replay Mode the stop moves to BE when the bar closes. When I reload the script Strategy in Replay the historical result differs completely from the one obtained in Replay. See attached screenshots.
I've tried everything that is suggested in the forum:
1. Added 1 tick secondary chart series
2. Tried TickRepay, High Fill Resolution, all the Calculation options, Prints all over the code
3. Downloaded all the Samples provided by Ninja and Chelsea.
4. Changed my code from basic entries and exits to the approach using OnOrderUpdate() and OnExecutionUpdate() methods
5. Inserted the Breakeven handling code in the OEU and in the OBU methods
I know this issue is widely experienced and the documentation provided in the forum is ample. But I'm stuck with this mind-boggling issue. Can you please help me find a solution?
// This code is inserted in the OEU method. if(enShort) { stopOrder = ExitShortStopMarket(2, true, execution.Order.Filled, execution.Order.AverageFillPrice+ (Stop*TickSize), "MyStop", "MyEntry"); targetOrder = ExitShortLimit(2, true, execution.Order.Filled, execution.Order.AverageFillPrice - (Target * TickSize), "MyTarget", "MyEntry"); // This code for TriggerSate = 1 works fine here. if(TriggerState == 1 && stopOrder != null && stopOrder.StopPrice > Position.AveragePrice) //&& (Close[0] >= currentPtPrice) { Print("Trigger1 "+Time[0]); currentSlPrice = order.AverageFillPrice + (Stop * TickSize); currentPtPrice = order.AverageFillPrice - (BreakEvenTicks *TickSize); Print("currentSlPrice "+Time[0]+ " "+currentSlPrice); Print("currentPtPrice "+ Time[0]+ " "+currentPtPrice); TriggerState = 2; BackBrush = Brushes.DarkKhaki; } #region BE code was removed from here and inserted in the OBU method because it never entered here /* if (TriggerState == 2 && (Closes[2][0] <= currentPtPrice)) { TriggerState = 3; stopOrder = ExitShortStopMarket(0, true, stopOrder.Quantity, order.AverageFillPrice, "MyStop", "MyEntry"); //ChangeOrder(stopOrder, DefaultQuantity,0,PriceEntered); Tried both approaches.... same result BackBrush = Brushes.LightGreen; currentSlPrice = Position.AveragePrice; currentPtPrice -= trailFrequency * (TickSize / 2); }
//This is the code I moved up the the OBU method. It works partially. The stop moves when the primary series bar closes. if ((TriggerState == 2) && (Closes[2][0] <= currentPtPrice) && stopOrder != null && stopOrder.StopPrice > Position.AveragePrice ) { //Print("TriggerState 2 " +Time[0] ); TriggerState = 3; currentSlPrice = PriceEntered; //Position.AveragePrice; currentPtPrice -= trailFrequency * (TickSize / 2); Print("currentSlPrice " +Time[0] + " "+currentSlPrice); Draw.Diamond(this, @"BreakEvenBuilderExample Diamond_1", true, 0, (High[0] + (2 * TickSize)) , Brushes.DarkCyan); //SetStopLoss(CalculationMode.Price,currentSlPrice); //stopOrder = ExitShortStopMarket(2, true, stopOrder.Quantity, Position.AveragePrice, "MyStop", "MyEntry"); ChangeOrder(stopOrder, DefaultQuantity,0,PriceEntered); BackBrush = Brushes.LightGreen; }
else if (State == State.Configure) { //BarArray Series 1 AddDataSeries("ES 12-22", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last); // BarArray series 2 AddDataSeries(Data.BarsPeriodType.Tick, 1);
I appreciate your support. Thanks.
Comment