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

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.
    Brandon H.NinjaTrader Customer Service

    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.

        Brandon H.NinjaTrader Customer Service

        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.
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Karado58, 11-26-2012, 02:57 PM
            8 responses
            14,828 views
            0 likes
            Last Post Option Whisperer  
            Started by Option Whisperer, Today, 09:05 AM
            0 responses
            1 view
            0 likes
            Last Post Option Whisperer  
            Started by cre8able, Yesterday, 01:16 PM
            3 responses
            11 views
            0 likes
            Last Post cre8able  
            Started by Harry, 05-02-2018, 01:54 PM
            10 responses
            3,204 views
            0 likes
            Last Post tharton3  
            Started by ChartTourist, Today, 08:22 AM
            0 responses
            6 views
            0 likes
            Last Post ChartTourist  
            Working...
            X