Help fix EA code please

 

Hello,

Please can anyone help fix my EA code I am trying to build, below are errors I am getting when running backtest:

'SymbolInfoInteger' - no one of the overloads can be applied to the function call Moving Average.mq5 40 8

could be one of 2 function(s) Moving Average.mq5 40 8

   built-in: long SymbolInfoInteger(const string,ENUM_SYMBOL_INFO_INTEGER) Moving Average.mq5 40 8

   built-in: bool SymbolInfoInteger(const string,ENUM_SYMBOL_INFO_INTEGER,long&) Moving Average.mq5 40 8

//+------------------------------------------------------------------+
//|                                              Moving Averages.mq5 |
//|                             Copyright 2000-2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2000-2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <Trade\Trade.mqh>

input double MaximumRisk        = 0.02;    // Maximum Risk in percentage
input double DecreaseFactor     = 3;       // Decrease factor
input int    MovingPeriod       = 89;      // Moving Average period
input int    MovingShift        = 0;       // Moving Average shift
input double LotSize            = 0.01;    // Lot size (1 micro lot)
input int    MaxPositions       = 1;       // Maximum number of positions to open

int    ExtHandle=0;
bool   ExtHedging=false;
CTrade ExtTrade;

#define MA_MAGIC 1234501

//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double TradeSizeOptimized() {
   double price=0.0;
   double margin=0.0;
   //--- select lot size
   if(!SymbolInfoDouble(_Symbol,SYMBOL_ASK,price))
      return(0.0);
   if(!OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,1.0,price,margin))
      return(0.0);
   if(margin<=0.0)
      return(0.0);

   long volumeDigits;
   if(!SymbolInfoInteger(_Symbol, SYMBOL_VOLUME_STEP, volumeDigits))
      return(0.0); // Return 0 if SymbolInfoInteger fails
   double lot = NormalizeDouble(LotSize, volumeDigits);
   return lot;
}

//+------------------------------------------------------------------+
//| Check for open position conditions                               |
//+------------------------------------------------------------------+
void CheckForOpen() {
   MqlRates rt[2];
   //--- go trading only for first ticks of new bar
   if(CopyRates(_Symbol,_Period,0,2,rt)!=2) {
      Print("CopyRates of ",_Symbol," failed, no history");
      return;
   }
   if(rt[1].tick_volume>1)
      return;
   //--- get current Moving Average 
   double   ma[1];
   if(CopyBuffer(ExtHandle,0,0,1,ma)!=1) {
      Print("CopyBuffer from iMA failed, no data");
      return;
   }
   //--- check signals
   ENUM_ORDER_TYPE signal = WRONG_VALUE;

   if(rt[1].close < ma[0] && rt[0].close >= ma[0])
      signal = ORDER_TYPE_BUY;    // buy conditions
   else if(rt[1].close > ma[0] && rt[0].close <= ma[0])
      signal = ORDER_TYPE_SELL;    // sell conditions

   //--- additional checking
   if(signal != WRONG_VALUE) {
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && PositionsTotal() < MaxPositions) {
         double lot = TradeSizeOptimized();
         ExtTrade.PositionOpen(_Symbol, signal, lot, SymbolInfoDouble(_Symbol, signal == ORDER_TYPE_SELL ? SYMBOL_BID : SYMBOL_ASK), 0, 0);
      }
   }
}

//+------------------------------------------------------------------+
//| Check for close position conditions                              |
//+------------------------------------------------------------------+
void CheckForClose() {
   MqlRates rt[2];
   //--- go trading only for first ticks of new bar
   if(CopyRates(_Symbol,_Period,0,2,rt)!=2) {
      Print("CopyRates of ",_Symbol," failed, no history");
      return;
   }
   if(rt[1].tick_volume>1)
      return;
   //--- get current Moving Average 
   double   ma[1];
   if(CopyBuffer(ExtHandle,0,0,1,ma)!=1) {
      Print("CopyBuffer from iMA failed, no data");
      return;
   }
   //--- positions already selected before
   bool signal = false;
   long type = PositionGetInteger(POSITION_TYPE);

   if(type == (long)POSITION_TYPE_BUY && rt[1].close >= ma[0] && rt[0].close < ma[0])
      signal = true;
   if(type == (long)POSITION_TYPE_SELL && rt[1].close <= ma[0] && rt[0].close > ma[0])
      signal = true;
   //--- additional checking
   if(signal) {
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && Bars(_Symbol,_Period) > 100)
         ExtTrade.PositionClose(_Symbol, 3);
   }
}

