iMOnArray

[Deleted]  

Dear all
I've started my first EXPERT in MQL4 2 weeks ago.
I decided to use iMAOnArray in my program
but when i use output of this function, it's equal
zero(0) and i put a Comment with value of this function but i saw it zero(0),
But when i plot it in a Buffer in an Indicator it's not equal zero.
i dont know what must i do and i need your experiences.
best regard.

[Deleted]  

Yeah, I'm having a similar problem with iBandsOnArray().

I think these are functions that are only available within an indicator and not in the interactive thread. Just like a buffer, you cannot use in an EA.

zzuegg
1503
zzuegg  
kennyhubbard:

Yeah, I'm having a similar problem with iBandsOnArray().

I think these are functions that are only available within an indicator and not in the interactive thread. Just like a buffer, you cannot use in an EA.

nope, it works within the EA, but, the most common error is that the buffer on which the calculation should be is not filled correctly.

double buffer[];
ArrayResize(buffer,calcPeriod);
for(int i=0;i<calcPeriod;i++){
  buffer[i]=//Whatever values you want;
}
double result=iMAOnArray(buffer,0,calcPeriod,0,MODE_SMA,0);
[Deleted]  

Hi zzuegg,

I see that you are correct. Please could you have a quick look at this and see if you can see what I am doing wrong. I am trying to calculate a bolliger band on the On Balance Volume indicator :-

int OBV_Check()
{
double
   Buffer[40],
   MABuffer[20];
   for(int z = 0;z<40;z++)Buffer[z] = iOBV(NULL,0,PRICE_CLOSE,z);          //load OBV into buffer
   for(z = 0;z<20;z++)MABuffer[z] = iMAOnArray(Buffer,0,20,0,MODE_SMA,z);  //calculate MA of buffer ie center of Bol band
   //ArraySetAsSeries(MABuffer,true);    
double
   Bands_Vol_Upper = iBandsOnArray(MABuffer,0,20,2,0,MODE_UPPER,0),        //
   Bands_Vol_Lower = iBandsOnArray(MABuffer,0,20,2,0,MODE_LOWER,0);
   Comment("Upper = " + Bands_Vol_Upper + " /Lower = " + Bands_Vol_Lower);
   if(iOBV(NULL,0,PRICE_CLOSE,1)<Bands_Vol_Lower)return(OP_BUY);
   if(iOBV(NULL,0,PRICE_CLOSE,1)>Bands_Vol_Upper)return(OP_SELL);
   return(NO_RESULT);
}

BTW, I set the first buffer to be twice the averaging period since I assume that the furthest left element will still need 20 bars for calculation.

I am also not sure if the ArraySetAsSeries is required or not?

Thanks

Kenny

zzuegg
1503
zzuegg  

hi, sadly you code looks good. i also tryed to do this by the way you are doing. by definition your code should work, but i never figured out why its not.

try this workaround i am using: it's not the nice good clean way, but it should work, and there is lot of optimizing space left ;)

int OBV_Check()
{
   double Buffer[20],
          MABuffer[20];
   for(int i=0;i<20;i++){
     for(int j=0;j<20;j++){
       Buffer[j]=iOBV(NULL,0,PRICE_CLOSE,j+i);
     }
     MABuffer[i]= iMAOnArray(Buffer,0,20,0,MODE_SMA,0);
   } 
   double Bands_Vol_Upper = iBandsOnArray(MABuffer,0,20,2,0,MODE_UPPER,0);
   double Bands_Vol_Lower = iBandsOnArray(MABuffer,0,20,2,0,MODE_LOWER,0);
   Comment("Upper = " + Bands_Vol_Upper + " /Lower = " + Bands_Vol_Lower);
   if(iOBV(NULL,0,PRICE_CLOSE,1)<Bands_Vol_Lower)return(OP_BUY);
   if(iOBV(NULL,0,PRICE_CLOSE,1)>Bands_Vol_Upper)return(OP_SELL);
   return(NO_RESULT);
}                 
[Deleted]  

Thanks, will give it a bash. My code does produce numbers but they are different to the numbers on the chart when I load the indicators manually.

[Deleted]  

hi

i have this problem too but i don't know what is the problem

i really thank of all friends




kennyhubbard:

Thanks, will give it a bash. My code does produce numbers but they are different to the numbers on the chart when I load the indicators manually.

[Deleted]  

hi

i found that if you use "ArraySetAsSeries(xx,true);" and it fixed my problem

and when you use ixxArray(aa,Bars,...);,you must use Bars. if you use a number it won't work