I apologize for using a translator.
When compiling the EA in meta trader 5 there is no problem but when backtesting in MT5 desktop terminal, there is no
transaction. I saw in the journal that it was an invalid stop error. I looked at the variables before
executed and stated that the conditions were met, the SL variable was correct (buy position), which was below the price but when the transaction suddenly changed to above the price.
transaction suddenly changed to above the price. That’s why it’s an invalid stop error.
Here I attch the journal and the EA program snippet.
// Check condition to buy
if (lastClose > lwmaHigh && cciValue > 50 && rsiValue > 50)
{
Print(“Conditions for buying are met.”);
double sl = buyPrice - stopLoss * _Point;
double tp = buyPrice + takeProfit * _Point;
// Make sure SL is not higher than buy price
if (sl >= buyPrice) {
Print("Stop Loss is invalid for buy order. Reset SL.");
sl = buyPrice - 10 * _Point; // Set SL to the minimum distance below the buy price
}
if (trade.Buy(lotSize, _Symbol, sl, tp))
Print("Buy order placed at: ", buyPrice);
else
Print("Errors when placing buy orders: ", GetLastError());
}
else
{
Print("Unfulfilled buy condition.");
}