MQL5 EA Code Correction

 

The given errors are:

'iMA' - wrong parameters count ThreeMA_Strategy_EA.mq5 76 22
'iMA' - wrong parameters count ThreeMA_Strategy_EA.mq5 77 22
'iMA' - wrong parameters count ThreeMA_Strategy_EA.mq5 79 22
'iMA' - wrong parameters count ThreeMA_Strategy_EA.mq5 81 23
'iMA' - wrong parameters count ThreeMA_Strategy_EA.mq5 82 23

Full Code:

#include <Trade\Trade.mqh>
CTrade trade;

// === Input Parameters ===
input double LotSize        = 0.1;
input int TakeProfitPts     = 200;
input int StopLossPts       = 0;     // 0 = automatic SL (last top/bottom)

input int OpenTradeMode     = 1;     // 1 = Both, 2 = Buy only, 3 = Sell only

input int FastMAPeriod      = 50;
input ENUM_MA_METHOD FastMAMethod = MODE_EMA;

input int SlowMAPeriod      = 100;
input ENUM_MA_METHOD SlowMAMethod = MODE_EMA;

input int TrendMAPeriod     = 200;
input ENUM_MA_METHOD TrendMAMethod = MODE_SMA;

input ENUM_APPLIED_PRICE AppliedPrice = PRICE_CLOSE;

//+------------------------------------------------------------------+
//| Initialization                                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   return INIT_SUCCEEDED;
}

//+------------------------------------------------------------------+
//| Utility: Get last lowest price (previous 10 bars)               |
//+------------------------------------------------------------------+
double GetLastLow()
{
   double lowest = iLow(_Symbol, _Period, 1);
   for (int i = 2; i <= 10; i++)
   {
      double low = iLow(_Symbol, _Period, i);
      if (low < lowest)
         lowest = low;
   }
   return lowest;
}

//+------------------------------------------------------------------+
//| Utility: Get last highest price (previous 10 bars)              |
//+------------------------------------------------------------------+
double GetLastHigh()
{
   double highest = iHigh(_Symbol, _Period, 1);
   for (int i = 2; i <= 10; i++)
   {
      double high = iHigh(_Symbol, _Period, i);
      if (high > highest)
         highest = high;
   }
   return highest;
}

//+------------------------------------------------------------------+
//| Expert Tick Function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   if (PositionsTotal() > 0) return; // Only one trade at a time

   // === MA Calculations ===
   double fastMA_0 = iMA(_Symbol, _Period, FastMAPeriod, 0, FastMAMethod, AppliedPrice, 0);
   double fastMA_1 = iMA(_Symbol, _Period, FastMAPeriod, 0, FastMAMethod, AppliedPrice, 1);

   double slowMA   = iMA(_Symbol, _Period, SlowMAPeriod, 0, SlowMAMethod, AppliedPrice, 0);

   double trendMA_0 = iMA(_Symbol, _Period, TrendMAPeriod, 0, TrendMAMethod, AppliedPrice, 0);
   double trendMA_1 = iMA(_Symbol, _Period, TrendMAPeriod, 0, TrendMAMethod, AppliedPrice, 1);

   double close_0 = iClose(_Symbol, _Period, 0);
   double close_1 = iClose(_Symbol, _Period, 1);

   // === Buy Logic ===
   bool buy1 = (fastMA_1 < trendMA_1 && fastMA_0 > trendMA_0);  // Cross above trend MA
   bool buy2 = (close_1 < fastMA_1 && close_0 > fastMA_0 &&
                fastMA_0 > trendMA_0 && slowMA > trendMA_0);     // Price crosses fastMA while both MAs above trend

   // === Sell Logic ===
   bool sell1 = (fastMA_1 > trendMA_1 && fastMA_0 < trendMA_0); // Cross below trend MA
   bool sell2 = (close_1 > fastMA_1 && close_0 < fastMA_0 &&
                 fastMA_0 < trendMA_0 && slowMA < trendMA_0);    // Price crosses below fastMA while both MAs below

   // === Open Trade if Signal Fires ===
   double sl = 0, tp = 0;

   if ((buy1 || buy2) && (OpenTradeMode == 1 || OpenTradeMode == 2))
   {
      double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
      tp = ask + TakeProfitPts * _Point;
      if (StopLossPts > 0)
         sl = ask - StopLossPts * _Point;
      else
         sl = GetLastLow();

      if (trade.Buy(LotSize, _Symbol, ask, sl, tp, "3MA Buy"))
         Print("Buy Order Sent | SL=", sl, " TP=", tp);
   }

   if ((sell1 || sell2) && (OpenTradeMode == 1 || OpenTradeMode == 3))
   {
      double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
      tp = bid - TakeProfitPts * _Point;
      if (StopLossPts > 0)
         sl = bid + StopLossPts * _Point;
      else
         sl = GetLastHigh();

      if (trade.Sell(LotSize, _Symbol, bid, sl, tp, "3MA Sell"))
         Print("Sell Order Sent | SL=", sl, " TP=", tp);
   }
}
 
