Please Help Me with IMAOnArray on EA piece of code

 

.

 

Hi,

 I've got an EA that needs to find the last  5 WPR's crosses of (-50 value).

 I've made it in a indicator with success:

extern int Periodo=20;
extern int Periodo_Smooth=5;

double wprBuffer[];
double SmoothBuffer[];


for(int i=0; i<Bars; i++)
{
   wprBuffer[i]=(iWPR(NULL,0,Periodo,i) + 50);
}

for(i=0; i<Bars; i++)
{
   SmoothBuffer[i]=iMAOnArray(wprBuffer,Bars,Periodo_Smooth,0,MODE_SMA,i);
}

 

Now I need it in an EA but I can not do it directly (without using this indicator with iCustom function)!

I've read a lot of posts about iMAonArray() and tryed a lot of things but my limited skills don't help me.

This is how I think it should work. But it do not work!

extern int Periodo = 20;
extern int Periodo_Smooth = 5;

int index=0, CrossAt[5], ArrayIndex = 0;

double DIF_MA[2]; WPR[];


// Code to find crosses at bar number index

index=0;
ArrayIndex = 0;

ArrayResize(WPR,Periodo+1);
ArraySetAsSeries(WPR,true);

     
for (int g=0; g<=Periodo; g++)
{
   WPR[g] = iWPR(NULL,0,Periodo,g);
}
     

while(ArrayIndex <= 5)
{       
   DIF_MA[0] = (iMAOnArray(WPR,Periodo,Periodo_Smooth,0,MODE_SMA,index) +50);
   DIF_MA[1] = (iMAOnArray(WPR,Periodo,Periodo_Smooth,0,MODE_SMA,index+1) +50);

  if( (DIF_MA[0]>0 && DIF_MA[1]<=0) || (DIF_MA[0]<0 && DIF_MA[1]>=0) )      // if cross found
   {
    CrossAt[ArrayIndex] = index;
    ArrayIndex++;
   }
   index++;
}
    

 

 Please help me discover how to use iMAOnArray() on this case! :)

 

.

 

.

It's so frustrating.. Because it doesn't give any error..

Looking to the Journal separator it just stays stopped  in the inputs line after the "loaded successfully".

This way I cannot know what is wrong.. :(

 . 

 

What do you expect and what do you get instead?

 
"Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
 

.

It really does not work!

It compiles without errors.

But when I run a backtest nothing happens.

I belive that with this part of code it is too slow. I belive something in that code is slowing down (almoast stoped!) the EA.

As I said.. I belive.. Because it doesn't do nothing!

.

The Expert Advisor with the iCustom function calling the indicator with iMAOnArray is working well.

That way, it means that this part of code is the one that is causing the troubles.

Sory but I cannot put the EA in here since the "property copyright" don't allow me.

 

.

 Here is a printscreen of the journal:

  

 . 

 
gooly:

What do you expect and what do you get instead?

Like I said.. I don't get nothing!

What I want to get is this:


 

 

Please, can someone help me with this? I'm stuck in this.. :(

Is that commented piece of code good? Or does it have same error?

 
Use the SRC button and copy & paste your code
 
extern int Periodo = 20;
extern int Periodo_Smooth = 5;

int index=0, CrossAt[5], ArrayIndex = 0;

double DIF_MA[2]; WPR[];


// Code to find crosses at bar number index

index=0;
ArrayIndex = 0;

ArrayResize(WPR,Periodo+1);
ArraySetAsSeries(WPR,true);

     
for (int g=0; g<=Periodo; g++)
{
   WPR[g] = iWPR(NULL,0,Periodo,g);
}
     

while(ArrayIndex <= 5)
{       
   DIF_MA[0] = (iMAOnArray(WPR,Periodo,Periodo_Smooth,0,MODE_SMA,index) +50);
   DIF_MA[1] = (iMAOnArray(WPR,Periodo,Periodo_Smooth,0,MODE_SMA,index+1) +50);

  if( (DIF_MA[0]>0 && DIF_MA[1]<=0) || (DIF_MA[0]<0 && DIF_MA[1]>=0) )      // if cross found
   {
    CrossAt[ArrayIndex] = index;
    ArrayIndex++;
   }
   index++;
}
    
 

Please post code that compiles

double DIF_MA[2]; WPR[];

WPR[] is declared without type.

If the code that you show doesn't compile, then it cannot be the code that you are using.

while(ArrayIndex <= 5)
{       
   DIF_MA[0] = (iMAOnArray(WPR,Periodo,Periodo_Smooth,0,MODE_SMA,index) +50);
   DIF_MA[1] = (iMAOnArray(WPR,Periodo,Periodo_Smooth,0,MODE_SMA,index+1) +50);

  if( (DIF_MA[0]>0 && DIF_MA[1]<=0) || (DIF_MA[0]<0 && DIF_MA[1]>=0) )      // if cross found
   {
    CrossAt[ArrayIndex] = index;
    ArrayIndex++;
   }
   index++;
}

You only increase ArrayIndex if a cross is found while you increase index every pass. Once index hits the size of WPR[], it no longer has anything to calculate with, so you will either get a critical Array out of range error, or you will be stuck in an endless loop

Reason: