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

The first trade of the strategy is not accounted for in the account

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

    The first trade of the strategy is not accounted for in the account

    Buenos días,
    estoy probando una estrategia que creé en Ninjatrader 8. La estrategia funciona con los gráficos de bloques de Renko y la he simulado en el mercado en vivo en varios instrumentos de futuros.
    La estrategia funciona todo el día, ingresa al mercado en la segunda barra de la sesión, hasta el final de la sesión. Para esto, he configurado la "salida en cierre de sesión", en verdadero y 30 segundos antes de cerrar, es decir, los valores que aparecen de forma predeterminada.
    También lo tengo configurado en "esperar hasta plano".
    La estrategia funciona más o menos bien, pero la primera operación del día en que se realiza la estrategia no se contabiliza en la cuenta, no aparece en el rendimiento de la estrategia.
    En la tabla de resumen de las estrategias aplicadas, en el cuadro "sincronizar", todos los valores marcan "verdadero", por lo que la estrategia aplicada en varios instrumentos se sincroniza con la cuenta en todos ellos.
    ¿Por qué la cuenta no detecta el primer intercambio de la sesión?
    ¿Cómo puedo resolverlo?

    Muchas gracias por su ayuda.

    #2
    Good Morning,
    I am trying a strategy that I created in Ninjatrader 8. The strategy works on Renko block graphics and I have simulated it on live market in several futures instruments.
    The strategy works all day, enters the market in the second bar of the session, until the end of the session. For this I have configured the "exit on session close", in true and 30 seconds before closing, that is, the values ​​that appear by default.
    I also have it configured in "wait until flat".
    The strategy works more or less well, but the first trade of the day that the strategy performs, is not accounted for by the account, it does not appear in the strategy's performance.
    In the summary table of the applied strategies, in the "sync" box all the values ​​mark "true", so the strategy applied in several instruments is synchronized with the account in all of them.
    Why is the first trade of the session not detected by the account?
    How can I solve it?

    Thank you very much for your help.

    Comment


      #3
      Hello danakede,
      Thanks for your post.

      I am not sure why you would not see the first trade of the session. Is the strategy Green on the Strategies tab when you notice this?

      Are you looking at historical performance, real-time performance, or both?

      Do you see any orders at the time you believe you should see a trade?

      Are there any errors or messages on the Logs tab of your Control Center whenever this occurs?

      Josh G.NinjaTrader Customer Service

      Comment


        #4
        Good Morning, The name of the strategy appears in green on all instruments. I'm looking at the real performance and comparing it to the real work (with simulated live data) of the strategy. Here below I share the data that appears with respect to the 6A instrument.



        Orden ='6d282a061f2040409c4edcb68f942340 / Sim101' nombre = 'Ventas cortas' nuevo estado = 'Entregado' instrumento = '6A 06-19' Acción = 'Ventas cortas' precio límite = 0 precio tope = 0 cantidad = 1 tipo = 'Mercado' Tiempo vigente = GTC Oco = '' llenado = 0 Llenar precio = 0 Error = 'Sin error' error nativo = ''
        Orden ='6d282a061f2040409c4edcb68f942340 / Sim101' nombre = 'Ventas cortas' nuevo estado = 'Aceptado' instrumento = '6A 06-19' Acción = 'Ventas cortas' precio límite = 0 precio tope = 0 cantidad = 1 tipo = 'Mercado' Tiempo vigente = GTC Oco = '' llenado = 0 Llenar precio = 0 Error = 'Sin error' error nativo = ''
        Orden ='6d282a061f2040409c4edcb68f942340 / Sim101' nombre = 'Ventas cortas' nuevo estado = 'Funcionando' instrumento = '6A 06-19' Acción = 'Ventas cortas' precio límite = 0 precio tope = 0 cantidad = 1 tipo = 'Mercado' Tiempo vigente = GTC Oco = '' llenado = 0 Llenar precio = 0 Error = 'Sin error' error nativo = ''
        Orden ='6d282a061f2040409c4edcb68f942340 / Sim101' nombre = 'Ventas cortas' nuevo estado = 'Falló' instrumento = '6A 06-19' Acción = 'Ventas cortas' precio límite = 0 precio tope = 0 cantidad = 1 tipo = 'Mercado' Tiempo vigente = GTC Oco = '' llenado = 1 Llenar precio = 0,7135 Error = 'Sin error' error nativo = ''
        La estrategia NinjaScript OPENVariableyGestionMonetariaDobleenVIVO/162495303 presentando orden
        Ejecución=f2c133fdc8754c0abefea9897f98b943 Instrumento=6A 06-19 Cuenta=Sim101 Intercambio =Por omisión Precio=0,7135 Cantidad=1 Posición de mercado=Corto Operación=Operation_Add Orden =6d282a061f2040409c4edcb68f942340 Tiempo=27/03/2019 2:00
        Orden ='bd8d7220bd5d42f0848af22fdabfc332 / Sim101' nombre = 'Stop loss' nuevo estado = 'Entregado' instrumento = '6A 06-19' Acción = 'Comprar para cubrir' precio límite = 0 precio tope = 0,7171 cantidad = 1 tipo = 'Mercado límite' Tiempo vigente = GTC Oco = 'f2c133fdc8754c0abefea9897f98b943' llenado = 0 Llenar precio = 0 Error = 'Sin error' error nativo = ''
        Instrumento = '6A 06-19' cuenta = 'Sim101' precio promedio = 0,7135 cantidad = posición en el mercado 1 = Corto operación = Operation_Add
        Orden ='bd8d7220bd5d42f0848af22fdabfc332 / Sim101' nombre = 'Stop loss' nuevo estado = 'Aceptado' instrumento = '6A 06-19' Acción = 'Comprar para cubrir' precio límite = 0 precio tope = 0,7171 cantidad = 1 tipo = 'Mercado límite' Tiempo vigente = GTC Oco = 'f2c133fdc8754c0abefea9897f98b943' llenado = 0 Llenar precio = 0 Error = 'Sin error' error nativo = ''

        Comment


          #5
          danakede,

          Based on your snippet it looks like the order is being rejected.

          Orden ='6d282a061f2040409c4edcb68f942340 / Sim101' nombre = 'Ventas cortas' nuevo estado = 'Falló' instrumento = '6A 06-19' Acción = 'Ventas cortas' precio límite = 0 precio tope = 0 cantidad = 1 tipo = 'Mercado' Tiempo vigente = GTC Oco = '' llenado = 1 Llenar precio = 0,7135 Error = 'Sin error' error nativo = ''
          Does this occur if you reset the SIM101 account? Resetting a simulation account will clear all historical trade data from this account. You may follow the instructions below to reset a simulation account.
          • From the NinjaTrader Control Center window select the Accounts tab
          • Right click on your simulation account and select 'Edit Account'
          • Press the "Reset" button
          Josh G.NinjaTrader Customer Service

          Comment


            #6
            Good morning,

            I have reset the account following the steps indicated, however, the problem persists. I have a similar strategy running on another computer with several futures and the problem is the same.
            I believe that the problem could be related to the synchronization of the account and the strategy, perhaps with the closing of the "exit on close" since at the beginning of the operation of the strategy in a new session I could verify the following:

            1. The position of the strategy is not flat. The strategy already has a strategy position in all futures (1S or 1L) in the closing period of the market and at the beginning of the strategy, in the first bar of the session. This should not happen, since they should have remained flat at the end of the previous session and continue flat during the formation of the first bar of the session.

            2. The position of the account is flat. A script (-) appears in all futures. So the position of the strategy does not match the position of the account.

            3. The color of the name of the strategy in all futures is yellow while the first trade is executed. At the end of the first trade, the strategy changes color to green and then the position of the strategy and the position of the account coincide, it is at this moment when the position of the account begins to count all the trades. But the first trade of the strategy in all futures is ignored.

            I remind you that in the properties box of the strategy, I have selected the option "wait until flat".
            The schedule that I have selected in all futures is the one that comes by default "use settings of the instruments", however, I do not think this is the problem.

            I hope you help me solve the problem.
            Thank you very much for your help.
            A greeting.

            Comment


              #7
              danakede,

              I do not think your order is being rejected because of your strategies settings. I suspect your logic. If you turn on TraceOrders what does the platform report about the rejection? Please see the following link for more information on TraceOrders: https://ninjatrader.com/support/help...aceorders2.htm

              1. The position of the strategy is not flat. The strategy already has a strategy position in all futures (1S or 1L) in the closing period of the market and at the beginning of the strategy, in the first bar of the session. This should not happen, since they should have remained flat at the end of the previous session and continue flat during the formation of the first bar of the session.
              This could be caused by the bar type you have selected or the bar period. What bar type and bar period are you using?

              3. The color of the name of the strategy in all futures is yellow while the first trade is executed. At the end of the first trade, the strategy changes color to green and then the position of the strategy and the position of the account coincide, it is at this moment when the position of the account begins to count all the trades. But the first trade of the strategy in all futures is ignored.
              This sounds like the first trade is not actually happening in real time, which would make sense why it wasn't appearing in your Live Strategy Performance. I would like to take a look at the english version of your log and trace files. Please write in to PlatformSupport(AT)NinjaTrader(DOT)com and reference ticket #2115066 with RE:JOSH in the subject line. Please attach your Log and Trace files to your email so that I may investigate this matter further. You may follow the steps below to attach those files.
              • Open your NinjaTrader folder under My Documents.
              • Right click on the 'log' and 'trace' folders and select Send To> Compressed (zipped) Folder.
              • Send the 2 compressed folders as attachments to this email.
              • Once complete, you can delete these compressed folders.
              Josh G.NinjaTrader Customer Service

              Comment


                #8
                Good Morning,

                Okay, I'll do what he asks, tonight at the beginning of the session and I'll pass him the record.

                I have been thinking and I think that error is because the "exist on session close" what it does is close the positions of the account, but it does not close the positions of the strategy, which continues to maintain the long or short positions. After closing the first bar of the next session, it is when the "exit on session close" closes or flattens the strategy.
                However, my strategy starts buying or selling at the close of the first bar of the session, when at that moment, the strategy is not flat, at that precise moment, the position of the strategy is long or short and the position of the account is flat (-), do not match, as I have configured that the strategy does not operate into account until "wait until flat", the account does not register the operation, since strategy position and account position do not match and also the position The strategy is not flat.
                However, at the close of the first trade, strategy position and account position are both flat and coincide, it is at that moment when the strategy becomes green and the trades begin to count.

                I think the secret of solving the problem is related to flattening the strategy at the end of the session, in my opinion this is what the "exit on session close" should do, I think it should close the positions of the account and also close the positions of the strategy at that moment and not wait to close the positions of the strategy until the completion of the formation of the first bar of the next session, I leave it as a suggestion for the next updates of Ninjatrader 8.
                I use Renko bars in my strategy.

                Is there a way to flatten the strategy at the end of the session?

                Tonight I send you the report you requested.

                Greetings and thank you.

                Comment


                  #9
                  danakede,

                  Renko bars can certainly cause some odd things to happen. It is possible that the renko bar that would execute the close is not yet finished building when this occurs. I would be interested to know if this happens with other bar types.

                  If all you are after is making sure you are flat at the end of the session you could set that through the UI. This may be the best way when using Renko bars. You can do this from your Control Center>>Tools>>Options>>Trading>>Auto close position

                  Otherwise, ExitOnSessionClose would be the best way to exit your strategies position at the end of the session.

                  I look forward to reviewing your files.

                  Josh G.NinjaTrader Customer Service

                  Comment


                    #10
                    Good Morning,
                    I have looked at the option that he proposes to me, however, it is a self-closing for a specific instrument or for several instruments simultaneously, but all of them AT ONE HOUR IN CONCRETE.
                    This option is not valid for me, if I want each instrument to close at the close of its specific session.
                    What I want is for each strategy to be in charge of closing the open positions in the account and in the strategy and that it is flat and that one instrument is independent of another.
                    If I set a time pej. 00:00 h, it will close 00:00 h for all instruments, it may be valid for some and not valid for others, since each future has a different session time.
                    Is that how I explained it?

                    I insist, I think what I need is a way to flatten the strategy at the end of the session and I do not get it this way nor with the "exit on session close".
                    There must be some other way.

                    Thanks and best regards

                    Comment


                      #11
                      Good Morning,
                      I just sent you the email with the two compressed folders that you requested.
                      I hope you can help me,
                      Greetings and thank you

                      Comment


                        #12
                        Good Morning,
                        besides that it is possible to have more than one error in my strategy (you will confirm it to me), I continue with the idea of flattening my strategy at the end of the session, since the "exit on session close" does not work for me .
                        I found this:

                        private SessionIterator sessionIterator;

                        protected override void OnStateChange()
                        {
                        if (State == State.DataLoaded)
                        {
                        //stores the sessions once bars are ready, but before OnBarUpdate is called
                        sessionIterator = new SessionIterator(Bars);
                        }
                        }

                        protected override void OnBarUpdate()
                        {
                        // Only process strategy logic up until three hours prior to the end of the trading day at the exchange
                        if (DateTime.Now <= sessionIterator.GetTradingDayEndLocal(Bars.Session Iterator.ActualTradingDayExchange).AddHours(-3))
                        {
                        // Strategy logic here
                        }
                        }



                        Would it be possible to modify it in the following way so that it executes what I want?







                        private SessionIterator sessionIterator;

                        protected override void OnStateChange()
                        {
                        if (State == State.DataLoaded)
                        {
                        //stores the sessions once bars are ready, but before OnBarUpdate is called
                        sessionIterator = new SessionIterator(Bars);
                        }
                        }

                        protected override void OnBarUpdate()
                        {
                        // Only process strategy logic up until three minutes prior to the end of the trading day at the exchange
                        if (DateTime.Now <= sessionIterator.GetTradingDayEndLocal(Bars.Session Iterator.ActualTradingDayExchange).AddMinutes(-3))
                        {
                        ExitLong("Cierredeldia", "");
                        ExitShort("Cierredeldia", "");
                        OkToTrade = false;
                        }
                        }


                        Comment


                          #13
                          Good Morning,
                          I have found another useful function, about what I want.
                          We will call MODE 1 to the previous formula and MODE 2 to this formula to be able to differentiate them, if it suits you.


                          SessionIterator sessionIterator;

                          protected override void OnStateChange()
                          {
                          if (State == State.Historical)
                          {
                          sessionIterator = new SessionIterator(Bars);
                          }
                          }

                          protected override void OnBarUpdate()
                          {
                          // on new bars session, find the next trading session
                          if (Bars.IsFirstBarOfSession)
                          {
                          // use the current bar time to calculate the next session
                          sessionIterator.GetNextSession(Time[0], true);

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


                          Would it be possible to modify it in the following way so that it executes what I want?



                          SessionIterator sessionIterator;
                          private DateTime endTime;

                          protected override void OnStateChange()
                          {
                          if (State == State.Historical)
                          {
                          sessionIterator = new SessionIterator(Bars);
                          }
                          }

                          protected override void OnBarUpdate()

                          endTime = sessionIterator.ActualSessionEnd;

                          {
                          // on new bars session, find the next trading session
                          if (Bars.IsFirstBarOfSession)
                          {
                          // use the current bar time to calculate the next session
                          sessionIterator.GetNextSession(Time[0], true);

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

                          }

                          if (endTime == DateTime.Now)
                          {
                          ExitLong("Cierredeldia", "");
                          ExitShort("Cierredeldia", "");
                          OkToTrade = false;
                          }
                          }
                          }


                          Comment


                            #14
                            danakede,

                            I am reviewing your files and need to look into a few items for clarification. Your english logs state the order was 'Filled', however the Spanish logs report the order was Rejected(Falló). I am sending you an email requesting your database so that I can confirm what we should be seeing here.

                            In regards to your code-- you could certainly use a Session Iterator here but would require some testing to ensure this will do exactly what you want.
                            Josh G.NinjaTrader Customer Service

                            Comment


                              #15
                              and which of the two methods I have sent you seems more appropriate? Do not have any errors? I ask you please, if you notice any error, please tell me, thank you

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jclose, Today, 09:37 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,414 views
                              0 likes
                              Last Post Traderontheroad  
                              Started by firefoxforum12, Today, 08:53 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post firefoxforum12  
                              Started by stafe, Today, 08:34 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by sastrades, 01-31-2024, 10:19 PM
                              11 responses
                              169 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X