//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double ma20 = iMA(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, 0);
   double ma200 = iMA(NULL, 0, 200, 0, MODE_SMA, PRICE_CLOSE, 0);
   double closePrice = iClose(NULL, 0, 0);
   double prevClosePrice = iClose(NULL, 0, 1);
   double prevMa20 = iMA(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, 1);

   int totalOrders = OrdersTotal();
   bool hasBuyOrder = false;
   bool hasSellOrder = false;
   
   // Verifica se há ordens abertas
   for (int i = 0; i < totalOrders; i++) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         if (OrderType() == OP_BUY) hasBuyOrder = true;
         if (OrderType() == OP_SELL) hasSellOrder = true;
      }
   }

   // Se a média de 200 está abaixo do preço e cruzamos acima da MA20 com uma vela de alta
   if (ma200 < closePrice && prevClosePrice <= prevMa20 && closePrice > ma20) {
      // Se houver uma ordem de venda, fechá-la
      if (hasSellOrder) CloseSellOrder();
      
      // Abrir ordem de compra
      if (!hasBuyOrder) OpenBuyOrder();
   }

   // Se a média de 200 está acima do preço e cruzamos abaixo da MA20 com uma vela de baixa
   if (ma200 > closePrice && prevClosePrice >= prevMa20 && closePrice < ma20) {
      // Se houver uma ordem de compra, fechá-la
      if (hasBuyOrder) CloseBuyOrder();

      // Abrir ordem de venda
      if (!hasSellOrder) OpenSellOrder();
   }
  }

//+------------------------------------------------------------------+
//| Funções para abrir e fechar ordens de compra e venda             |
//+------------------------------------------------------------------+
void OpenBuyOrder() {
   double lotSize = 0.1; // Define o lote conforme sua estratégia
   double stopLoss = 100; // Exemplo de stop loss
   double takeProfit = 100; // Exemplo de take profit
   OrderSend(Symbol(), OP_BUY, lotSize, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "Buy Order", 0, 0, clrGreen);
}

void CloseBuyOrder() {
   for (int i = OrdersTotal() - 1; i >= 0; i--) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, 3, clrRed);
      }
   }
}

void OpenSellOrder() {
   double lotSize = 0.1; // Define o lote conforme sua estratégia
   double stopLoss = 100; // Exemplo de stop loss
   double takeProfit = 100; // Exemplo de take profit
   OrderSend(Symbol(), OP_SELL, lotSize, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "Sell Order", 0, 0, clrRed);
}

void CloseSellOrder() {
   for (int i = OrdersTotal() - 1; i >= 0; i--) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, 3, clrGreen);
      }
   }
}

erro no codigo abaixo:

'iMA' - wrong parameters count	HTF_BUY_01.mq5	19	18
   built-in: int iMA(const string,ENUM_TIMEFRAMES,int,int,ENUM_MA_METHOD,int)	HTF_BUY_01.mq5	19	18
'iMA' - wrong parameters count	HTF_BUY_01.mq5	20	19
   built-in: int iMA(const string,ENUM_TIMEFRAMES,int,int,ENUM_MA_METHOD,int)	HTF_BUY_01.mq5	20	19
'iMA' - wrong parameters count	HTF_BUY_01.mq5	23	22
   built-in: int iMA(const string,ENUM_TIMEFRAMES,int,int,ENUM_MA_METHOD,int)	HTF_BUY_01.mq5	23	22
'SELECT_BY_POS' - undeclared identifier	HTF_BUY_01.mq5	31	26
'OrderSelect' - wrong parameters count	HTF_BUY_01.mq5	31	11
   built-in: bool OrderSelect(ulong)	HTF_BUY_01.mq5	31	11
