Product Validation Error (test on EURUSD,H1 strategy tester report not found) - page 2

 

Issue takes place again during MT4 product update: "test on EURUSD,H1 strategy tester report not found"

 
DMITRII GRIDASOV #:

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.


//+------------------------------------------------------------------+
//|                                     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 parameters
input double Lots = 0.1;
input int StopLoss = 100;
input int TakeProfit = 100;

#define MAGIC_NUMBER 123456

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    Print("SimpleEA initialized.");
    return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
    Print("SimpleEA deinitialized.");
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    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 crossover
    int 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);
        return 0;
    }

    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 money
    if (free_margin < 0)
    {
        string oper = (type == OP_BUY) ? "Buy" : "Sell";
        Print("Not enough money for ", oper, " ", lots, " ", symb, " Error code=", GetLastError());
        return false;
    }
    //--- checking successful
    return true;
}



MetaQuotes — the developer of trading platforms for brokers, banks, exchanges and hedge funds
MetaQuotes — the developer of trading platforms for brokers, banks, exchanges and hedge funds
  • www.metaquotes.net
MetaTrader 5 trading platform is a free Forex and stock trading tool