Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate oneachtick

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

    Calculate oneachtick

    Hi,

    I have set the Calculate method OnEachTick so I would expect the OnBarUpdate to be called multiple times for each bar however on every call there is an increase of the CurrentBar value.
    What do I miss?

    #2
    Hello tolisss,

    Thanks for opening the thread.

    As you can observe with Print(CurrentBar); in a strategy or indicator with Calculate.OnEachTick configured, CurrentBar will have the same print for each tick and will iterate after the bar closes.

    Please let me know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim

      Thanks for the answer and my apologies for not being specific enough as I am new to NT. What I observe is that Analyzer will call OnBarUpdate for each tick however when I apply the strategy on a chart it does not or from what I understand from other posts it probably does it for market data. The problem is that Analyzer does it for Historical data as well, so how to detect from my strategy in which mode am I? Checking if State is Historical apparently is not enough.

      Comment


        #4
        Hello tolisss,

        The Strategy Analyzer uses historical data to drive the backtest. This historical data is the OHLC values for each bar. When this data gets processed, OnBarUpdate() will only process the bars, whether or not Calculate is set to Calculate.OnEachTick.

        When enabled on a chart, the strategy will first process historical data and then transition to real time data. The historical data is again only processed per bar in OnBarUpdate() while the real time data will be called with each tick. CurrentBar still references the bar that the tick is iterated on.

        To have historical iterate in Calculate.OnEachTick, you will want to take a look at Tick Replay.

        I have made a video demonstrating OnBarUpdate() with Calculate.OnEachTick on a chart and in the Strategy Analyzer: https://www.screencast.com/t/30QmbzXfIGM
        JimNinjaTrader Customer Service

        Comment


          #5
          excellent video many thanks and my apologies again I already enabled Tick Replay so Analyzer worked on each tick. My problem is that my strategy needs to know if it operates on eachtick mode.

          For example Analyzer with Tick Replay does the chart also does but only when switching to real time so is there some property that can I can use to allow my script to run when eachtick really works as I do not want to run it for OHCL data.

          hope I make some sense

          Comment


            #6
            p.s. tick replay has no effect on a chart at least that what i observe

            Comment


              #7
              The Strategy Analyzer does not process realtime data, it only uses historical data. You will have to enable Tick Replay to have historical data played back per tick.

              I would suggest to perform the same tests that I have in the video with a script that has Calculate set to Calculate.OnEachTick when you have Tick Replay enabled.

              In depth information for utilizing Tick Replay can be found here: https://ninjatrader.com/support/help...ick_replay.htm
              JimNinjaTrader Customer Service

              Comment


                #8
                >I would suggest to perform the same tests that I have in the video with a script that has Calculate set to Calculate.OnEachTick when you have Tick Replay enabled.

                of course I did and is clear what you said, Analyzer works on historical where we can have the Tick Replay while chart is only OHCL on historical and tick on real.

                The question is: the strategy can run in both the Analyzer and the Chart so, can I detect where is running therefore detect if my historical data are tick or OHCL?

                Comment


                  #9
                  Ah, thanks for clearing that up.

                  You can use a combination of checking the State to see if you are in Historical or Realtime, and you can also use Bars.IsTickReplay to detect if you are using Tick Replay or not.

                  Code:
                  if (State == State.Historical && !Bars.IsTickReplay) // This historical bar is not rebuilt per tick
                  If you would like to specifically check if the strategy is being run from the Strategy Analyzer, you can check if Account.Name is "Backtest"

                  Documentation for reference:

                  State - https://ninjatrader.com/support/help...n-us/state.htm

                  Bars.IsTickReplay - https://ninjatrader.com/support/help...tickreplay.htm

                  Account - https://ninjatrader.com/support/help...gy_account.htm

                  Please let me know if I can be of further assistance.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    excellent thanks for your patient!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by fxRichard, Today, 04:35 AM
                    2 responses
                    12 views
                    0 likes
                    Last Post fxRichard  
                    Started by fernlicht, Today, 01:59 AM
                    12 responses
                    60 views
                    0 likes
                    Last Post NinjaTrader_Jason  
                    Started by space_trader, Today, 12:52 AM
                    0 responses
                    14 views
                    0 likes
                    Last Post space_trader  
                    Started by soon123, Today, 12:18 AM
                    0 responses
                    10 views
                    0 likes
                    Last Post soon123
                    by soon123
                     
                    Started by AxelrodWins, Yesterday, 07:07 PM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Marco  
                    Working...
                    X