Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by agclub, Yesterday, 08:57 PM
    2 responses
    16 views
    0 likes
    Last Post agclub
    by agclub
     
    Started by cre8able, 04-17-2024, 04:16 PM
    6 responses
    55 views
    0 likes
    Last Post cre8able  
    Started by Mindset, 05-06-2023, 09:03 PM
    13 responses
    293 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by kaywai, 09-01-2023, 08:44 PM
    4 responses
    600 views
    0 likes
    Last Post joselube001  
    Started by dpolyakov, 03-29-2024, 11:30 AM
    3 responses
    135 views
    2 likes
    Last Post sonia0101  
    Working...
    X