Close[n] In MT5

 
In MT4, there is a function called Close[n], what's this function in MT5??
 
JHenry:
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]

 
mladen:

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... 

 
JHenry:

"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

 
mladen:

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

Thank you very much, mladen!!!!!!!!!!!
 
Mladen Rakic #:

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.

 
Mladen Rakic #: To use it on global scope, do like this :
Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), 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. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
Reason: