I can't draw Envelopes on Array

 

Hi.

I can't solve this issue. I have to build an indicator that draws price ratio between two pairs and a Bollinger Bands or Envelopes.

I can draw Bolinger Bands without any problem but there is an issue drawing Envelopes...

Using debbugger seems that for cycle is not working properly.... Then I think there is an issue with EnvelopesOnArray syntax... Deviation must be an integer... I'm using now 1 and another value depends on user's choice...

This is the code:

//---- indicator settings

#property indicator_separate_window

#property indicator_buffers 6

#property indicator_color1 MediumBlue

#property indicator_color2 Red

#property indicator_color3 Red

#property indicator_color4 Green

#property indicator_color5 Green

#property indicator_color6 White

#property indicator_width1 2

//---- indicator parameters



enum Strategy{Envelopes,Bollinger};

enum Dev{Due=2,Tre=3,Quattro=4};

input Strategy Mode = 0;

input Dev Deviation = Due;

extern string FXPair1 = "EURUSD";

extern string FXPair2 = "GBPUSD";

extern int SignalMethod = MODE_SMA;

extern int SetPeriod=20;




datetime MostRecentBarStart;


//---- indicator buffers

double PriceRatio[];

double Upper1[];

double Upper2[];

double Lower1[];

double Lower2[];

double Center[];



//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- drawing settings

SetIndexStyle(0,DRAW_LINE, STYLE_SOLID,2);

SetIndexStyle(1,DRAW_LINE, STYLE_DOT);

SetIndexStyle(2,DRAW_LINE);

SetIndexStyle(3,DRAW_LINE, STYLE_DOT );

SetIndexStyle(4,DRAW_LINE);

SetIndexStyle(5,DRAW_LINE, STYLE_SOLID,2);

SetIndexDrawBegin(0,SetPeriod);

SetIndexDrawBegin(1,SetPeriod);

SetIndexDrawBegin(2,SetPeriod);

SetIndexDrawBegin(3,SetPeriod);

SetIndexDrawBegin(4,SetPeriod);

SetIndexDrawBegin(5,SetPeriod);

IndicatorDigits(Digits+1);

//---- indicator buffers mapping

SetIndexBuffer(0,PriceRatio);

SetIndexBuffer(1,Upper1);

SetIndexBuffer(2,Upper2);

SetIndexBuffer(3,Lower1);

SetIndexBuffer(4,Lower2);

SetIndexBuffer(5,Center);

//---- name for DataWindow and indicator subwindow label

IndicatorShortName("Spread Ratio Extended - 2014");

SetIndexLabel(0,"PriceRatio");

SetIndexLabel(1,"Upper1");

SetIndexLabel(2,"Upper2");

SetIndexLabel(3,"Lower1");

SetIndexLabel(4,"Lower2");

SetIndexLabel(5,"Center");

//---- initialization done

return(0);

}

//+------------------------------------------------------------------+

//| Moving Averages Convergence/Divergence |

//+------------------------------------------------------------------+

int start()

