Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to buy at the closing price on current bar?

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

    How to buy at the closing price on current bar?

    Hi, I have a problem in implementing "enter long or short" at the closing price on current bar. Is it possible? This is on backtesting daily chart.

    thanks

    #2
    Hi klchoi123, welcome to the NinjaTrader support forums. Unfortunately this is not directly possible as you will have to wait for the bar to close and could then place orders for the next bar.

    You can take a look at this reference sample. It gives you the opportunity to backtest your strategy with a finer resolution that the daily one for execution of your orders - http://www.ninjatrader-support2.com/...ead.php?t=6652
    BertrandNinjaTrader Customer Service

    Comment


      #3
      klchoi123,

      The reason in backtesting that orders are filled in the next bar is because the point in time when you evaluated the trade condition was when you had the close price of that bar. In order to have the close price it means the bar has closed. That means there are no more tradeable locations on that bar and as such the next available trade slot is the open of the next bar.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Josh View Post
        klchoi123,

        The reason in backtesting that orders are filled in the next bar is because the point in time when you evaluated the trade condition was when you had the close price of that bar. In order to have the close price it means the bar has closed. That means there are no more tradeable locations on that bar and as such the next available trade slot is the open of the next bar.
        Josh..... I must disagree. The very point of the present bar (0) that could be traded in back testing is the close. This is an artifice that one may use. Say your entry condition is Stoch < 30, and 5 mins before the closing of the market the Stoch is 10. Why not allow NT to enter the trade?

        You may disagree with me - but then I ask you: what is the difference in uncertainty between buying in the first 5 minuts of tomorrow's opening and todays last 5 min before closing? Actually entering the trade tomorrow is further away from enter conditions then today's close. There is always the possibility of gaps.

        Just a point of view.......

        rgds

        -geo-

        Comment


          #5
          Hi geovani, you will need to wait for the bar to close to sure the condition is true, otherwise what would you do if there's a potential reverse in the last 5 minutes where you enter? This would then lead to more whipsaws...

          However, to achieve what you have in mind, use our reference sample for backtesting with intrabar granularity - with this you can add a second, finer datastream and realize your entry - http://www.ninjatrader-support2.com/...ead.php?t=6652
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Geo,

            NinjaTrader always takes the most conservative approach. If you are backtesting, you have the close price. If you have the close price the bar has closed. If the bar has closed you cannot trade on that bar. The next available trading location is the open of the next bar.

            It is not about uncertainty, it is about feasibility from a chronological standpoint. If you have the close price. The time for you to trade on that bar has already passed. You are not able to trade there.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              I think what geovani is saying (and what I've also posted several times) is that we agree it is chronologically impossible to both know for certain the close and trade at it, but if you have an end of day strategy, where you send your order to market right before the close, as many of us do, you usually get filled at fairly close to the closing price and if your strategy usually holds for several days, the tiny entry price fluctuations are peanuts compared to the moves over the next few days. I ran the numbers on the last few years of closes and looked at the moves in the last minute before the close and and I get a little better and a little worse fills based on the last minute of action, but things basically averaged out in the end. In fact, some markets support MOC (market on close) orders for just this purpose (to get an order filled as close as possible to the market close).

              Now put yourself in the shoes of someone who has an end of day strategy. You could download hundreds of megabytes of minute data from a provider and use that to get an "exact" market price 1 minute before the close, and make your backtesting orders of magnitude slower, or you could simulate trading at the last minute with end of day data and be willing to live with the small fluctuations in the last minute of the market, but get much faster backtesting performance. Not only that, but you actually get much more accurate results using the market close on stocks, because due to overnight moves, the difference in today's close and tomorrow's open averages orders of magnitude larger than the move in the last minute of the market before the close.

              I'm not saying that allowing a purchase at the closing price is right for all strategies/people. People who don't understand price movements might get themselves into a big hole by ignoring this factor, but why restrict this ability for those that know what they are doing? I've had to implement some fairly hideous workarounds to fix this, and still get decent performance from backtesting that needs to go back several years. I'd definitely suggest a feature to trade at the close price be off by default, but I'd certainly appreciate the ability to do it without workarounds, which for me involve running a separate program I wrote to massage the prices in the NT database.

              Comment


                #8
                Anagoge,

                We do understand what you guys are saying and it has been noted. As it currently stands, it is policy that NinjaTrader takes the most conservative approach possible. This is to prevent any overstating of strategy performance.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Josh View Post
                  Anagoge,

                  We do understand what you guys are saying and it has been noted. As it currently stands, it is policy that NinjaTrader takes the most conservative approach possible. This is to prevent any overstating of strategy performance.
                  ==============
                  OK. I understand.
                  Now suppose I want to go long today at the High of yesterday's bar.
                  Todays High is higher then yesterdays.
                  Is there any impediment in backtesting that?
                  Or would NT only allow me to enter the trade at tomorrow's opening?
                  {Iwould not think so...}

                  In fact I am having difficulty to test a 3 days breakout. On the left side I choose High. The condition is >. On the right side I choose Highestbar.
                  Then the only option I have is the days lookback. I choose 3. Then I choose HIgh again. That's it. No trades are generated. There must be somthing in these hhv-llv setups thar I am missing.

                  rgds

                  -geo-

                  Comment


                    #10
                    Originally posted by NinjaTrader_Bertrand View Post
                    Hi geovani, you will need to wait for the bar to close to sure the condition is true, otherwise what would you do if there's a potential reverse in the last 5 minutes where you enter? This would then lead to more whipsaws...

                    However, to achieve what you have in mind, use our reference sample for backtesting with intrabar granularity - with this you can add a second, finer datastream and realize your entry - http://www.ninjatrader-support2.com/...ead.php?t=6652
                    Hello Bertrand. As you see I am new to NT. A new software, new language... so things should take some time to click. I feel though, that this intrabar granularity thing is something very interesting. I can not read scrips yet, so I would be glad if you could shed some light into this.
                    Is it that when some entry/exit signal is triggered in a test, NT is able to "dive" into a smaller time-frame to search and execute the entry/exit and then slip back to the upper frame and continue there??

                    thanks for the attention

                    -geo-

                    Comment


                      #11
                      Hi geo, I can understand there is a lot to learn when you are new to automatic trading on NinjaTrader - you are correct in your understanding, the order is executed on a finer timeframe to simulate what is called 'intrabar execution' if you look at it from your bigger timeframe. This is of course also possible when trading realtime then, as NinjaTrader allows you to submit orders to any loaded timeseries in your strategy (that we call Bars objects).

                      Here is a helpful link to this topic - http://www.ninjatrader-support.com/H...struments.html
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Hi geo, please check the attached picture for the High Breakout, this works well for me on daily data. Did you enter an order in the actions field on the bottom? Thanks!
                        Last edited by NinjaTrader_Bertrand; 01-23-2009, 10:30 AM.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Bertrand View Post
                          Hi geo, I can understand there is a lot to learn when you are new to automatic trading on NinjaTrader - you are correct in your understanding, the order is executed on a finer timeframe to simulate what is called 'intrabar execution' if you look at it from your bigger timeframe. This is of course also possible when trading realtime then, as NinjaTrader allows you to submit orders to any loaded timeseries in your strategy (that we call Bars objects).

                          Here is a helpful link to this topic - http://www.ninjatrader-support.com/H...struments.html
                          Bertrand, if I had daily bars and 5 min bars loaded as historical data, which would be the "primary Bars"? 5min or daily? My strategy is on the daily chart. I ask because in the example of the link he is calling "primary Bars" the smaller time-frame (1 min) and then calling the bigger (3 min) as object. (???)

                          Comment


                            #14
                            Hi Geo, the chart from which you start / load your strategy is the primary one. Any other Bars objects added to the strategy via the Add() method.

                            Those can then be accessed with the correct index value - http://www.ninjatrader-support.com/H...BarSeries.html
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              The strategy is to buy long at a 5 day breakout up and sell at a 3 day breakout down. Your picture looks like mine.
                              set1 - enter long High[0]>Highestbar[High,5]
                              set2 - exit long Low[0]<Lowestbar[Low,3]

                              Only one trade is generated - first bar and last bar - no breakouts at all.

                              PS - which is the easiest way to post a picture here?

                              -geo-

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Brevo, Today, 01:45 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Brevo
                              by Brevo
                               
                              Started by aussugardefender, Today, 01:07 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post aussugardefender  
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              238 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Started by TraderG23, 12-08-2023, 07:56 AM
                              9 responses
                              384 views
                              1 like
                              Last Post Gavini
                              by Gavini
                               
                              Started by oviejo, Today, 12:28 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post oviejo
                              by oviejo
                               
                              Working...
                              X