WHY: prev_calculated becomes 0 again after the first running of the indicator?

 

According to MT4 description, prev_calculated should be the same as rates_total after the first run of indicator.

However, I found that prev_calculated becomes 0 again in the forth tick, and then all rest are same as rates_total.

Why this happens? Is it expected to be the same as rates_total after the first run??

MT4

 
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. It becomes zero whenever it is necessary to recalculate all bars, likely #6 or #7.
    Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent and prices are valid.