Hi! Could someone help me solve these errors, identifying the shortcomings and making the necessary corrections.
These two errors usually occur when there is an error in the syntax of a code, usually caused by missing closing brackets or quotes. Only, no matter how carefully I go through my code and check that all brackets, parentheses and quotes are properly balanced and closed, I can't find anything. I'm not a programming expert. Is it possibly a simple spacing/column error?
Here is the full code below :
I will be very grateful!
Mustafa Z.
You have a mixture of MT4 and MT5 code. Stop using chatGPT.
| MT5 code. That is not an assignment; it's initialization of a common (globally declared), or static variable with a constant. | double Bid = SymbolInfoDouble(_Symbol, SYMBOL_BID); |
| MT5 code returns a handle (an int) not a double. | double atr = iATR(_Symbol, PERIOD_CURRENT, AtrPeriod); |
| MT4 code | OrderSend(_Symbol, OP_BUY, LotSize, Bid, 3, StopLoss, TakeProfit1, "EA Buy", MagicNumber); |
| MT4 code No order selcted. | int ticket = OrderTicket(); double openPrice = OrderOpenPrice(); |
ChatGPT (the worst), EA builder, EA Builder Pro, EATree, Etasoft forex generator, Forex Strategy Builder, ForexEAdvisor (aka. ForexEAdvisor STRATEGY BUILDER, and Online Forex Expert Advisor Generator), ForexRobotAcademy.com, forexsb, FX EA Builder, fxDreema, Forex Generator, FxPro, Molanis, Octa-FX Meta Editor, Strategy Builder FX, Strategy Quant, Visual Trader Studio, MQL5 Wizard, etc., are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.
-
Since you haven't learned MQL4/5, therefor there is no common language for us to communicate.
If we tell you what you need, you can't code it.
If we give you the code, you don't know how to integrate it into yours.We are willing to HELP you when you post your attempt (using Code button) and state the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.
ChatGPT - Mixing MT4 and MT5 code together.
- Creating multiple OnCalculate/OnTick functions.
- OnCalculate returning a double.
- Filling buffers with zero in OnInit (they have no size yet). Setting buffer elements to zero but not setting Empty Value to correspond.
- Calling undefined functions.
- Sometimes, not using strict.
- Code that will not compile.
- Creating code outside of functions.
- Creating incomplete code.
- Initialization of Global variables with non-constants.
- Assigning a MT5 handle to a double.
- Useing MT4 Trade Functions without first selecting an order.
EA builder - Counting up while closing multiple orders.
- New bar code: Bars is unreliable (Max bars in chart), volume is unreliable (miss ticks.) Always use time.
- Not adjusting for 4/5 digit brokers, TP/SL and slippage.
- Not adjusting for ECN brokers. pre-Build 500)
- Not checking return codes.
EATree Uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.) ForexEAdvisor FX EA Builder - Not checking return codes.
- Loosing open tickets on terminal restart. No recovery (crash/power failure.)
- Not adjusting stops for the spread.
- Using OrdersTotal directly.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi! Could someone help me solve these errors, identifying the shortcomings and making the necessary corrections.
These two errors usually occur when there is an error in the syntax of a code, usually caused by missing closing brackets or quotes. Only, no matter how carefully I go through my code and check that all brackets, parentheses and quotes are properly balanced and closed, I can't find anything. I'm not a programming expert. Is it possibly a simple spacing/column error?
Here is the full code below :
//+------------------------------------------------------------------+ //| Halftrend EA | //| Mustapha Zegoud | //| | //+------------------------------------------------------------------+ #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> // Declaration of external variables extern double RiskPercentage = 0.5; // Pourcentage de risque extern int AtrPeriod = 14; // Période ATR extern int AtrMultiplier = 3; // Multiplicateur ATR extern int EmaPeriod = 200; // Période EMA extern int HalfTrendAmplitude = 2; // Amplitude Halftrend extern int HalfTrendChannelDeviation = 2; // Déviation du canal Halftrend extern int TakeProfit1Multiple = 1; // Multiple de Take Profit 1 extern int TakeProfit2Multiple = 2; // Multiple de Take Profit 2 // Declaration of global variables double Bid = SymbolInfoDouble(_Symbol, SYMBOL_BID); double LotSize; // Taille du lot double StopLoss; // Stop loss double TakeProfit1; // Take profit 1 double TakeProfit2; // Take profit 2 double Equity; // Capital propre bool BreakevenActivated = false; // Breakeven activé ou non double BreakevenPrice; // Prix de breakeven double TradeEntryPrice; // Prix d'entrée du trade int MagicNumber = 12345; // Numéro magique // Initialize the EA void OnInit() { // Calcul de la taille du lot en fonction du risque et de l'ATR double atr = iATR(_Symbol, PERIOD_CURRENT, AtrPeriod); double equity = AccountInfoDouble(ACCOUNT_EQUITY); LotSize = (equity * RiskPercentage) / (atr * AtrMultiplier); // Calculation of Stop Loss and Take Profit levels StopLoss = atr * AtrMultiplier; TakeProfit1 = StopLoss * TakeProfit1Multiple; TakeProfit2 = StopLoss * TakeProfit2Multiple; } // Function to check if the purchase conditions are met bool BuyConditions() { double ema200 = iMA(_Symbol, PERIOD_CURRENT, EmaPeriod, 0, MODE_EMA, PRICE_CLOSE); double halftrend = iCustom(_Symbol, PERIOD_CURRENT, "Halftrend", HalfTrendAmplitude, HalfTrendChannelDeviation, 0); if(Bid > ema200 && Bid > halftrend) { return true; } else { return false; } } // Function to check if the conditions of sale are met bool SellConditions() { double ema200 = iMA(_Symbol, PERIOD_CURRENT, EmaPeriod, 0, MODE_EMA, PRICE_CLOSE); double halftrend = iCustom(_Symbol, PERIOD_CURRENT, "Halftrend", HalfTrendAmplitude, HalfTrendChannelDeviation, 0); if(Bid < ema200 && Bid < halftrend) { return true; } else { return false; } } // Function to open a buy trade void OpenBuy() { // Calcul de la taille du lot en fonction de l'équité actuelle double riskAmount = AccountEquity() * RiskPercent; double atr = iATR(_Symbol, PERIOD_CURRENT, AtrPeriod, 0) * AtrMultiplier; double LotSize = NormalizeDouble((riskAmount / atr) / LotSizeDivisor, 2); if(LotSize < MinLotSize) { LotSize = MinLotSize; } else if(LotSize > MaxLotSize) { LotSize = MaxLotSize; } // Function to open a buy trade void OpenBuy() { // Calculate lot size based on current equity double atr = iATR(_Symbol, PERIOD_CURRENT, AtrPeriod); LotSize = (AccountEquity() * RiskPercentage) / (atr * AtrMultiplier); // Calculation of Stop Loss and Take Profit levels StopLoss = Bid - (atr * AtrMultiplier); TakeProfit1 = Bid + (TakeProfit1Multiple * StopLoss); TakeProfit2 = Bid + (TakeProfit2Multiple * StopLoss); // Open the trade OrderSend(_Symbol, OP_BUY, LotSize, Bid, 3, StopLoss, TakeProfit1, "EA Buy", MagicNumber); } // Function to open a sell trade void OpenSell() { // Calculate lot size based on current equity double atr = iATR(_Symbol, PERIOD_CURRENT, AtrPeriod); LotSize = (AccountEquity() * RiskPercentage) / (atr * AtrMultiplier); // Calculation of Stop Loss and Take Profit levels StopLoss = Ask + (atr * AtrMultiplier); TakeProfit1 = Ask - (TakeProfit1Multiple * StopLoss); TakeProfit2 = Ask - (TakeProfit2Multiple * StopLoss); // Open the trade OrderSend(_Symbol, OP_SELL, LotSize, Ask, 3, StopLoss, TakeProfit1, "EA Sell", MagicNumber); } // Function to manage open trades void ManageTrades() { // Retrieve trade information int ticket = OrderTicket(); double openPrice = OrderOpenPrice(); double currentPrice = NormalizeDouble((Bid + Ask) / 2, _Digits); double profit = OrderProfit(); // Check if the trade is in profit if(profit > 0) { // Activation of breakeven if take profit 1 is reached if(!BreakevenActivated && currentPrice >= BreakevenPrice) { BreakevenActivated = true; BreakevenPrice = openPrice; if(OrderType() == OP_BUY) { BreakevenPrice += (StopLoss - openPrice); } else { BreakevenPrice -= (StopLoss - openPrice); } ModifyPosition(ticket, StopLoss, BreakevenPrice, TakeProfit2); } } // Partial closure of the position if take profit 1 is reached if(currentPrice >= (openPrice + StopLoss) && OrderType() == OP_BUY) { double closeLots = LotSize / 2; OrderClose(ticket, closeLots, Bid, 3); BreakevenActivated = false; } else if(currentPrice <= (openPrice - StopLoss) && OrderType() == OP_SELL) { double closeLots = LotSize / 2; OrderClose(ticket, closeLots, Ask, 3); BreakevenActivated = false; } // Close remaining position if take profit 2 is reached if(currentPrice >= (openPrice + (2 * StopLoss)) && OrderType() == OP_BUY) { OrderClose(ticket, LotSize, Bid, 3); BreakevenActivated = false; } else if(currentPrice <= (openPrice - (2 * StopLoss)) && OrderType() == OP_SELL) { OrderClose(ticket, LotSize, Ask, 3); BreakevenActivated = false; } } // Function for managing order execution errors bool IsTradeContextBusy() { if(!IsTradeAllowed()) { Print("Trade is not allowed!"); return true; } if(IsTradeContextBusy()) { Sleep(1000); return true; } return false; } // Main EA function void OnTick() { // Check if the EA is allowed to trade if(IsTradeContextBusy()) { return; } // Calculation of the indicators double ema200 = iMA(_Symbol, PERIOD_CURRENT, EmaPeriod, 0, MODE_EMA, PRICE_CLOSE, 0); double halftrend = iCustom(_Symbol, PERIOD_CURRENT, "HalfTrend-1.02", HalftrendAmplitude, HalftrendChannelDeviation, 0); // Check the conditions of purchase and sale if(Bid > ema200 && Bid > halftrend) { if(OrdersTotal() == 0) { OpenBuy(); } } else if(Ask < ema200 && Ask < halftrend) { if(OrdersTotal() == 0) { OpenSell(); } } // Management of open trades for(int i = 0; i < OrdersTotal(); i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { ManageTrades(); } } } //+------------------------------------------------------------------+I will be very grateful!
Mustafa Z.