Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Instant Exits and Bars updates

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

    Instant Exits and Bars updates

    Hi! I trying to make instant exits with indicator crossovers! But always exits in next bar update. Itīs possible to get exit at moment? here my sample:

    Code:
    // Conditional on OnBarUpdate()
    if (( CrossAbove(KPA900(), KPAutoStop(), 1)) && TipoTrade == "Venta")
         {
                 // Debug Flag    
    Print (" KPA900 Cruza sobre KPAutoStop en Variable de Trade:" + TipoTrade+ " Entrando con Posiciones activas: " + Position.Quantity.ToString());
          // Exit from positions on next bar :(     
          ExitShort ( ); 
          // Control Var
          TipoTrade = "Libre";
           // message to Alert Windows
           Alert("MyAlert2", Priority.High, "Saliendo de una Venta. Estado Bandera: " + TipoTrade , @"C:\Archivos de Programa\NinjaTrader 6\sounds\Alert2.wav", 60, Color.LightPink, Color.Black);
    								
                }

    #2
    Please see the property CalculateOnBarClose.

    RayNinjaTrader Customer Service

    Comment


      #3
      Thx! Itīs Possible! If my indicators support it!

      Comment


        #4
        Ok, I put CalculateOnBarClose = false; in my Initialize(), no problem, but the ExitShort and ExitLong orders, execute in next bar, not in current bar or bar in progress! Itīs possible to exit inmediatly with current bar, donīt wait to next bar, to execute exits commands?

        Comment


          #5
          Is this in backtest or in real-time?
          RayNinjaTrader Customer Service

          Comment


            #6
            In Real Time.

            Comment


              #7
              Hi Agamenon,

              For clarification, are the Print commands you call being executed on the bar you want the Exit orders to be sent or are they also printing on the next bar? Add Time[0] into the output string to see what time the Print command is executed.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Hi Josh,

                I Will check and reforced Time[0], thanks for the help!

                Now I think that the command, the parameter 1, for 1 bar ago will be 0!:

                Code:
                ( CrossAbove(KPA900(), KPAutoStop(), 1)
                I will change for it:

                Code:
                ( CrossAbove(KPA900(), KPAutoStop(), 0)
                could be it the event that lag the exitshort-long?

                I will take note of all events and time and will post again!

                Thx!

                Comment


                  #9
                  All of the examples in the help for CrossAbove and CrossBelow specify "1" as the smallest parameter value for "lookBackPeriod", so I had assumed that this was the smallest value one could use for the parameter.

                  Is a value of zero valid for this parameter?

                  Comment


                    #10
                    You would normally use 1. I suspect it is simply your indicators not crossing till the end of the bar. You can check this by printing out the values of the indicators.

                    If you do a crossabove on say SMA(5) over SMA(20) you will see it executes immediately if you have CalculateOnBarClose=false
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      OK, I check CrossBelow//Above with 0 instead of 1, and dont work .

                      But I try with 1 and Work perfectly! 2 o 3 seconds of delay, but work properly. Thanks to all!!!


                      The checks in debug with Print(), Time[0] and the ExitLong/Short, show that command executed with the indicator, all work perfectly in Real Time.

                      Another Question: What command or method i use for delays? Thread.Sleep() work???

                      Comment


                        #12
                        We highly advise NOT to handle any threads in the application. This can have adverse affects on NinjaTrader.
                        RayNinjaTrader Customer Service

                        Comment


                          #13
                          CrossAbove/Below missing crosses

                          I have a strategy that I am working on that is looking for crosses from two values of an indicator. Entries seem to be working as expected, but the Exits are missing crosses of the two variables and therefore missing the exits.

                          Is there something I should be looking for to get the behavior on the exits?

                          Here is the code:

                          // Long Entry
                          if ((CrossAbove(RMO(2,10,30,81).ST1, 25, 2)) &&
                          (RMO(2,10,30,81).ST4[0] > 0))

                          {
                          EnterLongLimit(GetCurrentBid(), "RMO Long Entry");
                          }

                          // Long Exit
                          if ((CrossBelow(RMO(2,10,30,81).ST1, RMO(2,10,30,81).ST3, 1)) &&
                          (CrossBelow(RMO(2,10,30,81).ST1, RMO(2,10,30,81).ST2, 1)) &&
                          (Position.MarketPosition == MarketPosition.Long))
                          {
                          ExitLong("RMO Long Entry");
                          }

                          Comment


                            #14
                            Hello,

                            I am sorry, I am not familiar with the RMO indicator.

                            I suggest testing the logic with a default indicator and see if the logic is correct. If it works with a default indicator I would check the custom indicator values.

                            Also try using Print() and TradeOrders to debug:
                            DenNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            571 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            330 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            101 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            549 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            549 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X