{

double limit;

int counted_bars=IndicatorCounted();

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;


RefreshRates();

//---- counted in the 1-st buffer

for(int i=0; i<limit; i++) {

//PriceRatio[i]=iMA(FXPair1,0,1,0,SignalMethod,PRICE_OPEN,i) / iMA(FXPair2,0,1,0,SignalMethod,PRICE_OPEN,i);

if (iOpen(FXPair2,Period(),i) == 0 ) {

continue;

}

PriceRatio[i] = iOpen(FXPair1,Period(),i) / iOpen(FXPair2,Period(),i);

}

//---- signal line counted in the 2-nd buffer

RefreshRates();

for(i=0; i<limit; i++) {


Center[i]=iMAOnArray(PriceRatio,0,SetPeriod,0,SignalMethod,i);

if(Mode == 0) {

Upper1[i]=iEnvelopesOnArray(Center, 0, SetPeriod, SignalMethod, 0, 1, MODE_UPPER, i);

Upper1[i]=iEnvelopesOnArray(Center, 0, SetPeriod, SignalMethod, 0, Deviation, MODE_UPPER, i);

Lower1[i]=iEnvelopesOnArray(Center, 0, SetPeriod, SignalMethod, 0, 1, MODE_LOWER, i);

Lower2[i]=iEnvelopesOnArray(Center, 0, SetPeriod, SignalMethod, 0, Deviation, MODE_LOWER, i);


}

if(Mode == 1) {

Upper1[i]=iBandsOnArray (PriceRatio, 0, SetPeriod, 1, 0, MODE_UPPER,i);

Upper2[i]=iBandsOnArray (PriceRatio, 0, SetPeriod, Deviation, 0, MODE_UPPER,i);

Lower1[i]=iBandsOnArray (PriceRatio, 0, SetPeriod, 1, 0, MODE_LOWER,i);

Lower2[i]=iBandsOnArray (PriceRatio, 0, SetPeriod, Deviation, 0, MODE_LOWER,i);

}

}





if (MostRecentBarStart != Time[0])

{

// Store the time of the current bar, preventing further action during this bar

MostRecentBarStart = Time[0];

// LevelVerify();

}

//---- done

return(0);

}

//+------------------------------------------------------------------+



int LevelVerify(){

/* if(PriceRatio[1]>Upper1[1] && PriceRatio[1]<Upper2[1]) Alert("Tra 1 e 2 UP" + " " + PriceRatio[1] + " " + Upper1[1] + " " + Upper2[1]);

if(PriceRatio[1]<Lower1[1] && PriceRatio[1]>Lower2[1]) Alert("Tra 1 e 2 DW" + PriceRatio[1] + " " + Lower1[1] + " " + Lower2[1]);

if(PriceRatio[1]>Upper1[1] && PriceRatio[1]>Upper2[1]) Alert("Oltre il max UP" + PriceRatio[1] + " " + Upper1[1] + " " + Upper2[1]);

if(PriceRatio[1]<Lower1[1] && PriceRatio[1]<Lower2[1]) Alert("Oltre il max DW" + PriceRatio[1] + " " + Lower1[1] + " " + Lower2[1]);*/

}

And theese are the screenshots:

Bollinger activated: https://www.mql5.com/en/charts/1816065/eurchf-h1-armada-markets?bind=1

Envelopes Activated: https://www.mql5.com/en/charts/1816066/eurchf-h1-armada-markets

Thnaks

 
//---- indicator settings

#property indicator_separate_window

#property indicator_buffers 6

#property indicator_color1 MediumBlue

#property indicator_color2 Red

#property indicator_color3 Red

#property indicator_color4 Green

#property indicator_color5 Green

#property indicator_color6 White

#property indicator_width1 2

//---- indicator parameters



enum Strategy{Envelopes,Bollinger};

enum Dev{Due=2,Tre=3,Quattro=4};

input Strategy Mode = 0;

input Dev Deviation = Due;

extern string FXPair1 = "EURUSD";

extern string FXPair2 = "GBPUSD";

extern int SignalMethod = MODE_SMA;

extern int SetPeriod=20;




datetime MostRecentBarStart;


//---- indicator buffers

double PriceRatio[];

double Upper1[];

double Upper2[];

double Lower1[];

double Lower2[];

double Center[];



//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- drawing settings

SetIndexStyle(0,DRAW_LINE, STYLE_SOLID,2);

SetIndexStyle(1,DRAW_LINE, STYLE_DOT);

SetIndexStyle(2,DRAW_LINE);

SetIndexStyle(3,DRAW_LINE, STYLE_DOT );

SetIndexStyle(4,DRAW_LINE);

SetIndexStyle(5,DRAW_LINE, STYLE_SOLID,2);

SetIndexDrawBegin(0,SetPeriod);

SetIndexDrawBegin(1,SetPeriod);

SetIndexDrawBegin(2,SetPeriod);

SetIndexDrawBegin(3,SetPeriod);

SetIndexDrawBegin(4,SetPeriod);

SetIndexDrawBegin(5,SetPeriod);

IndicatorDigits(Digits+1);

