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

OnBarClose?

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

    OnBarClose?

    Rather basic question, but is there a way I can access when a bar actually closes? I can see e.g. FirstTickOfBar, but this can occur sometime after the previous bar closed.

    #2
    Depending on the bar type you're using you may be able to use PercentComplete


    Let me know if I can be of further assistance.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Originally posted by AntiMatter View Post
      Rather basic question, but is there a way I can access when a bar actually closes? I can see e.g. FirstTickOfBar, but this can occur sometime after the previous bar closed.
      (Emphasis mine). That is not possible: they are the same event. The Closing price of the previous bar may be different from the Opening price of the current bar, but the event that closes the previous bar is the one that opens the current bar. You just have to refer to the correct price that you want.

      If COBC is false, then Close[1] and Open[0] from the same event can be different. If COBC is true, those prices are displaced one bar back. IOW, if COBC is true, there is no way to access any property of the CurrentBar until it closes, when it immediately becomes the past bar. It can get mighty confusing. Heck, it had me in knots for quite a while, until I figured it out.

      Comment


        #4
        Ok thanks, that's a useful post.

        When is the the Close generated? At the same time as the FirstTickOfBar on the next bar?

        Comment


          #5
          Most of the time yes, but not always.

          There isn't a way that I'm aware of that would allow you to know when the close was generated aside from performing an operation when the next tick comes in.
          LanceNinjaTrader Customer Service

          Comment


            #6
            Lets take minute price bars as our example. Waiting for the FirstTickOfBar (on the new bar) to generate the close (of the previous bar) results in an unnecessary delay for the data for the close - it can be sometime before the next tick.

            Instead, wouldn't it make sense to generate the close at the start of the next minute (e.g. 00 seconds)? Or is there something here I am missing?

            Comment


              #7
              If calculate on bar close is set to true, a trade could not be executed until a new tick of data comes through, thus creating a new bar. If COBC is set to false you would have the value of the close based on the most recent tick.

              If you would like I would be happy to submit your request to development.
              LanceNinjaTrader Customer Service

              Comment


                #8
                Originally posted by AntiMatter View Post
                Lets take minute price bars as our example. Waiting for the FirstTickOfBar (on the new bar) to generate the close (of the previous bar) results in an unnecessary delay for the data for the close - it can be sometime before the next tick.

                Instead, wouldn't it make sense to generate the close at the start of the next minute (e.g. 00 seconds)? Or is there something here I am missing?
                On the face of it, a very sensible idea. The only caveat is that we are then way too dependent on the accuracy of the computer clock. All clocks drift, so such a method will probably mean that we essentially have charts that cannot be replicated/compared between computers.

                Comment


                  #9
                  Hmmm yes interesting point.

                  The problem from my perspective is that I am trading on minute data. At the close of the minute, I actually have all the data I need to make a decision about the trade. However, on some of the thinner markets that I trade, the next tick can take quite some time. Thus, if I use FirstTickOfBar (or any of the related variables) then I am entering the trade with a rather unnecessary delay. This may well increase my frictional costs by some (small) margin.

                  Thus, I need a workaround.

                  One way would be PercentComplete. However, one issue I have with this is the inability to back test - something I do extensively with new versions of my scripts to confirm that they behave appropriately.

                  Could an alternative be to look at the seconds, and when we reach 00, I know that the current/last bar is *effectively* closed (with the above caveat about clock asynchrony), even though we may not have received the FirstTickOfBar yet?

                  Comment


                    #10
                    If you're looking to backtest you would need a smaller time frame to more accurately execute trades. In a backtest COBC is always set to true.

                    You can add the smaller time frame through the use of Add() http://www.ninjatrader.com/support/h...nstruments.htm

                    However you may want to look into using market replay and live SIM trading for your testing since historical data only provides the OHLC values.


                    LanceNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by AntiMatter View Post
                      Hmmm yes interesting point.

                      The problem from my perspective is that I am trading on minute data. At the close of the minute, I actually have all the data I need to make a decision about the trade. However, on some of the thinner markets that I trade, the next tick can take quite some time. Thus, if I use FirstTickOfBar (or any of the related variables) then I am entering the trade with a rather unnecessary delay. This may well increase my frictional costs by some (small) margin.

                      Thus, I need a workaround.

                      One way would be PercentComplete. However, one issue I have with this is the inability to back test - something I do extensively with new versions of my scripts to confirm that they behave appropriately.

                      Could an alternative be to look at the seconds, and when we reach 00, I know that the current/last bar is *effectively* closed (with the above caveat about clock asynchrony), even though we may not have received the FirstTickOfBar yet?
                      I guess you should then put a clock display on the chart, and maybe change the background for a few seconds to either tell you that the 00 is coming up and/or has been and gone for a few seconds?

                      Comment


                        #12
                        Yes, I definitely need something within the script to tell me when we are in the "grey zone" between 00 and FirtTickOfBar. In this grey zone, I have to temporarily utilise my <I>effective</I> close, because the actual close is not yet available. When the FirstTickOfBar happens, I can then go back to using the actual close (although they could differ....)

                        In fact, NT or the data provider must have the close information stored until the FirstTickOfBar, right? Would it be possible (potentially in future versions) to access this?

                        Comment


                          #13
                          Unfortunately this is not possible since the bar would not have closed yet within our framework at all. There's nothing time based driving the bars, all event.

                          You would need to develop a custom timer that tracked time since the last tick if you wanted to submit an order before the next tick came in after X amount of time passed.
                          Last edited by NinjaTrader_Lance; 05-30-2013, 07:10 AM.
                          LanceNinjaTrader Customer Service

                          Comment


                            #14
                            Further to my above posts, to implement what I want, I need access to the time (in seconds) on historical data.

                            ToTime(DateTime.Now) --> This gives me the time in seconds, but is always the clock time (e.g. when in market replay, it is still the real time).

                            ToTime(Time[0]) --> This gives me the bar time (e.g. correct for historic data), but only gives one minute resolution e.g. always 105100, wherever we are in the bar.

                            How can I get second resolution?

                            Comment


                              #15
                              Hello,

                              You can use

                              Time[0].Second to get the second only

                              Let me know if I can be of further assistance.
                              LanceNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by futtrader, 04-21-2024, 01:50 AM
                              4 responses
                              41 views
                              0 likes
                              Last Post futtrader  
                              Started by Option Whisperer, Today, 09:55 AM
                              1 response
                              11 views
                              0 likes
                              Last Post bltdavid  
                              Started by port119, Today, 02:43 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post port119
                              by port119
                               
                              Started by Philippe56140, Today, 02:35 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post Philippe56140  
                              Started by 00nevest, Today, 02:27 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post 00nevest  
                              Working...
                              X