Here’s the code:
//+------------------------------------------------------------------+
//| xMeterDiff.mq4 |
//| Nondisclosure007 |
//| http://no.link.yet |
//+------------------------------------------------------------------+
#property copyright "Nondisclosure007"
#property link "http://no.link.yet"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 3
//--- plot Up
#property indicator_label1 "Up"
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 clrBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//--- plot Down
#property indicator_label2 "Down"
#property indicator_type2 DRAW_HISTOGRAM
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
//--- plot Change
#property indicator_label3 "Change"
#property indicator_type3 DRAW_HISTOGRAM
#property indicator_style3 STYLE_SOLID
#property indicator_color3 clrDarkSlateGray
#property indicator_width3 2
//--- indicator buffers
double UpBuffer[];
double DownBuffer[];
double ChangeBuffer[];
double DataBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
IndicatorBuffers(3);
SetIndexBuffer(0,UpBuffer);
SetIndexLabel(0,"Up-Xmeter");
SetIndexBuffer(1,DownBuffer);
SetIndexLabel(1,"Down-Xmeter");
SetIndexBuffer(2,ChangeBuffer);
SetIndexLabel(2,"Change-Xmeter");
SetIndexBuffer(3,DataBuffer);
SetIndexLabel(3,NULL);
SetIndexStyle(3,DRAW_NONE);
int iDigits=(int)MarketInfo(Symbol(),MODE_DIGITS);
IndicatorDigits(iDigits);
int found=-1;
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---
int limit=rates_total-prev_calculated;
int i=0;
if(prev_calculated>0)
{
limit++;
}
for(i=0;i<limit;i++)
{
DataBuffer[i]=High[i]-Low[i];
}
double Diff=0.0;
for(i=0;i<limit;i++)
{
Diff=DataBuffer[i]-DataBuffer[i+1];
if(Diff>DataBuffer[i+1])
{
UpBuffer[i]=Diff;
DownBuffer[i]=0.0;
ChangeBuffer[i]=0.0;
}
if(Diff<DataBuffer[i+1])
{
DownBuffer[i]=Diff;
UpBuffer[i]=0.0;
ChangeBuffer[i]=0.0;
}
if(Diff==DataBuffer[+1])
{
ChangeBuffer[i]=Diff;
DownBuffer[i]=0.0;
UpBuffer[i]=0.0;
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
I get the array out of range error on this line:
Diff=DataBuffer[i]-DataBuffer[i+1];
Now, I think I now why (At the end of the loop, there is no DataBuffer[i+1]). I’m just not sure how to avoid it.
This indicator is finding out what the difference is of a candle’s range - the previous candle’s range. Not all that useful, but I’ve got other things in mind. If this can be solved, then the rest will be easy.
Thanks.