'OrderType' - undeclared identifier	HTF_BUY_01.mq5	32	14
')' - expression expected	HTF_BUY_01.mq5	32	24
'OP_BUY' - undeclared identifier	HTF_BUY_01.mq5	32	29
'OrderType' - undeclared identifier	HTF_BUY_01.mq5	33	14
')' - expression expected	HTF_BUY_01.mq5	33	24
'OP_SELL' - undeclared identifier	HTF_BUY_01.mq5	33	29
'OP_BUY' - undeclared identifier	HTF_BUY_01.mq5	63	24
'Ask' - undeclared identifier	HTF_BUY_01.mq5	63	41
'Ask' - undeclared identifier	HTF_BUY_01.mq5	63	49
',' - open parenthesis expected	HTF_BUY_01.mq5	63	71
'Ask' - undeclared identifier	HTF_BUY_01.mq5	63	73
',' - open parenthesis expected	HTF_BUY_01.mq5	63	97
'OrderSend' - wrong parameters count	HTF_BUY_01.mq5	63	4
   built-in: bool OrderSend(const MqlTradeRequest&,MqlTradeResult&)	HTF_BUY_01.mq5	63	4
'SELECT_BY_POS' - undeclared identifier	HTF_BUY_01.mq5	68	26
'OrderSelect' - wrong parameters count	HTF_BUY_01.mq5	68	11
   built-in: bool OrderSelect(ulong)	HTF_BUY_01.mq5	68	11
'OrderType' - undeclared identifier	HTF_BUY_01.mq5	69	14
')' - expression expected	HTF_BUY_01.mq5	69	24
'OP_BUY' - undeclared identifier	HTF_BUY_01.mq5	69	29
'OrderClose' - undeclared identifier	HTF_BUY_01.mq5	69	37
'OrderTicket' - undeclared identifier	HTF_BUY_01.mq5	69	48
')' - expression expected	HTF_BUY_01.mq5	69	60
',' - unexpected token	HTF_BUY_01.mq5	69	61
'OrderTicket' - some operator expected	HTF_BUY_01.mq5	69	48
')' - expression expected	HTF_BUY_01.mq5	69	73
',' - unexpected token	HTF_BUY_01.mq5	69	74
'Bid' - undeclared identifier	HTF_BUY_01.mq5	69	76
',' - unexpected token	HTF_BUY_01.mq5	69	79
',' - unexpected token	HTF_BUY_01.mq5	69	82
expression has no effect	HTF_BUY_01.mq5	69	81
')' - unexpected token	HTF_BUY_01.mq5	69	90
expression has no effect	HTF_BUY_01.mq5	69	84
'OP_SELL' - undeclared identifier	HTF_BUY_01.mq5	78	24
'Bid' - undeclared identifier	HTF_BUY_01.mq5	78	42
'Bid' - undeclared identifier	HTF_BUY_01.mq5	78	50
',' - open parenthesis expected	HTF_BUY_01.mq5	78	72
'Bid' - undeclared identifier	HTF_BUY_01.mq5	78	74
',' - open parenthesis expected	HTF_BUY_01.mq5	78	98
'OrderSend' - wrong parameters count	HTF_BUY_01.mq5	78	4
   built-in: bool OrderSend(const MqlTradeRequest&,MqlTradeResult&)	HTF_BUY_01.mq5	78	4
'SELECT_BY_POS' - undeclared identifier	HTF_BUY_01.mq5	83	26
'OrderSelect' - wrong parameters count	HTF_BUY_01.mq5	83	11
   built-in: bool OrderSelect(ulong)	HTF_BUY_01.mq5	83	11
'OrderType' - undeclared identifier	HTF_BUY_01.mq5	84	14
')' - expression expected	HTF_BUY_01.mq5	84	24
'OP_SELL' - undeclared identifier	HTF_BUY_01.mq5	84	29
'OrderClose' - undeclared identifier	HTF_BUY_01.mq5	84	38
'OrderTicket' - undeclared identifier	HTF_BUY_01.mq5	84	49
')' - expression expected	HTF_BUY_01.mq5	84	61
',' - unexpected token	HTF_BUY_01.mq5	84	62
'OrderTicket' - some operator expected	HTF_BUY_01.mq5	84	49
')' - expression expected	HTF_BUY_01.mq5	84	74
',' - unexpected token	HTF_BUY_01.mq5	84	75
'Ask' - undeclared identifier	HTF_BUY_01.mq5	84	77
',' - unexpected token	HTF_BUY_01.mq5	84	80
',' - unexpected token	HTF_BUY_01.mq5	84	83
expression has no effect	HTF_BUY_01.mq5	84	82
')' - unexpected token	HTF_BUY_01.mq5	84	93
expression has no effect	HTF_BUY_01.mq5	84	85