Is there someone who can help me understand these 2 lines of coding?

limit = rates_total-prev_calculated // so this should mean that limit equal to total number of bars - the already calculated bars by the indicator

why limit will be incremented by 1?

Because, the coder wants to recalculate the last bar calculated one more time. An ensuring that the last closed bar is calculated with the proper values.

If prev_calculated is greater than 0, means there is a previous calculation.

Case 1:
Suppose there are 10 rates_total. And the indicator calculated 10 bars, that is prev_calculated = 10.

In cosecutive ticks, when there is a new bar:
rates_total is 11 and prev_calculated is 10.

Then, limit is calculated as follows:
limit = 11 - 10 = 1
limit++ = 2

In the for loop, the code will be performed in the last 1 previous bar and the current bar (i<2).

Case 2:
Suppose there are 10 rates_total. And the indicator calculated 10 bars, that is prev_calculated = 10.

In cosecutive ticks, before a new bar is formed:
rates_total is 10 and prev_calculated is 10.

Then, limit is calculated as follows:
limit = 10 - 10 = 0
limit++ = 1

In the for loop, the code will be performed only in the current bar.

Thank you so much, :pray: