Cross of three MAs

 

Hi, I'm new in mql5.

I have the following problem,

Suppose I want  see the cross of three MA's, but in different times. For exemplo MA_Fast ,MA_Medium and MA_ Slow, so the MA_medium cross the MA_Slow, I want to see if the MA_Fast crossed the MA_Slow too in a period of 20 bars ago or less, How I make this?

 

Thanks for everyone.

Hugs 

 
What have you tried ? Please post your attempt if you need coding help.
 
Alain Verleyen:
What have you tried ? Please post your attempt if you need coding help.

Ok ..  Actually  I tried several things, 

In my mind is easier make a index and then use this index to make a EA using a wizard.

My last tried was shift the MA, but appear a error when I compile.

I TRIED THIS

 

int MA_Cross::LongCondition()
  {
   int signal=0;

//--- For operation with ticks idx=0, for operation with formed bars idx=1
   int idx=StartIndex();
//--- Values of MAs at the last formed bar
   
   double last_slow_value=SlowMA(idx);
   double last_vslow_value=VslowMA(idx);
   
//--- Values of MAs at the last but one formed bar


   double prev_slow_value=SlowMA(idx+1);
   double prev_vslow_value=VslowMA(idx+1);
// ---- combinações dois tres quarto cinco seis(s) sete(st) e oito  last 

        
//--- If the fast MA crossed the slow MA from bottom upwards on the last two closed bars

   if((last_slow_value>last_vslow_value) && (prev_slow_value<prev_vslow_value))
     {
     
     int j;
     
     for(j=0; j<=m_janela; j++)
      {

         FastMAsh=iMA(NULL,0,m_period_fast,j,MODE_EMA, PRICE_CLOSE);
         VslowMAsh=iMA(NULL,0,m_period_vslow,j,m_method_vslow, PRICE_CLOSE);
      
       double last_fast_value=FastMAsh(idx);
       double prev_fast_value=FastMAsh(idx+1);
       double last_vslow_value_sh=VslowMAsh(idx);
       double prev_vslow_value_sh=VslowMAsh(idx+1);
       if((last_fast_value>last_vslow_value_sh) && (prev_fast_value<prev_vslow_value_sh))
          {
            signal=100; // There is a signal to buy
          }
       
      }
     }
  
//--- Return the signal value
   return(signal);

 }

 

==========================================================================================
Off course this is just a part of my code.. 

Thanks for everything

 

hugs 

Reason: