Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

end of market

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

    end of market

    It is possible to access the market closure so that in cases where it is a holiday in the United States, you can close operations before premature closing

    #2
    Hello franatas,

    Thanks for your post.

    SessionIterator could be used to get the time the market starts or ends at. It could also be used to test if a specific date is a defined trading day.

    See the help guide documentation linked below for an example and more information.

    SessionIterator: https://ninjatrader.com/support/helpGuides/nt8/sessioniterator.htm

    You might also want to review the indicator "Holiday Tomorrow Indicator" in the NT user apps.

    This indicator is publicly available on our NinjaTrader Ecosystem website:Please let us know if we may assist further.​

    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    <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


      #3
      if (Bars.IsFirstBarOfSession)
      {
      sessionIterator.GetNextSession(Time[0], true);

      Print("The current session end time is " + sessionIterator.ActualSessionEnd);
      }

      DateTime currentTime = Time[0];
      if (currentTime <= sessionIterator.ActualSessionEnd.AddMinutes(-5))
      Print("The current " + currentTime);

      // Verifica si estamos dentro de los últimos 5 minutos de la sesión
      if (currentTime >= sessionIterator.ActualSessionEnd.AddMinutes(-5))
      {
      if (OrdenEntrada != null)
      {
      CancelOrder(OrdenEntrada); EntradaOk = true; OrdenEntrada = null;
      }

      if (OrdenEntrada != null && Position.MarketPosition == MarketPosition.Long)
      {
      SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Market, Position.Quantity, 0, 0, "", "CIERRE DE OPERACIONES");
      OrdenEntrada = null;
      EntradaOk = true;
      }

      if (OrdenEntrada != null && Position.MarketPosition == MarketPosition.Short)
      {
      SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, Position.Quantity, 0, 0, "", "CIERRE DE OPERACIONES");
      OrdenEntrada = null;
      EntradaOk = true;
      }​
      I understand that it would be fine so that 5 minutes before closing the operations would close if there were any. I have tried it in the analyzer and it does not remove those operations from the statistics,

      Comment


        #4
        Hello franatas,

        Thanks for your notes.

        In the code you shared I see you are passing 'OrdenEntrada' into the CancelOrder() method.

        The CancelOrder() method requires that you pass in an order object to the method to cancel that specific order.

        Is 'OrdenEntrada' an order object in your script?

        If so, are you assigning the order object to 'OrdenEntrada' in OnBarupdate() in your script?

        Here is a reference sample demonstrating how CancelOrder() is used in NinjaScript: https://ninjatrader.com/support/help...thod_to_ca.htm

        See this help guide page for more information about CancelOrder() and sample code: https://ninjatrader.com/support/help...ancelorder.htm

        See this help guide documentation for more information about OnOrderUpdate(): https://ninjatrader.com/support/help...rderupdate.htm

        Further, when a strategy is not behaving as expected then it is necessary to add debugging prints to the script to understand exactly how the logic is behaving.

        In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places or cancels an order along with the time of that bar.

        Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

        Also, enable TraceOrders which will let you know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.

        <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


          #5
          private void AssignOrderToVariable(ref Order order)
          {
          if (order.Name == "LARGOS" || order.Name == "CORTOS" || order.Name == "LARGOSTendencia" || order.Name == "CORTOSTendencia" && OrdenEntrada != order)
          OrdenEntrada = order;
          }
          Yes, in fact, if I put the same code so that it closes orders 5 minutes before 11:00 p.m. in Spain, which is the market closing time, it closes them perfectly, but here it is not doing it, that's why I ask if it does in the analyzer. It should work the same as where I'm testing it

          Comment


            #6
            Hello franatas,

            Thanks for your notes.

            In the code you shared, I see you are calling SubmitOrderUnmanaged() to submit a market order.

            The CancelOrder() method cannot be used for market orders, this method is used for canceling limit orders that are working and have not filled.

            You would need to wait for the market order to fill and then submit an exit order to exit the position at that specific time.

            If you are trading near the end of the session and see that market orders are delayed in being filled due to volume, you could use limit orders instead and could call CancelOrder() for the limit order to cancel the limit order at that specific time.

            Please let us know if we 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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            606 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            351 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            560 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            561 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X