My Bot can't take any trades on XAUUSD even the script likes correct. What correction should I bring please.


hi add this before on tick
bool AllowTrading = true;
add this bloc in on tick to allow trades
#include <Trade\Trade.mqh> CTrade trade; void OnTick() { // 1. Vérifie spread if(MaxSpread != 0 && SymbolInfoInteger(Symbol(), SYMBOL_SPREAD) > MaxSpread) { AllowTrading = false; Print("Spread: ", SymbolInfoInteger(Symbol(), SYMBOL_SPREAD), " > MaxSpread = ", MaxSpread, " → trading désactivé."); return; } else AllowTrading = true; // 2. Vérifie s'il y a déjà assez de trades ouverts int open_trades = 0; for(int i = 0; i < PositionsTotal(); i++) { if(PositionGetTicket(i) != -1) { if(PositionGetInteger(POSITION_MAGIC) == Magic_Number) open_trades++; } } if(Max_Trades != 0 && open_trades >= Max_Trades) { Print("Nombre max de trades atteints: ", open_trades); return; } // 3. Vérifie si trading est autorisé globalement if(!AllowTrading || !TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)) { Print("Trading non autorisé par le terminal."); return; } // 4. CONDITIONS DE STRATÉGIE (exemple simplifié) double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); double sl = ask - 200 * _Point; double tp = ask + 400 * _Point; // 5. Envoi d’ordre exemple if(trade.Buy(0.1, _Symbol, ask, sl, tp, "Buy Order")) Print("Trade envoyé avec succès !"); else Print("Erreur en envoyant l’ordre : ", trade.ResultRetcode(), " - ", trade.ResultRetcodeDescription()); }
Improperly formatted code edited by moderator. Please always and use the CODE button (Alt-S) when inserting code.
Samuel Bedin #:
hi add this before on tick
add this bloc in on tick to allow trades
Improperly formatted code edited by moderator. Please always and use the CODE button (Alt-S) when inserting code.
Thanks a lot
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