//---- indicator buffers mapping

SetIndexBuffer(0,PriceRatio);

SetIndexBuffer(1,Upper1);

SetIndexBuffer(2,Upper2);

SetIndexBuffer(3,Lower1);

SetIndexBuffer(4,Lower2);

SetIndexBuffer(5,Center);

//---- name for DataWindow and indicator subwindow label

IndicatorShortName("Spread Ratio Extended - 2014");

SetIndexLabel(0,"PriceRatio");

SetIndexLabel(1,"Upper1");

SetIndexLabel(2,"Upper2");

SetIndexLabel(3,"Lower1");

SetIndexLabel(4,"Lower2");

SetIndexLabel(5,"Center");

//---- initialization done

return(0);

}

//+------------------------------------------------------------------+

//| Moving Averages Convergence/Divergence |

//+------------------------------------------------------------------+

int start()

{

double limit;

int counted_bars=IndicatorCounted();

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;


RefreshRates();

//---- counted in the 1-st buffer

for(int i=0; i<limit; i++) {

//PriceRatio[i]=iMA(FXPair1,0,1,0,SignalMethod,PRICE_OPEN,i) / iMA(FXPair2,0,1,0,SignalMethod,PRICE_OPEN,i);

if (iOpen(FXPair2,Period(),i) == 0 ) {

continue;

}

PriceRatio[i] = iOpen(FXPair1,Period(),i) / iOpen(FXPair2,Period(),i);

}

//---- signal line counted in the 2-nd buffer

RefreshRates();

for(i=0; i<limit; i++) {


Center[i]=iMAOnArray(PriceRatio,0,SetPeriod,0,SignalMethod,i);

if(Mode == 0) {

Upper1[i]=iEnvelopesOnArray(Center, 0, SetPeriod, SignalMethod, 0, 1, MODE_UPPER, i);

Upper1[i]=iEnvelopesOnArray(Center, 0, SetPeriod, SignalMethod, 0, Deviation, MODE_UPPER, i);

Lower1[i]=iEnvelopesOnArray(Center, 0, SetPeriod, SignalMethod, 0, 1, MODE_LOWER, i);

Lower2[i]=iEnvelopesOnArray(Center, 0, SetPeriod, SignalMethod, 0, Deviation, MODE_LOWER, i);


}

if(Mode == 1) {

Upper1[i]=iBandsOnArray (PriceRatio, 0, SetPeriod, 1, 0, MODE_UPPER,i);

Upper2[i]=iBandsOnArray (PriceRatio, 0, SetPeriod, Deviation, 0, MODE_UPPER,i);

Lower1[i]=iBandsOnArray (PriceRatio, 0, SetPeriod, 1, 0, MODE_LOWER,i);

Lower2[i]=iBandsOnArray (PriceRatio, 0, SetPeriod, Deviation, 0, MODE_LOWER,i);

}

}





if (MostRecentBarStart != Time[0])

{

// Store the time of the current bar, preventing further action during this bar

MostRecentBarStart = Time[0];

// LevelVerify();

}

//---- done

return(0);

}

//+------------------------------------------------------------------+



int LevelVerify(){

/* if(PriceRatio[1]>Upper1[1] && PriceRatio[1]<Upper2[1]) Alert("Tra 1 e 2 UP" + " " + PriceRatio[1] + " " + Upper1[1] + " " + Upper2[1]);

if(PriceRatio[1]<Lower1[1] && PriceRatio[1]>Lower2[1]) Alert("Tra 1 e 2 DW" + PriceRatio[1] + " " + Lower1[1] + " " + Lower2[1]);

if(PriceRatio[1]>Upper1[1] && PriceRatio[1]>Upper2[1]) Alert("Oltre il max UP" + PriceRatio[1] + " " + Upper1[1] + " " + Upper2[1]);

if(PriceRatio[1]<Lower1[1] && PriceRatio[1]<Lower2[1]) Alert("Oltre il max DW" + PriceRatio[1] + " " + Lower1[1] + " " + Lower2[1]);*/

}