51 lines
1.5 KiB
Markdown
51 lines
1.5 KiB
Markdown
# BarIndex
|
|
|
|
in pine script bar_index reffers to current candle number, in reversal indexing.
|
|
in MQL for accessing bar_index to calculate indicator data, we have to do something like this:
|
|
|
|
```mq4
|
|
int OnCalculate(const int rates_total,
|
|
const int prev_calculated,
|
|
const datetime &time[],
|
|
const double &open[],
|
|
const double &high[],
|
|
const double &low[],
|
|
const double &close[],
|
|
const long &tick_volume[],
|
|
const long &volume[],
|
|
const int &spread[])
|
|
{
|
|
//
|
|
// here we define our limit ...
|
|
int limit = rates_total - prev_calculated;
|
|
|
|
//
|
|
// if our indicator requires some candles to pass as a length,
|
|
// and then start calculating by past passed values, by this way
|
|
// we are going to inform MQL Compiler, which do nothing, until
|
|
// required length passed ...
|
|
if(rates_total <= InpBullsPeriod) {
|
|
return(0);
|
|
}
|
|
|
|
//
|
|
// because bar index a zero start indexing system, for fixing
|
|
// qctual indexing in for loops, we have to call this ...
|
|
if(prev_calculated > 0) {
|
|
limit++;
|
|
}
|
|
|
|
//
|
|
// Loop through Bar Indexes ...
|
|
for(int i = 0; i < limit; i++) {
|
|
//
|
|
// Filling Exists Buffers, based on current Bar Index and required Conditions ...
|
|
ExtTempBuffer[i]=iMA(NULL,0,InpBullsPeriod,0,MODE_EMA,PRICE_CLOSE,i);
|
|
ExtBullsBuffer[i]=high[i]-ExtTempBuffer[i];
|
|
}
|
|
|
|
//
|
|
return(rates_total);
|
|
}
|
|
```
|