how can I check whether a moving average cuts another moving average from bellow or from the top?

 
Hi, Here I have the code that I want to check when ma8 cuts ma21 from bellow I want to place the buy order and when ma8 cuts ma21 from the top I want to  place the sell order, How can do these two in if statements that I leave them empty in the code?
#property strict
//+------------------------------------------------------------------+
//| Global Variables                                                 |
//+------------------------------------------------------------------+
int     ma8_period = 8;
int     ma8_shift = 0;
int     ma8_handle;
int     ma21_period = 21;
int     ma21_shift = 0;
int     ma21_handle;
uint    magic_number = 155712;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   ma8_handle = ma_init(ma8_period, ma8_shift, MODE_SMA, PRICE_CLOSE);
   ma21_handle = ma_init(ma21_period, ma21_shift, MODE_SMA, PRICE_CLOSE);
   
   if(ma8_handle || ma21_handle == -1)
   {
      return (INIT_FAILED);
   }
   
   return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   Print("Expert removed from the chart."); 
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   double ask_price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double bid_price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double tick_size = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
   double ma8 = ma(ma8_handle, 0);
   double ma21 = ma(ma21_handle, 0);
   
   
   ask_price = round(ask_price / tick_size) * tick_size; 
   bid_price = round(bid_price / tick_size) * tick_size;
   
   string comment = _Symbol;
   
   if()
   {
      MqlTradeRequest request = {};
      MqlTradeRequest result = {};
      
      request.action = TRADE_ACTION_DEAL;
      request.symbol = _Symbol;
      request.volume = 0.01;
      request.type = ORDER_TYPE_BUY;
      request.price = ask_price;
      request.deviasion = 10;
      request.magic = magic_number;
      request.comment = comment;
      
      if(!OrderSend(request, result))
      {
         Print("An error occured while placing the buy order: ", GetLastError());
      }
   }
   
   else if()
   {
      MqlTradeRequest request = {};
      MqlTradeRequest result = {};
      
      request.action = TRADE_ACTION_DEAL;
      request.symbol = _Symbol;
      request.volume = 0.01;
      request.type = ORDER_TYPE_SELL;
      request.price = bid_price;
      request.deviasion = 10;
      request.magic = magic_number;
      request.comment = comment;
      
      if(!OrderSend(request, result))
      {
         Print("An error occured while placing the sell order: ", GetLastError());
      }
      
   }
}

int ma_init(int pMAPeriod, int pMAShift, ENUM_MA_METHOD pMAMethod, ENUM_APPLIED_PRICE pMAPrice)
{
   ResetLastError();
   
   int Handle = iMA(_Symbol, PERIOD_CURRENT, pMAPeriod, pMAShift, pMAMethod, pMAPrice);
   
   if(Handle == INVALID_HANDLE)
   {
      Print("An error occured while creating the handle: ", GetLastError());
      
      return -1;
   }
   
   Print("Handle was successfully created !");
   
   return Handle;
}

double ma(int ma_handle, int ma_shift)
{  
   ResetLastError();
     
   double ma[];
   ArraySetAsSeries(ma, true);
   
   bool fillResult = CopyBuffer(pMAHandle, 0, 0, 3, ma);   
   if(fillResult == false){
      Print("FILL_ERROR: ", GetLastError());}
   
        double maValue = ma[pShift];
        
        maValue = NormalizeDouble(maValue, _Digits);
        
        return maValue;           
}
 
محمد دهقانی: t I want to check when ma8 cuts ma21 from bellow
   double ma8 = ma(ma8_handle, 0);
   double ma21 = ma(ma21_handle, 0);

Look for a cross.

double aPrev = …(i+1), aCurr = …(i),
       bPrev = …(i+1), bCurr = …(i);
bool   wasUp = aPrev > bPrev,
        isUp = aCurr > bCurr,
     isCross = isUp != wasUp;
 
Compare the previous prices
 
Just do it
 
William Roeder #:

Look for a cross.

William would you please explain the solution you said a little bit that I can understand it? 

 
bool crossover(int index)
{
   return ma(ma8_handle, index)>ma(ma21_handle, index) && ma(ma8_handle, index+1)<ma(ma21_handle, index+1);
}

bool crossunder(int index)
{
   return ma(ma8_handle, index)<ma(ma21_handle, index) && ma(ma8_handle, index+1)>ma(ma21_handle, index+1);
}