Home Technical Indicator Post

Understanding the isNewBar Indicator for MetaTrader 5

Attachments
107.zip (1.21 KB, Download 0 times)

As traders, we often need to know when a new bar appears on our chosen timeframe. This is where the isNewBar function comes in handy. Let’s dive into how this works!

When you first call the isNewBar() function, the current bar isn't considered a new one yet. The function tracks the time of the current bar, so it knows that the next bar will be new. The code is commented for clarity, making it straightforward to follow.

Be mindful when using this method, which is commonly utilized in MQL4 - the bars counting using the Bars function (you can find more on this here).

In MQL5, this will only function if your chart's max bars setting is set to Unlimited:

isNewBar

When new bars appear, the Bars function will return an increasing number of bars. However, if the max bars in your chart is capped (like 10,000 bars), this approach won't work! It's an easy check to perform.

This is why it's crucial to keep track of the times of the last bars and compare them, as the time remains unchanged until a bar is completed. This method is incorporated into the indicator for better accuracy.

Related Posts

Comments (0)