Trouble with iEnvelopes and iEnvelopesOnArray

 
Hello:

I am a new user with any experience programing but I am studing to learn. I have several questions about these functions. I would like to explain the problem.

1) Which is the difference between iEnvelopes and iEnvelopesOn array?

2) I do not understand which is the importance of a "buffer" and if I can avoid it.

3) Can I send you the code to open position of my EA?, I have tried everything. I have troubles with my code to close and to open positions . However I think the problem is the same because the criteria to close is similar to the criteria to open. So I think I have the same problem for both cases. I have used iEnvelopes and iEnvelopesOnArray, I have used variables and arrays type double. I really do not know what to do. I have search in MQL4.com and in this forum. I HAVE DONE THE HOMEWORK but I do not know what to do.

4) Is There something wrong with the parameters for the function iEnvelopes?. When you see the help of MT4, you find the explanation about iEnvelopes has 8 inputs, but when you see the example of MT4 there are only 7 input used, So I am confused about that

5) Furthermore, I do not understand the difference between parameteres "int ma_shift" and "int shift". I think "int shift" is useful to explain you to want the envelope for time 0, 1, 3, etc. But which is the function of int ma_shift?



//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{


// Declaración de variables

double takeprofit;
int i,k,error, totalOrders,count,res,handled,NoOrdenes;
double Upperband[],Lowerband[],BandaSup1,BandaInf1,BandaSup5,BandaInf5;
double sum,newres;
int limit=20;

ArrayResize(Upperband,limit);
ArrayResize(Lowerband,limit);
ArraySetAsSeries(Upperband,true);
ArraySetAsSeries(Lowerband,true);

// Calculo de la banda y de sus bandas extremas
//---- go trading only for first tiks of new bar
// if(Volume[0]>1) return;
//---- get Bandas superior e inferior de los sobres

/*
for(i=0; i<limit; i++)

{
Upperband[i]=iEnvelopes(NULL,PERIOD_H1,BandsPeriod,MODE_EMA,0,PRICE_CLOSE, desviation,MODE_UPPER,i);
Lowerband[i]=iEnvelopes(NULL,PERIOD_H1,BandsPeriod,MODE_EMA,0,PRICE_CLOSE, desviation,MODE_LOWER,i);
En caso de que la función ArraySetAsSeries no funciones tendrés que intentar la segunda función

Upperband[i]=iEnvelopesOnArray(Close,limit,BandsPeriod,MODE_EMA,0,desviation, MODE_UPPER,i);
Upperband[i]=iEnvelopesOnArray(Close,limit,BandsPeriod,MODE_EMA,0,desviation, MODE_UPPER,i);
Print("En el primer caso el balor de la banda superior para los periodos, 0 ,1, 2 son", Upperband[0],Upperband[1],Upperband[2]);
Print("En el primer caso el balor de la banda inferior para los periodos, 0 ,1, 2 son", Lowerband[0],Lowerband[1],Lowerband[2]);
}
*/
BandaSup1=iEnvelopes(NULL,PERIOD_H1,BandsPeriod,MODE_EMA,5,PRICE_CLOSE,desviation, MODE_UPPER,1);
BandaInf1=iEnvelopes(NULL,PERIOD_H1,BandsPeriod,MODE_EMA,5,PRICE_CLOSE,desviation, MODE_LOWER,1);

BandaSup5=iEnvelopes(NULL,PERIOD_H1,BandsPeriod,MODE_EMA,5,PRICE_CLOSE,desviation, MODE_UPPER,4);
BandaInf5=iEnvelopes(NULL,PERIOD_H1,BandsPeriod,MODE_EMA,5,PRICE_CLOSE,desviation, MODE_LOWER,4);

//---- sell conditions
if((BandaInf1<Close[1]<BandaSup1) && (Close[5]>BandaSup5)&&(Close[1]<Close[5]))
{
Stop= High[Highest(NULL,PERIOD_H1,MODE_HIGH,10,1)]+ 40*Point;
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Stop,0,"Abrio un Corto",MAGICMA, 0,Red);
//El siguiente condicional lo escribí en el caso de que no se pudiera abrir la orden

if(res!=TRUE)
{
error=GetLastError();
Print("LastError = ",error);
}

return;
}
//---- buy conditions
if((BandaSup1>=Close[1]>=BandaInf1)&&(Close[4]<=BandaInf5)&&(Close[1]>Close[4]))
{
Stop= Low[Lowest(NULL,PERIOD_H1,MODE_LOW,10,1)]-40*Point;
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Stop,0,"",MAGICMA,0,Blue);

return;
}


Reason: