Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Pending order cancel

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Pending order cancel

    Hello,

    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?

    Code:
     
    
    // 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;
    	}	
    	}	
    	}	
    	
    	}
    Thank you

    Filip

    #2
    Hello,

    Thank you for the question.

    Have you used TraceOrders to see if the order is being expired?




    I noted that you are using:
    EnterLongStop(0, false,

    The false would indicate the order is not live until cancelled so it would only persist for as long as you are calling the method on each OnBarUpdate. In the case you are getting an expired order, setting this to true instead to make a live until cancelled order should persist the order.

    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    639 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    366 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    107 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    569 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    572 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X