//+------------------------------------------------------------------+
//| Position select depending on netting or hedging                  |
//+------------------------------------------------------------------+
bool SelectPosition() {
   bool res = false;
   //--- check position in Hedging mode
   if(ExtHedging) {
      uint total = PositionsTotal();
      for(uint i = 0; i < total; i++) {
         string position_symbol = PositionGetSymbol(i);
         if(_Symbol == position_symbol && MA_MAGIC == PositionGetInteger(POSITION_MAGIC)) {
            res = true;
            break;
         }
      }
   }
   //--- check position in Netting mode
   else {
      if(!PositionSelect(_Symbol))
         return(false);
      else
         return(PositionGetInteger(POSITION_MAGIC) == MA_MAGIC); //---check Magic number
   }
   //--- result for Hedging mode
   return(res);
}

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(void) {
   //--- prepare trade class to control positions if hedging mode is active
   ExtHedging = ((ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE) == ACCOUNT_MARGIN_MODE_RETAIL_HEDGING);
   ExtTrade.SetExpertMagicNumber(MA_MAGIC);
   ExtTrade.SetMarginMode();
   ExtTrade.SetTypeFillingBySymbol(Symbol());
   //--- Moving Average indicator
   ExtHandle = iMA(_Symbol, _Period, MovingPeriod, MovingShift, MODE_SMA, PRICE_CLOSE);
   if(ExtHandle == INVALID_HANDLE) {
      printf("Error creating MA indicator");
      return(INIT_FAILED);
   }
   //--- ok
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick(void) {
   //---
   if(SelectPosition())
      CheckForClose();
   else
      CheckForOpen();
   //---
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
}
//+------------------------------------------------------------------+


 
140014828:

Hello,

Please can anyone help fix my EA code I am trying to build, below are errors I am getting when running backtest:

'SymbolInfoInteger' - no one of the overloads can be applied to the function call Moving Average.mq5 40 8

could be one of 2 function(s) Moving Average.mq5 40 8

   built-in: long SymbolInfoInteger(const string,ENUM_SYMBOL_INFO_INTEGER) Moving Average.mq5 40 8

   built-in: bool SymbolInfoInteger(const string,ENUM_SYMBOL_INFO_INTEGER,long&) Moving Average.mq5 40 8



This is wrong:

SymbolInfoInteger(_Symbol, SYMBOL_VOLUME_STEP, volumeDigits)
Change it to this:

SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP, volumeDigits)


 
double volumeDigits;
if(!SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP, volumeDigits))
   return(0.0); // Return 0 if SymbolInfoInteger fails
double lot = NormalizeDouble(LotSize, (int)(1/volumeDigits));
 
Thank you, I will update the code and advise.
Appreciate the help.
 

For some reason, no trades are opening.
Please advise what am I missing from this code to achieve the below:

Entry Criteria:
Buy position - when candle closes above 89 SMA.

Sell position - when candle closes below 89 SMA.

Exit Criteria:

Buy position -  when candle closes below 89 SMA.

Sell position -  when candle closes above 89 SMA.

Compatible on MT5 for micro lots.

 
SwingTrader #:

For some reason, no trades are opening.
Please advise what am I missing from this code to achieve the below:

Entry Criteria:
Buy position - when candle closes above 89 SMA.

Sell position - when candle closes below 89 SMA.

Exit Criteria:

Buy position -  when candle closes below 89 SMA.

Sell position -  when candle closes above 89 SMA.

Compatible on MT5 for micro lots.

It placed a few trades but not much (about 2). If the conditions to place a trade occurs in the first tick of the forming candle it would place a trade. Remove this condition to get it functioning as intended,

if(rt[1].tick_volume>1)
   return;
from both the CheckForOpen() and CheckForClose()