In MT4, there is a function called Close[n], what's this function in MT5??
Depends on where you are
If you are in OnCalculate() of an indicator then you have the following format :
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 );
but if you want a "general solution" than the closes to what you are looking for is the following :
double aclose[]; CopyClose(_Symbol,_Period,n,1,aclose);
and then use the aclose[0] as you used to use the Close[n]
Depends on where you are
If you are in OnCalculate() of an indicator then you have the following format :
but if you want a "general solution" than the closes to what you are looking for is the following :
and then use the aclose[0] as you used to use the Close[n]
"double aclose[]; CopyClose(_Symbol,_Period,n,1,aclose);" doesn't work in global scope, I receive this message:
'CopyClose' - declaration without type...
"double aclose[]; CopyClose(_Symbol,_Period,n,1,aclose);" doesn't work in global scope, I receive this message:
'CopyClose' - declaration without type...
To use it on global scope, do like this :
double aclose[]; int temp = CopyClose(_Symbol,_Period,n,1,aclose); // replace n with some constant value // or a reference to some existing variable
But then you lose control of it (temp will be -1, if the copy is not successful)
To access the aclose, use the aclose[0] for the upper example, since that element is going to have the value of Close[n] stored in it
To use it on global scope, do like this :
But then you lose control of it (temp will be -1, if the copy is not successful)
To access the aclose, use the aclose[0] for the upper example, since that element is going to have the value of Close[n] stored in it
Depends on where you are
If you are in OnCalculate() of an indicator then you have the following format :
but if you want a "general solution" than the closes to what you are looking for is the following :
and then use the aclose[0] as you used to use the Close[n]
Excellent! Thank you.
- 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.
- A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use