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

FirstTickOfBar on historical data

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

    FirstTickOfBar on historical data

    I draw some levels and I want them to be drawn only once per bar even if calculate on bar close = false. so I put the code to draw them inside an if(FirstTickOfBar) {} block. That seems to work real time and historically. I read the help and searched the forums which say that FirstTickOfBar is only valid for realtime data. But it seems to be working for me.

    Is this ok? If so can you update the documentation. If not, is there a better way to accomplish this? I could have an index variable and do my drawing and then set lastDrawBar = CurrentBar etc. but FirstTickOfBar is simpler.

    #2
    Hello cunparis,

    Thank you for your post.

    FirstTickOfBar means the first tick received of a bar in real-time, this works in real-time data with CalculateOnBarClose = false because you are receiving the incoming ticks in real-time.

    However, in historical data there is no tick by tick data only the Open, High, Low and Close of the chosen bar type you are using. Historical Data will always be CalculateOnBarClose = true, which would act similar to FirstTickOfBar as the first tick of a bar is also the tick that closes the previous bar.

    So you can see similar behavior when running historical as in real-time when using the FirstTickOfBar.
    We have a reference sample on using CalculateOnBarClose = false but using FirstTickOfBar to calculate items only once per bar at the following link if you are looking for additional information on this subject: http://www.ninjatrader.com/support/f...ad.php?t=19387

    Please let me know if I may be of further assistance.

    Comment


      #3
      Thanks for the explanation. You may want to update the help because it does not explain how FirstTickOfBar will work historically and gives the impression it won't work.

      Comment


        #4
        When set to CalculateOnBarClose = false, OnBarUpdate() will be triggered with every incoming tick by real-time data. With CalculateOnBarClose = true or on historical data, OnBarUpdate() will be triggered only once, which corresponds to a single tick.

        This means that the expression

        Code:
        if(FirstTickOfBar)
        {
        
        }

        has no impact on historical data or with COBC = true, as all incoming ticks are first ticks. It only filters the ticks with real-time data, such that the indicator calculation will only be performed once per bar. However, those indicator calculations may not reflect the value of the indicator once that bar is completed.

        Comment


          #5
          I guess what I'm saying is when I read the help, it sounded like FirstTickOfBar would return false if it was historical, but that's not the case, it will return true. That part wasn't clear.

          Maybe I'm the only one confused. Because for historical you actually get FirstTickOfBar and last tick of bar at the same time.

          Comment


            #6
            Originally posted by cunparis View Post
            I guess what I'm saying is when I read the help, it sounded like FirstTickOfBar would return false if it was historical, but that's not the case, it will return true. That part wasn't clear.

            Maybe I'm the only one confused. Because for historical you actually get FirstTickOfBar and last tick of bar at the same time.
            I have made excessive use of FirstTickOfBar in my indicators, because

            -> it has no impact on historical data and when the indicator is set to COBC = true
            -> it can considerably improve the speed of the indicator in all cases that one calculation per bar is sufficient

            However, in some cases this leads to a more complex code. Let us assume that you want to draw a triangle and trigger a sound alert for a low volume bar. You cannot know that a bar will be a low volume bar prior to the close. Let us also assume that the indicator does a few other things, which can be done intra-bar.

            In this case you would need to differentiate

            Code:
            if( Historical || CalculateOnBarClose)
            {
               // draw triangle for the current bar
               // trigger low volume sound alert if !Historical
            }
            else if (FirstTickOfBar)  // this means !CalculateOnBarClose && Real-time data
            {
              // draw triangle for the prior bar
              // trigger low volume sound alert
            }
            What I do not understand, is how the transition bar needs to be treated in COBC = false! You get

            Many historical bars (1 historical tick each) -> 1 transition bar (1 historical tick followed by a bunch of real ticks) -> many real-time bars (each built from many ticks)

            With the code above the triangle might show for the transition bar, because the volume was low on the first historical tick of that bar, which only included a fraction of the volume for that bar.

            Refresh your chart, and the transition bar moves to the right end of your chart.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            59 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            21 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            10 views
            0 likes
            Last Post cre8able  
            Working...
            X