Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limit Orders Cancelling and Not Entering Automated Trades Again

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

    Limit Orders Cancelling and Not Entering Automated Trades Again

    Hello,

    I have a fully functional code for taking my automated trades. It has always been taking market orders for entry. I have made a copy where I want to have it switched to limit orders a set number of ticks below the market. I currently have all of that working so that's all good. My issue is when my limit order is cancelled if not filled in the first bar, I assume my system thinks it is still in a trade or something because it is not reset.

    I have read through all the code pieces related to limit trades and cancelled trades and attempted to use those pieces of codes but have not had any luck. I have attached a few links I have been using to try and figure it out. The code pieces that I have entered will be in here as well. Maybe I have the code in the wrong areas?
    Code for LongLimit:

    private Order myEntryOrder = null; -this is defined at the beginning of the code, do I need this defined before the onbarupdate?

    if(TradeSize1 != 0)
    {
    Trade_1_In_Progress_Long = true;

    EnterLongLimit(TradeSize1, (Close[0]-(TicksLimitLong* TickSize)) , "LE 1");

    InTrade = true;
    IsLongTrade = true;
    activeBar = CurrentBar;

    if (myEntryOrder.OrderState == OrderState.Cancelled)
    {

    myEntryOrder = null;
    }
    }​



    Last edited by durdcash; 01-08-2023, 08:41 AM.

    #2
    Originally posted by durdcash View Post
    My issue is when my limit order is cancelled if not filled in the first bar, I assume my system thinks it is still in a trade or something because it is not reset.
    From the link you posted:

    By default, orders submitted via Entry() and Exit() methods automatically cancel at the end of a bar if not re-submitted​
    With this type of order method you need to basically check every bar and use the method to place the order on each bar (OnBarUpdate())

    Comment


      #3
      So would this still be the issue you mentioned if my first trade took successfully, the second one cancelled because it left the bar, and then no new trades were taken after? If so, I will try to rework the code in the next few days to see if that works

      Comment


        #4
        If you experienced a situation where you got a fill it's likely the fill occurred during the first bar because the order still existed.

        Update the code so that each time OnBarUpdate is called it checks for your position and then places relevant orders. For example: if long place sell stop at X-Y price, if flat and bullish place buy limit at X-Z price, etc.

        It will be fastest to create sample code in the wizard and generate a simple strategy and see how it does it then implement that in your existing code. There are also examples posted to the forum as well.

        Comment


          #5
          Hello durdcash,

          Thanks for your post.

          WalterSkinner is correct. By default, orders submitted via Entry() and Exit() methods automatically cancel at the end of a bar if not re-submitted as mentioned in the Managed Approach help guide page linked below​.

          Managed Approach: https://ninjatrader.com/support/help...d_approach.htm

          It is possible to submit orders that stay active until canceled by setting liveUntilCancelled overload to true.

          See this reference sample demonstrating how to keep orders alive: https://ninjatrader.com/support/help...ders_alive.htm

          Let me know if I may assist further.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          56 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          132 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X