Close above/below MA code

 

Hi guys, 

I got this original script somewhere here, I modify it so it would become cloing above or below MA. The problem is I lack in skill in mq4 and still learning. Need advice please. How to make it run correctly. Thanks.


void CheckForClose()
  {
   double ma;
   if(Volume[0]>1) return;
   ma=iMA(NULL,1440,5,0,MODE_SMA,PRICE_CLOSE,0);

   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderType()==OP_BUY)
        {
         if(Open[1]>ma) 
            if(Bid > OrderOpenPrice() + 1*Point)
               OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(Open[1]<ma)  
            if(Ask > OrderOpenPrice() + 1*Point)
               OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
         break;
        }
     }
     }
 
Or this one I try, none of it working , please advice.
void OnTick()
   {
    if (OrdersTotal()>0)
    closeaboveMA()
   }

double ma;
   {
    ma=iMA(NULL,1440,5,0,MODE_SMA,PRICE_CLOSE,0);
   }

double closeaboveMA;
   {
 
      if(OrderType()==OP_BUY)
        {
         if(Open[1]>ma) 
            if(Bid > OrderOpenPrice() + 1*Point)
               OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(Open[1]<ma)  
            if(Ask > OrderOpenPrice() + 1*Point)
               OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
         break;
        }  
    }
 
Kret_kret:
Or this one I try, none of it working , please advice.

Hello friend,

Time frame

double ma;
   {
    ma=iMA(NULL,1440,5,0,MODE_SMA,PRICE_CLOSE,0);
   }

You could do this

double ma;
   {
    ma=iMA(NULL,0,5,0,MODE_SMA,PRICE_CLOSE,0);
   }
also scripts only execute once and then they exit.