I would like to ask about possibility to cancel pending order in multitime frame strategy.
In default timeframe (daily bar) i am using conditions from weekly and monthly timeframe.
When condition from weekly time frame is set to true, strategy place order in daily time frame. The problem is that the pending order is canceled when the 1st daily bar is closed. I would like to program a code where the pending order, placed on daily chart, will be canceled when the weekly bar is closed.
I am using IOrders to enter in a trade. Could you help me please? Is possible to set a condition in weekly time frame to cancel pending order at the end of weekly bar, even though the order was placed on daily time frame?
// Formation on weekly chart if ( High[1] > High[2]&& High[1] > High[3] && High[1] > High[4] && High[0] < High[1] && Position.MarketPosition == MarketPosition.Flat && FirstTickOfBar && rhBool1 == true && BarsInProgress == 4 // Weekly time frame ) { DrawArrowUp(CurrentBar.ToString(), false, 0, High[0], Color.Lime); Print("|| Weekly condition: OK"); Print("|| Weekly High: " + High[0]); rhBool1 = false; condition = true; } // Daily chart if (condition == true && BarsInProgress == 0) // Default timeframe (Daily) { ++a; double enter = Highs[4][0]; Print("Weekly and Monthly condition: OK, ENTER IN TRADE"); Print("Entry price: " + enter); entryOrderLong = EnterLongStop(0, false, 1, enter + 1 * TickSize, "enter1" + a); DrawArrowUp(CurrentBar.ToString(), false, 0, Low[0], Color.Pink); condition = false; } protected override void OnOrderUpdate(IOrder order) { // Handle entry orders here. The entryOrder object allows us to identify that the order that is calling the OnOrderUpdate() method is the entry order. if (entryOrderLong != null && entryOrderLong == order) { // Reset the entryOrder object to null if order was cancelled without any fill if (order.OrderState == OrderState.Cancelled && order.Filled == 0) { entryOrderLong = null; } } } protected override void OnExecution(IExecution execution) { if (entryOrderLong != null && entryOrderLong == execution.Order) { if (execution.Order.OrderState == OrderState.Filled) { exitStopLong = ExitLongStop(0, true, 1, execution.Order.AvgFillPrice - ATR(ATR_rh1_SL)[0], "MyStop" + a, "enter1" + a); exitLimitLong = ExitLongLimit(0, true, 1, execution.Order.AvgFillPrice + ATR(ATR_rh1_TP)[0], "MyTarget" + a, "enter1" + a); if (execution.Order.OrderState != OrderState.Filled) { entryOrderLong = null; } } } }
Filip
Comment