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

Exit at the close of the bar

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

    Exit at the close of the bar

    hi, how can i exit at the close of the bar?

    if (BarsSinceExit() > 0 || BarsSinceExit() == -1 && ...............) //to prevent me from taking multiple entry orders in the same bar.
    {
    EnterLong();
    }


    if (BarsSinceEntry() == 0) // exit at the end of the same bar's signal
    {
    ExitLong();
    }

    ie, i enter long, now i want to exit at the close of the same bar, rather than waiting for the open of the next bar

    i looked around the forums and couldnt get anything to work..

    #2
    calhawk01, in NT's event based framework the open tick of the new bar seen would dictate when the 'old' bar would close so it's not time based, but strictly event based. So per default the first possible fill location is then the next bar open for your market order.

    What you can look into is adding a finer timeseries in to have access to the intrabar timestamps of your higher series to be able to submit an exit close to the potential close of the bar.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      calhawk01, in NT's event based framework the open tick of the new bar seen would dictate when the 'old' bar would close so it's not time based, but strictly event based. So per default the first possible fill location is then the next bar open for your market order.

      What you can look into is adding a finer timeseries in to have access to the intrabar timestamps of your higher series to be able to submit an exit close to the potential close of the bar.
      Hi betrand-

      Any way to perhaps add a timer? Or exit seconds before the end of bar

      Ie get the currents bar opening time and predict the future time minus few seconds

      Comment


        #4
        Correct, a timer could be used as well for that purpose.

        You also store the current PC time if you see the first tick of the bar and then with BarsPeriod id / value you would know when the next bar is ending on a time based chart.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          Correct, a timer could be used as well for that purpose.

          You also store the current PC time if you see the first tick of the bar and then with BarsPeriod id / value you would know when the next bar is ending on a time based chart.
          when you say ''as well for this purpose'' what other way do you see we can tackle this?

          trying to find the most efficient way.. b/c the clocks can be out of sync. do you have any templates/examples?

          thank you

          Comment


            #6
            We would unfortunately not have a premade sample here for this task - as the clock is a main reference I would highly suggest to keep it up to date regularly, it's also very important for incoming executions and any data that's not natively timestamped. Which what you choose would be also governed by if you desire to backtest this setup or not, the clock would only be a realtime reference.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Hi Bertrand,

              I have a closely related question if you don't mind.

              I've been trying to learn how incorporate multi-timeframe Bar Objects so that my strategy executes an order on the current bar of a given market entry signal, and not the bar that follows. I've read all the stuff in the support section and understand the idea and how its supposed to work but I find the examples insufficient for a newbie like me.

              So if I had a 610 Tick bar chart and wanted to slice those 610 ticks into, lets say, five primary 122 ticks bars. On signal, for example an ma crossover, I would like the close of the 5th 122 tick bar (of the current 610 tick bar) to execute an order on the open of the new 610 tick bar and not on the following 610 tick bar as is the case by default. How do I go about doing that? My understanding is that the trade gets executed on the primary timeframe contained in the secondary timeframe holder. From what I grasp I have to add these two timeframes using the the Add method but then I'm lost as to how to implement this into my entry signals.

              Thanks for any help you can spare.

              Comment


                #8
                It would be much easier to help you, if you would say what you need.
                Now after several help attempts you say that you want to run your strategy on tick chart.
                Tick chart has nothing to do with time. Nada.
                I admire NT support patience.

                Comment


                  #9
                  Shadowshorter, to get a better understanding of the logic and code structure needed I would highly suggest to review the SampleMultiTimeFrame script shipped per default with NT.

                  If you would like to backtest preparing an order already when the primary chart has not yet closed the bar, then placing your entry logic and calculations on a finer series would help, however here you would run into the challenge to replicate the entry logic and MA's from the higher time series. Traders approximate this by using longer lengths for their studies run on the finer bar, although this would not be exact it's a start. In realtime / realtime simulation running CalculateOnBarClose = false this would be easier as you could look inside the bar and just process the order then on when desired, to get to your event you could count the 122 tick bar updates in FirstTickOfBar for example and reset the count on the next 610 update then.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Hi Bertrand,

                    Thanks for your reply. I totally forgot about the Multi timeframe template and does seem to have some of what I'm looking for.

                    So to understand you correctly, in CalculateOnBarClose = false, I can count the 5 intrabars updates on the lower timeframe and initiate a market entry on the last bar using FirstTickOfBar and then reset it for the next cycle.

                    Do you have a simple example using FirstTickOfBar you could share?

                    Cheers

                    Comment


                      #11
                      Originally posted by Baruch View Post
                      It would be much easier to help you, if you would say what you need.
                      Now after several help attempts you say that you want to run your strategy on tick chart.
                      Tick chart has nothing to do with time. Nada.
                      I admire NT support patience.
                      i need to exit at the end of the bar... same bar as the order was executed on! any idea?

                      Comment


                        #12
                        count ticks

                        Comment


                          #13
                          Originally posted by Baruch View Post
                          count ticks
                          I'm pretty sure ratio of tickets to seconds is not 1:1

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by burtoninlondon, Today, 12:38 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post burtoninlondon  
                          Started by AaronKoRn, Yesterday, 09:49 PM
                          0 responses
                          14 views
                          0 likes
                          Last Post AaronKoRn  
                          Started by carnitron, Yesterday, 08:42 PM
                          0 responses
                          11 views
                          0 likes
                          Last Post carnitron  
                          Started by strategist007, Yesterday, 07:51 PM
                          0 responses
                          13 views
                          0 likes
                          Last Post strategist007  
                          Started by StockTrader88, 03-06-2021, 08:58 AM
                          44 responses
                          3,982 views
                          3 likes
                          Last Post jhudas88  
                          Working...
                          X