Sodiq Kayode Hammed:

The given errors are:


Full Code:

You need to check iMA function in documentation and correct your code as per the correct parameters mentioned on documentation. 
 

Delete, ,0 and ,1 in iMA after AppliedPrice


#include <Trade\Trade.mqh>
CTrade trade;

// === Input Parameters ===
input double LotSize        = 0.1;
input int TakeProfitPts     = 200;
input int StopLossPts       = 0;     // 0 = automatic SL (last top/bottom)

input int OpenTradeMode     = 1;     // 1 = Both, 2 = Buy only, 3 = Sell only

input int FastMAPeriod      = 50;
input ENUM_MA_METHOD FastMAMethod = MODE_EMA;

input int SlowMAPeriod      = 100;
input ENUM_MA_METHOD SlowMAMethod = MODE_EMA;

input int TrendMAPeriod     = 200;
input ENUM_MA_METHOD TrendMAMethod = MODE_SMA;

input ENUM_APPLIED_PRICE AppliedPrice = PRICE_CLOSE;

//+------------------------------------------------------------------+
//| Initialization                                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   return INIT_SUCCEEDED;
}

//+------------------------------------------------------------------+
//| Utility: Get last lowest price (previous 10 bars)               |
//+------------------------------------------------------------------+
double GetLastLow()
{
   double lowest = iLow(_Symbol, _Period, 1);
   for (int i = 2; i <= 10; i++)
   {
      double low = iLow(_Symbol, _Period, i);
      if (low < lowest)
         lowest = low;
   }
   return lowest;
}

//+------------------------------------------------------------------+
//| Utility: Get last highest price (previous 10 bars)              |
//+------------------------------------------------------------------+
double GetLastHigh()
{
   double highest = iHigh(_Symbol, _Period, 1);
   for (int i = 2; i <= 10; i++)
   {
      double high = iHigh(_Symbol, _Period, i);
      if (high > highest)
         highest = high;
   }
   return highest;
}

//+------------------------------------------------------------------+
//| Expert Tick Function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   if (PositionsTotal() > 0) return; // Only one trade at a time

   // === MA Calculations ===
   double fastMA_0 = iMA(_Symbol, _Period, FastMAPeriod, 0, FastMAMethod, AppliedPrice);
   double fastMA_1 = iMA(_Symbol, _Period, FastMAPeriod, 0, FastMAMethod, AppliedPrice);

   double slowMA   = iMA(_Symbol, _Period, SlowMAPeriod, 0, SlowMAMethod, AppliedPrice);

   double trendMA_0 = iMA(_Symbol, _Period, TrendMAPeriod, 0, TrendMAMethod, AppliedPrice);
   double trendMA_1 = iMA(_Symbol, _Period, TrendMAPeriod, 0, TrendMAMethod, AppliedPrice);

   double close_0 = iClose(_Symbol, _Period, 0);
   double close_1 = iClose(_Symbol, _Period, 1);

   // === Buy Logic ===
   bool buy1 = (fastMA_1 < trendMA_1 && fastMA_0 > trendMA_0);  // Cross above trend MA
   bool buy2 = (close_1 < fastMA_1 && close_0 > fastMA_0 &&
                fastMA_0 > trendMA_0 && slowMA > trendMA_0);     // Price crosses fastMA while both MAs above trend

   // === Sell Logic ===
   bool sell1 = (fastMA_1 > trendMA_1 && fastMA_0 < trendMA_0); // Cross below trend MA
   bool sell2 = (close_1 > fastMA_1 && close_0 < fastMA_0 &&
                 fastMA_0 < trendMA_0 && slowMA < trendMA_0);    // Price crosses below fastMA while both MAs below

   // === Open Trade if Signal Fires ===
   double sl = 0, tp = 0;

   if ((buy1 || buy2) && (OpenTradeMode == 1 || OpenTradeMode == 2))
   {
      double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
      tp = ask + TakeProfitPts * _Point;
      if (StopLossPts > 0)
         sl = ask - StopLossPts * _Point;
      else
         sl = GetLastLow();

      if (trade.Buy(LotSize, _Symbol, ask, sl, tp, "3MA Buy"))
         Print("Buy Order Sent | SL=", sl, " TP=", tp);
   }

   if ((sell1 || sell2) && (OpenTradeMode == 1 || OpenTradeMode == 3))
   {
      double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
      tp = bid - TakeProfitPts * _Point;
      if (StopLossPts > 0)
         sl = bid + StopLossPts * _Point;
      else
         sl = GetLastHigh();

      if (trade.Sell(LotSize, _Symbol, bid, sl, tp, "3MA Sell"))
         Print("Sell Order Sent | SL=", sl, " TP=", tp);
   }
}