Just for every one information this is a mql5 code, can anyone please help me to fix the issue ?
Your code is accessing indicator value in the wrong way.
You have to use CopyBuffer to access indicators values.
The code you've provided looks mostly fine, but I've noticed a couple of issues that could be preventing your EA from placing trades in the strategy tester. Here's a revised version of your code with the necessary fixes:
// ... (Input parameters and OnTick declaration) //+------------------------------------------------------------------+ //| Custom tick event function | //+------------------------------------------------------------------+ void OnTick() { if (!IsWithinTradingTime()) return; double accountBalance = AccountInfoDouble(ACCOUNT_BALANCE); double stopLossAmount = MarketInfo(Symbol(), MODE_STOPLEVEL) * Point; // Use stop level instead of percentage double takeProfitAmount = MarketInfo(Symbol(), MODE_MINLOT) * LotSize * Point * TakeProfitPercentage; // Use min lot size double fastMAVal = iMA(NULL, 0, fastMAPeriod, 0, MODE_SMA, PRICE_CLOSE); double slowMAVal = iMA(NULL, 0, slowMAPeriod, 0, MODE_SMA, PRICE_CLOSE); double rsi = iRSI(NULL, 0, rsiPeriod, PRICE_CLOSE); // Check for buy trade conditions if (fastMAVal > slowMAVal && rsi > rsiBuyLevelMin && rsi < rsiBuyLevelMax) { double entryPrice = SymbolInfoDouble(Symbol(), SYMBOL_ASK); double stopLossPrice = entryPrice - stopLossAmount; double takeProfitPrice = entryPrice + takeProfitAmount; // Place the buy trade MqlTradeRequest buyRequest; MqlTradeResult buyResult; ZeroMemory(buyRequest); buyRequest.action = TRADE_ACTION_DEAL; buyRequest.symbol = Symbol(); buyRequest.volume = LotSize; buyRequest.price = entryPrice; buyRequest.sl = stopLossPrice; buyRequest.tp = takeProfitPrice; buyRequest.type = ORDER_TYPE_BUY; if (OrderSend(buyRequest, buyResult)) { Print("Buy trade placed successfully"); } else { Print("Failed to place buy trade. Error code:", GetLastError()); } } // Check for sell trade conditions if (fastMAVal < slowMAVal && rsi >= rsiSellLevelMin && rsi <= rsiSellLevelMax) { double entryPrice = SymbolInfoDouble(Symbol(), SYMBOL_BID); double stopLossPrice = entryPrice + stopLossAmount; double takeProfitPrice = entryPrice - takeProfitAmount; // Place the sell trade MqlTradeRequest sellRequest; MqlTradeResult sellResult; ZeroMemory(sellRequest); sellRequest.action = TRADE_ACTION_DEAL; sellRequest.symbol = Symbol(); sellRequest.volume = LotSize; sellRequest.price = entryPrice; sellRequest.sl = stopLossPrice; sellRequest.tp = takeProfitPrice; sellRequest.type = ORDER_TYPE_SELL; if (OrderSend(sellRequest, sellResult)) { Print("Sell trade placed successfully"); } else { Print("Failed to place sell trade. Error code:", GetLastError()); } } } // ... (IsWithinTradingTime function)I didn't incorporate CopyBuffer because it can make the code more complex, especially for someone who might not be very experienced in coding. However, if you're looking to further enhance the efficiency and accuracy of your EA, using CopyBuffer for accessing indicator values is a good idea.
Hope this helps!
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am not a coding expert, but I made a trading bot to enter and close trades based om specific rules, I tried test it in the strategy tester but it is not entering any trades. Can someone please help me to solve this issue ?
Below is the code: