>> Please update your country flag in your profile. Thank you 🙂 <<
BARINDEX will always return the bars quantity of the opened chart. So sorry if I don’t understand but what do you want to do exactly please? Because if you use BARINDEX as your period for your moving average, it will instantly calculate the good mean for all the data displayed on your chart.
To know if you are on the last bar of the chart, you can use the code snippet below:
1
2
LastBarOnChart=currenttime=opentimeanddate=today
returnLastBarOnChart
But because the history is only read once, in your case, you will not be able to use it as a period for your indicator automatically. Another way would be to make loop in the past starting only on the current bar and with the last barindex as the period.. But still, ProBuilder doesn’t allow to plot curves in the past..
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue