Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OK to set Calculate parameter programmatically?

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

    OK to set Calculate parameter programmatically?

    Is this permissible?

    Code:
    if(State==State.Historical && IsTickReplays[0]==true)
    {Caculate = Calculate.OnBarClose }
    
    if(State==State.Realtime)
    {Calculate = Calculate.OnPriceChange;}
    What about doing this in OnBarUpdate?

    #2
    Hello Ricam,

    No, the Calculate object must be set in SetDefaults.

    This is because this settings controls how the data series are added, so changing this object would not be effective after the data is loaded.

    However, the Calculate only applies to real-time data and does not apply to historical data. Historical data is always Calculate.OnBarClose.

    http://ninjatrader.com/support/helpG.../calculate.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Calculate with Tick Replay

      On a tick replay chart, if Calculate is not set to OnBarClose, OnBarUpdate will receive every tick of the primary data series, not just the closing tick of each bar.

      How can I ensure that indicators that do not need to see every tick will only see the last tick of each bar? if(State==State.Historical && !IsFirstTickOfBar) return: doesn't work. It excludes all ticks other than the first tick of the bar, but what's needed is to exclude all ticks other than the LAST tick of the bar.

      Ordinarily, for historical, first and last tick of bar are the same. But NOT for tick replay!

      Comment


        #4
        Hello Ricam,

        What you are asking for is basically impossible.

        Lets say that you have a 1 minute bar. As ticks are being received just before the bar is about to be closed, NinjaTrader doesn't have a way to know that this was the last tick received until the bar is actually closed. Once the bar is closed, then we can know for sure that the previous tick was the last tick of the previous bar.

        While the bar is open, NinjaTrader is not able to know that in the future no more ticks will be received before be bar closes. You also would have no way to know that a tick is the last tick that will be received before the bar closes. You can guess, but you have no way to know for absolute sure.

        In your script, you could write logic that says if the bar is less than a few milliseconds of closing then use that current bar.. but you would need to write that special logic. NinjaTrader is not going to guess that the tick received is the last tick of the bar.

        So, to get the last tick of the bar for sure, save each tick as it comes in. When the bar closes, on that first tick, use the previous tick that was saved to a variable.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by Ricam View Post
          On a tick replay chart, if Calculate is not set to OnBarClose, OnBarUpdate will receive every tick of the primary data series, not just the closing tick of each bar.

          How can I ensure that indicators that do not need to see every tick will only see the last tick of each bar? if(State==State.Historical && !IsFirstTickOfBar) return: doesn't work. It excludes all ticks other than the first tick of the bar, but what's needed is to exclude all ticks other than the LAST tick of the bar.

          Ordinarily, for historical, first and last tick of bar are the same. But NOT for tick replay!
          There is no mix and matching for tick replay, and there is not a way to filter your OBU to run at different frequencies outside of the methods you tried.

          Depending on what you're doing with the data...

          Try using an absolute index value so you're not subjected to the mercy of the calculate property influencing the "current" barsAgo reference (which is set internally and out of your control).

          Code:
          protected override void OnBarUpdate()
          {
          	if(State==State.Historical && !IsFirstTickOfBar)
          		return;			
          	
          	Print(Bars.GetTime(CurrentBar - 1) + " : " + Bars.GetClose(CurrentBar - 1));
          	
          }
          MatthewNinjaTrader Product Management

          Comment


            #6
            Correct backfill on tick replay

            Tried the approach suggested by ChelseaB.(Post #4) It works well. Thanks!

            Now can use OnPriceChange or OnEachTick on tick replay charts. During the intrabar historical ticks the indicator is not doing anything other than remembering the value of the Input in case it needs to be recovered as the previous input on first tick of bar.
            Last edited by Ricam; 04-30-2016, 03:43 PM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Aviram Y, Today, 05:29 AM
            0 responses
            2 views
            0 likes
            Last Post Aviram Y  
            Started by quantismo, 04-17-2024, 05:13 PM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by ScottWalsh, 04-16-2024, 04:29 PM
            7 responses
            34 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cls71, Today, 04:45 AM
            0 responses
            6 views
            0 likes
            Last Post cls71
            by cls71
             
            Started by mjairg, 07-20-2023, 11:57 PM
            3 responses
            217 views
            1 like
            Last Post PaulMohn  
            Working...
            X