| //+------------------------------------------------------------------+
|
| //| M1_Frequent_Scalper.mq5|
|
| //| Copyright 2026, Personal AI |
|
| //| https://www.mql5.com |
|
| //+------------------------------------------------------------------+
|
| #property copyright "Copyright 2026"
|
| #property link "https://www.mql5.com"
|
| #property version "1.00"
|
| #property strict
|
|
|
| //--- Inclure la bibliothèque de trading standard
|
| #include <Trade\Trade.mqh>
|
| CTrade trade;
|
|
|
| //--- Paramètres d'entrées (Inputs)
|
| input group "=== Paramètres de Gestion des Risques =="
|
| input double InpLotSize = 0.1; // Taille du lot
|
| input int InpStopLoss = 150; // Stop Loss (en points)
|
| input int InpTakeProfit = 300; // Take Profit (en points)
|
| input int InpMaxSpread = 30; // Spread maximum autorisé (en points)
|
|
|
| input group "=== Paramètres des Indicateurs (EMA) =="
|
| input int InpFastEMAPeriod = 9; // Période EMA Rapide
|
| input int InpSlowEMAPeriod = 21; // Période EMA Lente
|
|
|
| //--- Variables globales
|
| int fastEMAHandle;
|
| int slowEMAHandle;
|
| datetime lastBarTime;
|
|
|
| //+------------------------------------------------------------------+
|
| //| Expert initialization function |
|
| //+------------------------------------------------------------------+
|
| int OnInit()
|
| {
|
| // Configuration du Magic Number pour identifier les ordres du robot
|
| trade.SetExpertMagicNumber(123456);
|
|
|
| // Création des handles des indicateurs EMA
|
| fastEMAHandle = iMA(_Symbol, _Period, InpFastEMAPeriod, 0, MODE_EMA, PRICE_CLOSE);
|
| slowEMAHandle = iMA(_Symbol, _Period, InpSlowEMAPeriod, 0, MODE_EMA, PRICE_CLOSE);
|
|
|
| if(fastEMAHandle == INVALID_HANDLE || slowEMAHandle == INVALID_HANDLE)
|
| {
|
| Print("Erreur : Impossible de créer les handles des indicateurs EMA.");
|
| return(INIT_FAILED);
|
| }
|
|
|
| lastBarTime = 0;
|
| Print("EA M1 Scalper initialisé avec succès !");
|
| return(INIT_SUCCEEDED);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| Expert deinitialization function |
|
| //+------------------------------------------------------------------+
|
| void OnDeinit(const int reason)
|
| {
|
| // Libération des handles d'indicateurs pour éviter les fuites mémoire
|
| IndicatorRelease(fastEMAHandle);
|
| IndicatorRelease(slowEMAHandle);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| Expert tick function |
|
| //+------------------------------------------------------------------+
|
| void OnTick()
|
| {
|
| // 1. Vérification d'une nouvelle barre sur M1
|
| datetime currentBarTime = iTime(_Symbol, _Period, 0);
|
| if(currentBarTime == lastBarTime) return; // Attendre la bougie suivante
|
|
|
| // 2. Vérification du spread
|
| long currentSpread = SymbolInfoInteger(_Symbol, SYMBOL_SPREAD);
|
| if(currentSpread > InpMaxSpread) return;
|
|
|
| // 3. Récupération des valeurs des EMA ([1] = bougie fermée, [2] = bougie précédente)
|
| double fastEMA[], slowEMA[];
|
| ArraySetAsSeries(fastEMA, true);
|
| ArraySetAsSeries(slowEMA, true);
|
|
|
| if(CopyBuffer(fastEMAHandle, 0, 0, 3, fastEMA) <= 0 || CopyBuffer(slowEMAHandle, 0, 0, 3, slowEMA) <= 0)
|
| {
|
| Print("Erreur lors de la copie des buffers des indicateurs.");
|
| return;
|
| }
|
|
|
| // 4. Logique de trading (si aucune position n'est ouverte)
|
| if(PositionsTotal() == 0)
|
| {
|
| // Croisement haussier : EMA rapide passe au-dessus de l'EMA lente
|
| bool buySignal = (fastEMA[1] > slowEMA[1]) && (fastEMA[2] <= slowEMA[2]);
|
|
|
| // Croisement baissier : EMA rapide passe en dessous de l'EMA lente
|
| bool sellSignal = (fastEMA[1] < slowEMA[1]) && (fastEMA[2] >= slowEMA[2]);
|
|
|
| double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
|
| double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
|
|
| if(buySignal)
|
| {
|
| double sl = (InpStopLoss > 0) ? ask - InpStopLoss * _Point : 0;
|
| double tp = (InpTakeProfit > 0) ? ask + InpTakeProfit * _Point : 0;
|
|
|
| if(trade.Buy(InpLotSize, _Symbol, ask, sl, tp, "M1 Scalper Buy"))
|
| {
|
| lastBarTime = currentBarTime;
|
| Print("Ordre d'ACHAT exécuté avec succès à ", ask);
|
| }
|
| }
|
| else if(sellSignal)
|
| {
|
| double sl = (InpStopLoss > 0) ? bid + InpStopLoss * _Point : 0;
|
| double tp = (InpTakeProfit > 0) ? bid - InpTakeProfit * _Point : 0;
|
|
|
| if(trade.Sell(InpLotSize, _Symbol, bid, sl, tp, "M1 Scalper Sell"))
|
| {
|
| lastBarTime = currentBarTime;
|
| Print("Ordre de VENTE exécuté avec succès à ", bid);
|
| }
|
| }
|
| }
|
| }
|