hello dear friends i have managed to get a test EA passed by the Mql5 Market Validator for mt4 EA, Here is the code for your reference. it has overcome multiple errors such as insufficient funds, volume checks etc.
//+------------------------------------------------------------------+//| MQL5AutoValidationPassEA.mq4 |//| Copyright 2024, FxProfitBots ltd. |//| fxprofitbots.com |//+------------------------------------------------------------------+#property copyright"Copyright 2024, FxProfitBots ltd."#property link"fxprofitbots.com"#property version"1.00"#property strict// Input parametersinputdouble Lots = 0.1;
inputint StopLoss = 100;
inputint TakeProfit = 100;
#define MAGIC_NUMBER 123456//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
Print("SimpleEA initialized.");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
Print("SimpleEA deinitialized.");
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
if (OrdersTotal() == 0) // Check if there are no open orders
{
if (ShouldOpenTrade())
{
double volume = NormalizeLotSize(Lots);
if (volume > 0 && CheckMoneyForTrade(Symbol(), volume, OP_BUY))
{
OpenBuyTrade(volume);
}
}
}
}
//+------------------------------------------------------------------+//| Function to open a buy trade |//+------------------------------------------------------------------+void OpenBuyTrade(double volume)
{
double price = Ask;
double sl = price - StopLoss * Point;
double tp = price + TakeProfit * Point;
int ticket = OrderSend(Symbol(), OP_BUY, volume, price, 3, sl, tp, "SimpleEA Buy", MAGIC_NUMBER, 0, Blue);
if (ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
else
{
Print("Buy order opened successfully. Ticket: ", ticket);
}
}
//+------------------------------------------------------------------+//| Function to close all trades |//+------------------------------------------------------------------+void CloseAllTrades()
{
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUY || OrderType() == OP_SELL)
{
bool result = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 3, clrRed);
if (!result)
{
Print("OrderClose failed with error #", GetLastError());
}
else
{
Print("Order closed successfully. Ticket: ", OrderTicket());
}
}
}
}
}
//+------------------------------------------------------------------+//| Function to check if trade should be opened |//+------------------------------------------------------------------+bool ShouldOpenTrade()
{
// Example condition: simple moving average crossoverint maPeriod = 14;
double maCurrent = iMA(Symbol(), 0, maPeriod, 0, MODE_SMA, PRICE_CLOSE, 0);
double maPrevious = iMA(Symbol(), 0, maPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);
return (maCurrent > maPrevious);
}
//+------------------------------------------------------------------+//| Function to normalize the lot size according to market conditions|//+------------------------------------------------------------------+double NormalizeLotSize(double lotSize)
{
double minLot = MarketInfo(Symbol(), MODE_MINLOT);
double maxLot = MarketInfo(Symbol(), MODE_MAXLOT);
double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
if (lotSize < minLot) lotSize = minLot;
if (lotSize > maxLot) lotSize = maxLot;
lotSize = MathFloor(lotSize / lotStep) * lotStep;
if (lotSize < minLot || lotSize > maxLot)
{
Print("Lot size out of range. Adjusted to ", lotSize);
return0;
}
return lotSize;
}
//+------------------------------------------------------------------+//| Function to check if there is enough money for trade |//+------------------------------------------------------------------+bool CheckMoneyForTrade(string symb, double lots, int type)
{
double free_margin = AccountFreeMarginCheck(symb, type, lots);
//-- if there is not enough moneyif (free_margin < 0)
{
string oper = (type == OP_BUY) ? "Buy" : "Sell";
Print("Not enough money for ", oper, " ", lots, " ", symb, " Error code=", GetLastError());
returnfalse;
}
//--- checking successfulreturntrue;
}
Hi, My EA is not designed to trade EURUSD, but the MT5 validation routing tests it with Forex so the valdation fails. How do indicate with the EA is not designed to trade Forex?
John Banks # : Ciao, il mio Expert Advisor (EA) non è progettato per operare sulla coppia EUR/USD , ma il routing di validazione di MT5 lo testa con il Forex, quindi la validazione fallisce. Come posso indicare che l'EA non è progettato per operare sul Forex?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Issue takes place again during MT4 product update: "test on EURUSD,H1 strategy tester report not found"
Issue takes place again during MT4 product update: "test on EURUSD,H1 strategy tester report not found"
Actually it was fixed by MQL. Thanks as usually
hello dear friends i have managed to get a test EA passed by the Mql5 Market Validator for mt4 EA, Here is the code for your reference. it has overcome multiple errors such as insufficient funds, volume checks etc.
My EA is not designed to trade EURUSD, but the MT5 validation routing tests it with Forex so the valdation fails. How do indicate with the EA is not designed to trade Forex?