ibandsonarray

 

I'm attempting to calculate bollinger bands based on a ratio of EURUSD/USDCHF.

I have figured out how to make the indicator show the ratio, i'm now trying to make it calculate the bollinger bands on the ratio.

The RED LINE with ibandsonarray at the end of this code is supposed to give me the upper, lower and the mean values.

For some reason i'm not getting the upper,lower,mean values.

Basically what i'm doing is storing the ratio into an ARRAY and applying ibandsonarray to the ARRAY to determine the bollinger bands values. The values come out to be zero. What I'm I doing wrong?

How do I use the ibandsonarray to determine the upper,lower,mean of the stored array?


//this is the complete indicator code
#property indicator_separate_window
#property indicator_buffers 5
datetime x;
#property indicator_color1 Black
#property indicator_color2 Blue
extern string Pair1="EURUSD";
extern string Pair2="USDCHF";
extern int Periood=2;
extern int BandsPeriod=90;
extern int BandsShift=0;
extern double BandsDeviations=2.0;
double Correl1_Buffer[];
double ExtMapBuffer2[];
double MovingBuffer[];
double UpperBuffer[];
double LowerBuffer[];
int init()
{
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Correl1_Buffer);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(1,ExtMapBuffer2);
return(0);
}
int deinit()
{ return(0);
}


int start()

{
int k,bar, limit1;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit1=Bars-IndicatorCounted();
//for(bar=0; bar<limit1; bar++)
//ExtMapBuffer1[bar] = iCCI(NULL,0,14,PRICE_TYPICAL,bar);

//int counted_bars=IndicatorCounted();
int limit=BarsPerWindow();
int koht, count, shift;
double sum1, sum2, correl, first, second, third, average1, average2;
double deviation;
double sum,oldval,newres;
if(counted_bars<1)
for(int ii=1;ii<=BandsPeriod;ii++)
{
MovingBuffer[Bars-ii]=EMPTY_VALUE;
UpperBuffer[Bars-ii]=EMPTY_VALUE;
LowerBuffer[Bars-ii]=EMPTY_VALUE;
}
//----

double array1[][6];
double array2[][6];

shift=1;
if(x!=iTime(NULL, 0, 0)) shift=limit;//makes only by creation of a new bar
ArrayCopyRates(array1, Pair1, NULL);
ArrayCopyRates(array2, Pair2, NULL);
koht=2;
count=ArraySize(array1);

while(shift>0)
{
sum1=0; sum2=0;
for(int i=1; i<Periood; i++)
{
sum1+=array1[shift+i][koht];
sum2+=array2[shift+i][koht];
}
average1=sum1/(Periood-1);
average2=sum2/(Periood-1);
first=0; second=0; third=0;
for(int c=1; c<Periood; c++)
{
first+=(array1[shift+c][koht]);
second+=(array2[shift+c][koht]);
third+=MathPow((array2[shift+c][koht]-average2), 2.0);
}

Correl1_Buffer[shift]=first/second;//PAIR EURUSD/USDCHF RATIO

shift--;
}
x=iTime(NULL, 0, 0);

//----
// return(0);



for(bar=0; bar<limit1; bar++)
ArraySetAsSeries(Correl1_Buffer,true);
//Print("count: ",count);
ExtMapBuffer2[bar]=iBandsOnArray(Correl1_Buffer,0,90,2,0,MODE_CLOSE,bar);
//ExtMapBuffer2[bar]=iMAOnArray(Correl1_Buffer,Bars,90,0,MODE_SMA,bar);
//ExtMapBuffer2[bar]=iEnvelopesOnArray(Correl1_Buffer,Bars,14,MODE_SMA,0,0.2,MODE_UPPER, 0);
//ExtMapBuffer2[bar]=iRSIOnArray(Correl1_Buffer,0,14,0);
Print("IMA: ",ExtMapBuffer2[1]);

return(0); }

 
There is mistake in the documentation. Instead of MODE_CLOSE You should use MODE_LOWER or MODE_UPPER depending from band
Reason: