Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Cancels Right Away

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

    Order Cancels Right Away

    Hi all.

    Using this code shown below. After meeting the "Bars formula" below, an order is submitted, and immediately canceled. I'd like to have the order stay active for the duration of the following bar, using a buy/sell price of the last closing bar (Close[0]), and this has been my experience as the default action with other strategy I've built. However it does not appear to be working with this strategy, and I can't seem to figure out why...

    The time frame I'm using is a 2-min, and caclulateonbarclose = true.


    // Bars formula
    int greenbars=0;
    int redbars=0;
    for (int x=0;x<signalbars;x++)
    {
    if (Closes[1][x]>Opens[1][x])
    greenbars++;

    if (Closes[1][x]<Opens[1][x])
    redbars++;
    }

    // Short Order
    if (
    greenbars==signalbars &&
    tradeshort == true &&
    tradepermission == true
    )

    SE=EnterShortLimit(1,false,tradesize,Close[0],"");
    barNumberOfOrder = CurrentBar;


    // Long Order
    if (
    redbars==signalbars &&
    tradelong == true &&
    tradepermission == true
    )

    LE=EnterLongLimit(1,false,tradesize,Close[0],"");

    #2
    If you do not keep the order alive it will automatically expire and cancel. To prevent this you can either keep the order alive by resubmitting or you can use the liveUntilCancelled parameter set to true. If you choose the latter you will have to use CancelOrder() when you are ready to cancel it.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Right...

      But by default, shouldn't the order stay active until the next bar update, which is 2-min since I'm using a 2-min bar and calculateonbarclose = false?

      Brian

      Comment


        #4
        You are using multi-time frame. You may need to keep it alive on the other BarsInProgress.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks! Think I get it now.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          115 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          161 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          83 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          127 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          87 views
          0 likes
          Last Post PaulMohn  
          Working...
          X