I try to make an EA basing on the crossing of 2 MA

 
Hello!

I hope you are well. Please, can someone help me to resolve this problem.
I try to make an EA basing on the crossing of  2 MA. The EA have to take position when the 2 MA are crossing (down for buy positions and up for sell positions) but the EA don't work as i want. Please help me.
Files:
MA_L.mq4  15 kb
 
Lawson_Oma:
Hello!

I hope you are well. Please, can someone help me to resolve this problem.
I try to make an EA basing on the crossing of  2 MA. The EA have to take position when the 2 MA are crossing (down for buy positions and up for sell positions) but the EA don't work as i want. Please help me.

Given that you have:

   double Fast_ma_2 = iMA(NULL, 0, Fast_period, 0, MODE_SMA, PRICE_CLOSE, 2);
   double Fast_ma_1 = iMA(NULL, 0, Fast_period, 0, MODE_SMA, PRICE_CLOSE, 1);
   
   double Lw_ma_2 = iMA(NULL, 0, Lw_period_1, 0, MODE_SMA, PRICE_CLOSE, 2);
   double Lw_ma_1 = iMA(NULL, 0, Lw_period_1, 0, MODE_SMA, PRICE_CLOSE, 1);
   
   double P_close_1= iClose(NULL,0,1);
   double P_close_2= iClose(NULL,0,2);
   double P_open_0 = iOpen(NULL,0,0);

Your condition checks should be:

   if (Fast_ma_1>Lw_ma_1 && Fast_ma_2<=Lw_ma_2 && P_close_1>MathMax(Fast_ma_1,P_close_2))
      // open buy

   if (Fast_ma_1<Lw_ma_1 && Fast_ma_2>=Lw_ma_2 && P_close_1<MathMin(Fast_ma_1,P_close_2))
      // open sell


edit: typo