Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How does the bar close recognized in OnBarUpdate on Calculate!=Calculate.OnBarClose

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

    How does the bar close recognized in OnBarUpdate on Calculate!=Calculate.OnBarClose

    Hi

    OnBarUpdate documentation doesn't give much details about how to handle the end of the bar data, when using other options else than OnBarClose. If I understand between the lines, they way it may handled is to use IsFirstTickOfBar of the next bar to handle it. In this case +1 needs to be added to any barsAgo. Is that right? is that the case in any bar type including volume?

    Could you provide a sample code to show this?

    #2
    Hello Shai Samuel,

    Thank you for your post.

    When the calculate property is not set to OnBarClose and is instead set to OnEachTick or OnPriceChange, you may use IsFirstTickOfBar in a conditional statement for any code you would like to run when each bar is closed. This may be achieved using a conditional statement, such as the following example provided in the help guide:


    Code:
    // On a tick by tick strategy the only way you know when a bar is closed is when
    // the IsFirsTickOfBar is true.
    protected override void OnBarUpdate()
    {
        // Only process entry signals on a bar by bar basis (not tick by tick)
        if (IsFirstTickOfBar)
        {
            if (CCI(20)[1] < -250)
                  EnterLong();
            return;
        }
    
        // Process exit signals tick by tick
        if (CCI(20)[0] > 250)
            ExitLong();
    }

    In the case of adding +1 to any barsAgo, that depends on what you are looking to achieve. Essentially, when the current bar is still working it would be considered to be barsAgo[0], then once IsFirstTickOfBar becomes true that bar becomes barsAgo[1] and the new bar that is opened would now be barsAgo[0]. For volume and tick-based bars, you could reference Bars.TickCount and Volume[0] to verify if the number of ticks or volume satisfies the amount to build a new bar. Something important to keep in mind is that for any bar types set to remove the last bar on the chart (such as renko bars), IsFirstTickOfBar always returns true.

    For additional information, please see the help guide section about IsFirstTickOfBar here:




    Please let us know if we may be of further assistance.

    Comment


      #3
      thank you Emily for you clear reply. Since your great example is about Strategy, just wanted to confirm that the same is true with Indicator. It is?

      Comment


        #4
        Hello Shai Samuel,

        Thank you for your note.

        That is correct, although the example was from a strategy, the same would be true with an indicator script. If you would like the script to run a particular line or block of code on bar close, you could use the condition "if (IsFirstTickOfBar)" for an indicator as well.

        If you have any additional questions, feel free to post them here.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X