Bars variable returning 0
Sadi: it is in the OnInit() function of the indicator.
Don't try to use any price or server related functions in
OnInit (or on load,) as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
Thank you.
So, how do I make it run only once (that's all I need for now), and make sure it only runs only when the bars have been loaded?
So, how do I make it run only once (that's all I need for now), and make sure it only runs only when the bars have been loaded?
Sadi:
Thank you.
So, how do I make it run only once (that's all I need for now), and make sure it only runs only when the bars have been loaded?
Thank you.
So, how do I make it run only once (that's all I need for now), and make sure it only runs only when the bars have been loaded?
int OnCalculate (const int rates_total, // size of input time series const int prev_calculated, // bars handled in previous call const datetime& time[], // Time const double& open[], // Open const double& high[], // High const double& low[], // Low const double& close[], // Close const long& tick_volume[], // Tick Volume const long& volume[], // Real Volume const int& spread[] // Spread ) { if ( prev_calculated == 0 ) { // Do all functions you cannot do in OnInit() here. } // . . . }
Perfect. Thank you!
Any hints on why this happens?