Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to know when a bar closes when CalculateOnBarClose=false

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

    How to know when a bar closes when CalculateOnBarClose=false

    If I have a strategy the has CalculateOnBarClose = false because I want to get OnBarUpdate() events for each tick, but I also want to make some decisions based on how a bar closes. So how can I determine when a bar closes when I have CalculateOnBarClose = false?

    I'm using NT 6.5

    #2
    Hello Shodson,

    The opening of the next bar is the same event as the closing of the prior bar. You can use FirstTickOfBar to identify this. The reference sample below can help implementing this.

    Separating logic to either calculate once on bar close or on every tick
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks, I have a follow-up

      If I am using multiple time frames, and my primary time frame is 15min and my secondary time frame is 1min then my OnBarUpdate() will be called 16 times: 15 times for BarsInProgress 1 and once for BarsInProgress 0, even if I have CalculateOnBarClose set to true, correct?
      Last edited by shodson; 06-29-2010, 10:33 AM.

      Comment


        #4
        Hello Shodson,

        I'm not sure the exact number of calls done. I suggest adding a counter if you would like to track this. When using CalculateOnBarClose == true, OnBarUpdate is called only once per bar. When set to false it will update for each incoming tick.

        The reference sample below is good for understanding the sequence of OnBarUpdate() calls in a multi time frame strategy:
        Backtesting NinjaScript Strategies with an intrabar granularity

        Excerpted below:
        When working with multiple bar series objects it is important to understand the sequential order in which the OnBarUpdate() method is triggered. The bars will always run with the primary first followed by the secondary and so on.

        Important: Primary bars will always execute before the secondary bar series.
        If a bar is timestamped as 12:00PM on the 5min bar series, the call order between the equally timestamped 12:00PM bar on the 1min bar series is like this:
        12:00PM 5min
        12:00PM 1min
        12:01PM 1min
        12:02PM 1min
        12:03PM 1min
        12:04PM 1min
        12:05PM 5min
        12:05PM 1min
        Ryan M.NinjaTrader Customer Service

        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