This commit is contained in:
zhutoutoutousan
2026-05-27 14:59:00 +02:00
parent b5acd37754
commit 3f75a08848
122 changed files with 5259 additions and 12459 deletions
@@ -0,0 +1,35 @@
; saved on 2026.05.13
; genetic optimization set for EMASlopeDistanceCocktailXAUUSD/main.mq5
; load in MT5 Strategy Tester -> Inputs -> Load
; format: Parameter=Current||Start||Step||Stop||Optimize(Y/N)
;
; ENUM_TIMEFRAMES: M1=1 M5=5 M15=15 M30=30 H1=16385 H4=16388 D1=16408
; Timeframe fixed at H1 (16385); sweeping 0..49153 can pick invalid enum values.
;
; Ranges/steps match Desktop 123.set (2026.05.13); Y marks parameters included in genetic optimization.
; === EMA / trigger thresholds ===
EMA_Periode=50||50||1||500||Y
PreisSchwelle=700.0||70.0||70.0||7000.0||Y
SteigungSchwelle=25.0||2.5||2.5||250.0||Y
ÜberwachungTimeout=340||1||1||3400||Y
TrailingStop=370.0||37.0||37.0||3700.0||Y
LotGröße=0.07||0.007||0.007||0.7||Y
; === execution / data ===
MagicNumber=135790||135790||1||1357900||N
UseSpreadAdjustment=true||false||0||true||N
Timeframe=16385||16385||0||16385||N
UseBarData=true||false||0||true||N
; === crossover / profit management ===
MaxTradesPerCrossover=10||1||1||100||Y
ProfitCheckBars=15||1||1||150||Y
CloseUnprofitableTrades=true||false||0||true||N
; === weekly ADX filter ===
UseWeeklyADXFilter=true||false||0||true||N
WeeklyADXPeriod=15||1||1||150||Y
WeeklyADXMin=40.0||4.0||4.0||400.0||Y
WeeklyADXBarShift=2||1||1||20||Y
WeeklyADXUseDirection=true||false||0||true||N
@@ -8,24 +8,24 @@
#property version "1.00"
#include <Trade\Trade.mqh>
#include "../_united/MagicNumberHelpers.mqh"
//--- Eingabeparameter (Input Parameters) - Optimized Profitable Parameters
input int EMA_Periode = 50; // EMA Periode
input double PreisSchwelle = 700.0; // Preisbewegung Schwelle in Pips
input double SteigungSchwelle = 25.0; // EMA Steigung Schwelle in Pips
//--- Eingabeparameter (Input Parameters) — synced with Desktop 123.set (2026.05.13)
input int EMA_Periode = 85; // EMA Periode
input double PreisSchwelle = 350.0; // Preisbewegung Schwelle in Pips
input double SteigungSchwelle = 22.5; // EMA Steigung Schwelle in Pips
input int ÜberwachungTimeout = 340; // Überwachungszeit in Sekunden
input double TrailingStop = 370.0; // Gleitender Stop in Pips
input double TrailingStop = 74.0; // Gleitender Stop in Pips
input double LotGröße = 0.07; // Handelsvolumen
input int MagicNumber = 135790; // Magic Number für Trades
input bool UseSpreadAdjustment = true; // Spread-Anpassung verwenden
input ENUM_TIMEFRAMES Timeframe = PERIOD_H1; // Zeitraum für Analyse
input bool UseBarData = true; // Bar-Daten statt Tick-Daten verwenden
input int MaxTradesPerCrossover = 10; // Maximale Trades pro Crossover-Ereignis
input int ProfitCheckBars = 15; // Bars bis zur Profit-Prüfung
input int MaxTradesPerCrossover = 48; // Maximale Trades pro Crossover-Ereignis
input int ProfitCheckBars = 78; // Bars bis zur Profit-Prüfung
input bool CloseUnprofitableTrades = true; // Unprofitable Trades nach X Bars schließen
input bool UseWeeklyADXFilter = true; // W1 ADX Trendfilter aktivieren
input int WeeklyADXPeriod = 15; // ADX-Periode auf W1
input double WeeklyADXMin = 40.0; // Minimaler ADX fuer Trendfreigabe
input int WeeklyADXBarShift = 2; // 1=letzte geschlossene W1-Kerze
input int WeeklyADXPeriod = 28; // ADX-Periode auf W1
input double WeeklyADXMin = 25.0; // Minimaler ADX fuer Trendfreigabe
input int WeeklyADXBarShift = 8; // 1=letzte geschlossene W1-Kerze
input bool WeeklyADXUseDirection = true; // +DI/-DI Richtung mitpruefen
//--- Globale Variablen (Global Variables)
@@ -1,347 +0,0 @@
//+------------------------------------------------------------------+
//| RSIConsolidation.mq5 |
//| Mean-reversion RSI for ranging markets; trend filters block runs |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025"
#property link "https://www.mql5.com"
#property version "1.00"
#include <Trade\Trade.mqh>
//--- Symbol (empty = chart symbol)
input group "=== Symbol & session ==="
input string InpSymbol = "";
input group "=== Timeframe & bar logic ==="
input ENUM_TIMEFRAMES SignalTF = PERIOD_M15;
input bool EntryOnNewBarOnly = true;
//--- Core: no trend / consolidation regime
input group "=== Regime: consolidation (anti-trend) ==="
input int ADX_Period = 23;
input double ADX_Max = 29.0;
input bool UseATRRatioFilter = true;
input int ATR_Period = 8;
input int ATR_SMA_Period = 35;
input double ATR_Ratio_Max = 1.36;
input bool UseFlatEMAFilter = true;
input int EMA_Fast = 13;
input int EMA_Slow = 17;
input double EMA_Separation_MaxPct = 0.26;
//--- RSI entries (fade extremes toward mean)
input group "=== RSI entries ==="
input int RSI_Period = 8;
input ENUM_APPLIED_PRICE RSI_Price = PRICE_OPEN;
input double RSI_Oversold = 22.0;
input double RSI_Overbought = 63.0;
//--- Exits: mean target + hard ATR bracket
input group "=== Exits ==="
input bool UseRSI_MeanExit = true;
input double RSI_Exit_Long = 48.0;
input double RSI_Exit_Short = 52.0;
input double SL_ATR_Mult = 2.15;
input double TP_ATR_Mult = 2.40;
input int MaxBarsInTrade = 54;
input group "=== Risk & execution ==="
input double Lots = 0.10;
input ulong MagicNumber = 20250420;
input int Slippage = 10;
input int MaxSpreadPoints = 28;
CTrade trade;
string g_sym;
int h_rsi = INVALID_HANDLE;
int h_adx = INVALID_HANDLE;
int h_atr = INVALID_HANDLE;
int h_ema_fast = INVALID_HANDLE;
int h_ema_slow = INVALID_HANDLE;
datetime g_last_bar = 0;
bool PositionExistsByMagicSym(string sym, ulong magic)
{
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong t = PositionGetTicket(i);
if(t == 0) continue;
if(PositionGetString(POSITION_SYMBOL) == sym && PositionGetInteger(POSITION_MAGIC) == (long)magic)
return true;
}
return false;
}
ulong GetPositionTicketByMagicSym(string sym, ulong magic)
{
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong t = PositionGetTicket(i);
if(t == 0) continue;
if(PositionGetString(POSITION_SYMBOL) == sym && PositionGetInteger(POSITION_MAGIC) == (long)magic)
return t;
}
return 0;
}
bool SelectPositionTicketSymMagic(ulong ticket, string sym, ulong magic)
{
if(!PositionSelectByTicket(ticket)) return false;
return PositionGetString(POSITION_SYMBOL) == sym && PositionGetInteger(POSITION_MAGIC) == (long)magic;
}
double NormalizeVolume(string sym, double vol)
{
double minLot = SymbolInfoDouble(sym, SYMBOL_VOLUME_MIN);
double maxLot = SymbolInfoDouble(sym, SYMBOL_VOLUME_MAX);
double step = SymbolInfoDouble(sym, SYMBOL_VOLUME_STEP);
if(step > 0.0)
vol = MathFloor(vol / step) * step;
if(vol < minLot) vol = minLot;
if(vol > maxLot) vol = maxLot;
return vol;
}
int CurrentSpreadPoints(string sym)
{
long spread = 0;
if(!SymbolInfoInteger(sym, SYMBOL_SPREAD, spread))
return 999999;
return (int)spread;
}
double MinStopsDistancePrice(string sym)
{
long lvl = 0;
if(!SymbolInfoInteger(sym, SYMBOL_TRADE_STOPS_LEVEL, lvl))
return 0;
double pt = SymbolInfoDouble(sym, SYMBOL_POINT);
if(pt <= 0)
return 0;
return (double)lvl * pt;
}
bool Copy1(int handle, double &v)
{
double b[];
ArraySetAsSeries(b, true);
if(CopyBuffer(handle, 0, 0, 1, b) < 1) return false;
v = b[0];
return true;
}
bool RSI_Buffers(double &cur, double &prev, double &twoAgo)
{
double b[];
ArraySetAsSeries(b, true);
if(CopyBuffer(h_rsi, 0, 0, 3, b) < 3) return false;
cur = b[0];
prev = b[1];
twoAgo = b[2];
return true;
}
bool Regime_IsConsolidation()
{
double adx = 0;
if(!Copy1(h_adx, adx))
return false;
if(adx >= ADX_Max)
return false;
if(UseATRRatioFilter)
{
double atrArr[], atrSma[];
ArraySetAsSeries(atrArr, true);
if(CopyBuffer(h_atr, 0, 0, ATR_SMA_Period + 1, atrArr) < ATR_SMA_Period + 1)
return false;
double sum = 0;
for(int i = 1; i <= ATR_SMA_Period; i++)
sum += atrArr[i];
double smaAtr = sum / (double)ATR_SMA_Period;
if(smaAtr <= 0.0)
return false;
double ratio = atrArr[0] / smaAtr;
if(ratio > ATR_Ratio_Max)
return false;
}
if(UseFlatEMAFilter)
{
double ef[], es[];
ArraySetAsSeries(ef, true);
ArraySetAsSeries(es, true);
if(CopyBuffer(h_ema_fast, 0, 0, 1, ef) < 1) return false;
if(CopyBuffer(h_ema_slow, 0, 0, 1, es) < 1) return false;
double c = SymbolInfoDouble(g_sym, SYMBOL_BID);
if(c <= 0) return false;
double sep = MathAbs(ef[0] - es[0]) / c * 100.0;
if(sep > EMA_Separation_MaxPct)
return false;
}
return true;
}
bool Entry_BuyCross(double twoAgo, double prev)
{
return (twoAgo <= RSI_Oversold && prev > RSI_Oversold);
}
bool Entry_SellCross(double twoAgo, double prev)
{
return (twoAgo >= RSI_Overbought && prev < RSI_Overbought);
}
void TryCloseByRSI(ENUM_POSITION_TYPE typ, double rsi)
{
ulong tk = GetPositionTicketByMagicSym(g_sym, MagicNumber);
if(tk == 0 || !SelectPositionTicketSymMagic(tk, g_sym, MagicNumber))
return;
if(!UseRSI_MeanExit)
return;
if(typ == POSITION_TYPE_BUY && rsi >= RSI_Exit_Long)
trade.PositionClose(tk);
else if(typ == POSITION_TYPE_SELL && rsi <= RSI_Exit_Short)
trade.PositionClose(tk);
}
void ManageOpenPosition(double rsi)
{
ulong tk = GetPositionTicketByMagicSym(g_sym, MagicNumber);
if(tk == 0 || !SelectPositionTicketSymMagic(tk, g_sym, MagicNumber))
return;
ENUM_POSITION_TYPE typ = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
datetime openT = (datetime)PositionGetInteger(POSITION_TIME);
int barsAgo = iBarShift(g_sym, SignalTF, openT, false);
if(barsAgo >= 0 && barsAgo >= MaxBarsInTrade)
{
trade.PositionClose(tk);
return;
}
TryCloseByRSI(typ, rsi);
}
int OnInit()
{
g_sym = InpSymbol;
StringTrimLeft(g_sym);
StringTrimRight(g_sym);
if(StringLen(g_sym) == 0)
g_sym = _Symbol;
if(!SymbolSelect(g_sym, true))
{
Print("RSIConsolidation: SymbolSelect failed: ", g_sym);
return INIT_FAILED;
}
trade.SetExpertMagicNumber(MagicNumber);
trade.SetDeviationInPoints(Slippage);
trade.SetTypeFilling(ORDER_FILLING_RETURN);
h_rsi = iRSI(g_sym, SignalTF, RSI_Period, RSI_Price);
h_adx = iADX(g_sym, SignalTF, ADX_Period);
h_atr = iATR(g_sym, SignalTF, ATR_Period);
h_ema_fast = iMA(g_sym, SignalTF, EMA_Fast, 0, MODE_EMA, PRICE_CLOSE);
h_ema_slow = iMA(g_sym, SignalTF, EMA_Slow, 0, MODE_EMA, PRICE_CLOSE);
if(h_rsi == INVALID_HANDLE || h_adx == INVALID_HANDLE || h_atr == INVALID_HANDLE
|| h_ema_fast == INVALID_HANDLE || h_ema_slow == INVALID_HANDLE)
{
Print("RSIConsolidation: indicator init failed");
return INIT_FAILED;
}
Print("RSIConsolidation: symbol=", g_sym, " TF=", EnumToString(SignalTF));
return INIT_SUCCEEDED;
}
void OnDeinit(const int reason)
{
if(h_rsi != INVALID_HANDLE) IndicatorRelease(h_rsi);
if(h_adx != INVALID_HANDLE) IndicatorRelease(h_adx);
if(h_atr != INVALID_HANDLE) IndicatorRelease(h_atr);
if(h_ema_fast != INVALID_HANDLE) IndicatorRelease(h_ema_fast);
if(h_ema_slow != INVALID_HANDLE) IndicatorRelease(h_ema_slow);
}
bool EnoughHistory()
{
int need = MathMax(RSI_Period + 3, MathMax(ADX_Period + 2, ATR_SMA_Period + 3));
if(Bars(g_sym, SignalTF) < need)
return false;
return true;
}
void OnTick()
{
if(!EnoughHistory())
return;
if(MaxSpreadPoints > 0 && CurrentSpreadPoints(g_sym) > MaxSpreadPoints)
return;
double rsi, rsiPrev, rsi2;
if(!RSI_Buffers(rsi, rsiPrev, rsi2))
return;
datetime barTime = iTime(g_sym, SignalTF, 0);
bool isNew = (barTime != g_last_bar);
if(PositionExistsByMagicSym(g_sym, MagicNumber))
{
ManageOpenPosition(rsi);
if(isNew)
g_last_bar = barTime;
return;
}
if(EntryOnNewBarOnly && !isNew)
return;
g_last_bar = barTime;
if(!Regime_IsConsolidation())
return;
double atrArr[];
ArraySetAsSeries(atrArr, true);
if(CopyBuffer(h_atr, 0, 0, 1, atrArr) < 1)
return;
double atr = atrArr[0];
int dig = (int)SymbolInfoInteger(g_sym, SYMBOL_DIGITS);
double slDist = atr * SL_ATR_Mult;
double tpDist = atr * TP_ATR_Mult;
double minD = MinStopsDistancePrice(g_sym);
if(slDist < minD)
slDist = minD;
if(tpDist < minD)
tpDist = minD;
double vol = NormalizeVolume(g_sym, Lots);
if(Entry_BuyCross(rsi2, rsiPrev))
{
double ask = SymbolInfoDouble(g_sym, SYMBOL_ASK);
double sl = ask - slDist;
double tp = ask + tpDist;
sl = NormalizeDouble(sl, dig);
tp = NormalizeDouble(tp, dig);
trade.Buy(vol, g_sym, ask, sl, tp, "RSIConsolidation BUY");
}
else if(Entry_SellCross(rsi2, rsiPrev))
{
double bid = SymbolInfoDouble(g_sym, SYMBOL_BID);
double sl = bid + slDist;
double tp = bid - tpDist;
sl = NormalizeDouble(sl, dig);
tp = NormalizeDouble(tp, dig);
trade.Sell(vol, g_sym, bid, sl, tp, "RSIConsolidation SELL");
}
}
//+------------------------------------------------------------------+
@@ -1,37 +0,0 @@
; RSIConsolidation.mq5 — optimization preset (Strategy Tester → Inputs → Load)
; Format: Name=Current||Start||Step||Stop||Y|N (Y = include in optimization)
;
; === Symbol & session ===
InpSymbol=
; === Timeframe & bar logic ===
; SignalTF: optimize per run (ENUM is non-sequential); M15=15, H1=16385, H4=16388
SignalTF=15||15||0||15||N
EntryOnNewBarOnly=true||false||0||true||N
; === Regime: consolidation (anti-trend) ===
ADX_Period=14||7||1||28||Y
ADX_Max=22.0||16.0||1.0||32.0||Y
UseATRRatioFilter=true||false||0||true||N
ATR_Period=14||7||1||21||Y
ATR_SMA_Period=50||20||5||100||Y
ATR_Ratio_Max=1.18||1.0||0.02||1.35||Y
UseFlatEMAFilter=true||false||0||true||N
EMA_Fast=8||5||1||13||Y
EMA_Slow=21||13||2||34||Y
EMA_Separation_MaxPct=0.22||0.08||0.02||0.45||Y
; === RSI entries ===
RSI_Period=14||7||1||21||Y
RSI_Price=1||1||1||7||Y
RSI_Oversold=32.0||22.0||1.0||42.0||Y
RSI_Overbought=68.0||58.0||1.0||78.0||Y
; === Exits ===
UseRSI_MeanExit=true||false||0||true||N
RSI_Exit_Long=52.0||48.0||1.0||62.0||Y
RSI_Exit_Short=48.0||38.0||1.0||52.0||Y
SL_ATR_Mult=1.35||0.9||0.05||2.2||Y
TP_ATR_Mult=1.85||1.0||0.05||3.0||Y
MaxBarsInTrade=36||12||2||80||Y
; === Risk & execution ===
Lots=0.1||0.1||0.01||1.0||N
MagicNumber=20250420||20250420||1||20250420||N
Slippage=10||10||1||100||N
MaxSpreadPoints=0||0||1||30||Y
@@ -0,0 +1,38 @@
; RSICrossOverReversalXAUUSD/main.mq5 — Strategy Tester → Inputs → Load
;
; MT5 line format: Name=Value||From||Step||To||Optimize
; Value = input default when you Load this file
; From, Step, To = optimization range when Optimize=Y (Genetic / slow complete algorithm)
; Optimize=N = keep Value; From/Step/To are ignored
;
; First column matches main.mq5 source defaults (not the old Desktop 123 snapshot).
MagicNumber=7||7||1||7||N
rsiPeriod=19||10||1||35||Y
overboughtLevel=93||65||2||95||Y
oversoldLevel=22||10||1||45||Y
entryRSIBuySpread=0.0||0.0||0.5||8.0||Y
entryRSISellSpread=0.0||0.0||0.5||8.0||Y
lotSize=0.1||0.1||0.01||0.5||N
slippage=3||3||1||3||N
cooldownSeconds=209||60||30||600||Y
TimeFrame1=1||1||0||1||N
TimeFrame2=1||1||0||1||N
BarTimeFrame=12||12||0||12||N
emaPeriod=140||50||10||300||Y
emaSlopeThreshold=105.0||20.0||5.0||200.0||Y
exitBuyRSI=86.0||65.0||1.0||92.0||Y
exitSellRSI=10.0||5.0||1.0||40.0||Y
TrailingStop=295.0||80.0||15.0||450.0||Y
emaDistanceThreshold=165.0||40.0||10.0||350.0||Y
tradingHourOneBegin=24||0||1||23||N
tradingHourOneEnd=22||0||1||23||N
tradingHourTwoBegin=6||0||1||14||Y
tradingHourTwoEnd=19||14||1||23||Y
Sunday=false||false||0||true||Y
Monday=false||false||0||true||Y
Tuesday=true||false||0||true||Y
Wednesday=true||false||0||true||Y
Thursday=true||false||0||true||Y
Friday=false||false||0||true||Y
Saturday=false||false||0||true||Y
@@ -0,0 +1,50 @@
; RSIMidPointHijackXAUUSD/main.mq5 — Strategy Tester → Inputs → Load (Genetic optimization)
; Format: Parameter=Current||Start||Step||Stop||Optimize(Y/N)
;
; Baseline from Desktop 123.set (2026.05.13). InpTimeframe fixed at H1 (16385) to avoid invalid ENUM_TIMEFRAMES.
; RSI level sweeps capped at 100; hour sweeps capped at 23 (123.set used wider columns that are invalid for this EA).
; === General Settings ===
InpTimeframe=16385||16385||1||16385||N
InpLotSize=0.1||0.01||0.01||1.0||Y
InpMagicNumberRSIFollow=1001||1001||1||10010||N
InpMagicNumberRSIReverse=1002||1002||1||10020||N
InpMagicNumberEMACross=1003||1003||1||10030||N
; === Strategy Switches ===
InpEnableRSIFollow=true||false||0||true||N
InpEnableRSIReverse=true||false||0||true||N
InpEnableEMACross=true||false||0||true||N
InpEnableStrategyLock=true||false||0||true||N
InpLockProfitThreshold=6.0||0.6||0.6||60.0||Y
InpCloseOppositeTrades=true||false||0||true||N
; === RSI Follow Strategy ===
InpRSIPeriod=32||8||2||96||Y
InpRSIOverbought=78||60||1||95||Y
InpRSIOversold=46||5||1||45||Y
InpRSIExitLevel=44||10||1||90||Y
InpRSIFollowStartHour=23||0||1||23||Y
InpRSIFollowEndHour=8||0||1||23||Y
InpRSIFollowCloseOutsideHours=false||false||0||true||N
; === RSI Reverse Strategy ===
InpRSIReversePeriod=59||14||2||96||Y
InpRSIReverseOverbought=51||55||1||95||Y
InpRSIReverseOversold=49||5||1||50||Y
InpRSIReverseCrossLevel=53||45||1||70||Y
InpRSIReverseExitLevel=48||10||1||90||Y
InpRSIReverseStartHour=7||0||1||23||Y
InpRSIReverseEndHour=13||0||1||23||Y
InpRSIReverseCloseOutsideHours=false||false||0||true||N
InpRSIReverseCooldownBars=15||1||1||150||Y
InpRSIReverseCooldownOnLoss=true||false||0||true||N
; === EMA Cross Strategy ===
InpEMAPeriod=120||20||5||200||Y
InpEMACrossStartHour=8||0||1||23||Y
InpEMACrossEndHour=14||0||1||23||Y
InpEMACrossCloseOutsideHours=true||false||0||true||N
InpUseEMADistanceEntry=true||false||0||true||N
InpEMADistancePips=160.0||16.0||16.0||1600.0||Y
InpEMADistancePeriod=26||5||1||60||Y
@@ -0,0 +1,23 @@
; RSIReversalAsianAUDUSD/main.mq5 — Strategy Tester → Inputs → Load (Genetic optimization)
; Format: Parameter=Current||Start||Step||Stop||Optimize(Y/N)
; Baseline aligned with current input defaults and Desktop 123.set-style ranges (2026.05.13).
;
; Core RSI / exits
RSIPeriod=28||14||2||40||Y
OverboughtLevel=68.0||55.0||1.0||80.0||Y
OversoldLevel=30.0||18.0||1.0||42.0||Y
TakeProfitPips=175||50||25||350||Y
StopLossPips=5||5||5||80||Y
MaxLotSize=0.2||0.01||0.01||0.2||N
MaxSpread=1000||200||100||2000||Y
MaxDuration=340||48||24||720||Y
UseStopLoss=false||false||0||true||N
UseTakeProfit=false||false||0||true||N
UseRSIExit=true||false||0||true||N
RSIExitLevel=48.0||40.0||1.0||55.0||Y
CloseOutsideSession=true||false||0||true||Y
; Panel (usually fixed; colors as in MT5 saved sets)
PanelBackground=0
PanelText=16777215
PanelX=10||10||1||100||N
PanelY=20||20||1||200||N
@@ -0,0 +1,23 @@
; RSIReversalAsianAUDUSD/main.mq5 — Strategy Tester → Inputs → Load (Genetic optimization)
; Format: Parameter=Current||Start||Step||Stop||Optimize(Y/N)
; Baseline aligned with current input defaults and Desktop 123.set-style ranges (2026.05.13).
;
; Core RSI / exits
RSIPeriod=28||14||2||40||Y
OverboughtLevel=68.0||55.0||1.0||80.0||Y
OversoldLevel=30.0||18.0||1.0||42.0||Y
TakeProfitPips=175||50||25||350||Y
StopLossPips=5||5||5||80||Y
MaxLotSize=0.2||0.01||0.01||0.2||N
MaxSpread=1000||200||100||2000||Y
MaxDuration=340||48||24||720||Y
UseStopLoss=false||false||0||true||N
UseTakeProfit=false||false||0||true||N
UseRSIExit=true||false||0||true||N
RSIExitLevel=48.0||40.0||1.0||55.0||Y
CloseOutsideSession=true||false||0||true||Y
; Panel (usually fixed; colors as in MT5 saved sets)
PanelBackground=0
PanelText=16777215
PanelX=10||10||1||100||N
PanelY=20||20||1||200||N
@@ -0,0 +1,539 @@
//+------------------------------------------------------------------+
//| RSIReversalAsianGBPUSD.mq5 |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
// Include trade class
#include <Trade\Trade.mqh>
// Input parameters (defaults synced from working 123.set 2026.05.13)
input int RSIPeriod = 32; // RSI period
input double OverboughtLevel = 80; // Overbought level
input double OversoldLevel = 37; // Oversold level
input int TakeProfitPips = 225; // Take profit in pips
input int StopLossPips = 45; // Stop loss in pips
input double MaxLotSize = 0.2; // Maximum lot size
input int MaxSpread = 1800; // Maximum allowed spread in pips
input int MaxDuration = 480; // Maximum trade duration in hours
input bool UseStopLoss = false; // Use stop loss
input bool UseTakeProfit = false; // Use take profit
input bool UseRSIExit = true; // Use RSI for exit
input double RSIExitLevel = 43; // RSI level to exit (50 = neutral)
input bool CloseOutsideSession = true; // Close trades outside Asian session
input color PanelBackground = clrBlack; // Panel background color
input color PanelText = clrWhite; // Panel text color
input int PanelX = 10; // Panel X position
input int PanelY = 20; // Panel Y position
// Global variables
CTrade trade;
int rsiHandle;
bool isPositionOpen = false;
double positionOpenPrice = 0;
datetime positionOpenTime = 0;
ENUM_POSITION_TYPE lastPositionType = POSITION_TYPE_BUY;
bool sessionCloseAttempted = false; // Track if we've attempted to close positions for current session
// RSI crossover variables
double rsiCurrent = 0;
double rsiPrevious = 0;
double rsiPrevious2 = 0;
bool rsiCrossedOverbought = false;
bool rsiCrossedOversold = false;
bool rsiCrossedExitLevel = false;
// Panel objects
string panelName = "RSIPanel";
int panelWidth = 200;
int panelHeight = 200;
int labelHeight = 20;
int labelSpacing = 5;
// Session times (UTC)
const int AsianSessionStart = 0; // 00:00 UTC
const int AsianSessionEnd = 8; // 08:00 UTC
//+------------------------------------------------------------------+
//| Create panel |
//+------------------------------------------------------------------+
void CreatePanel()
{
// Create panel background
ObjectCreate(0, panelName, OBJ_RECTANGLE_LABEL, 0, 0, 0);
ObjectSetInteger(0, panelName, OBJPROP_XDISTANCE, PanelX);
ObjectSetInteger(0, panelName, OBJPROP_YDISTANCE, PanelY);
ObjectSetInteger(0, panelName, OBJPROP_XSIZE, panelWidth);
ObjectSetInteger(0, panelName, OBJPROP_YSIZE, panelHeight);
ObjectSetInteger(0, panelName, OBJPROP_BGCOLOR, PanelBackground);
ObjectSetInteger(0, panelName, OBJPROP_BORDER_TYPE, BORDER_FLAT);
ObjectSetInteger(0, panelName, OBJPROP_CORNER, CORNER_LEFT_UPPER);
ObjectSetInteger(0, panelName, OBJPROP_COLOR, PanelText);
ObjectSetInteger(0, panelName, OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0, panelName, OBJPROP_WIDTH, 1);
ObjectSetInteger(0, panelName, OBJPROP_BACK, false);
ObjectSetInteger(0, panelName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, panelName, OBJPROP_SELECTED, false);
ObjectSetInteger(0, panelName, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, panelName, OBJPROP_ZORDER, 0);
// Create title label
ObjectCreate(0, panelName + "Title", OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, panelName + "Title", OBJPROP_XDISTANCE, PanelX + 5);
ObjectSetInteger(0, panelName + "Title", OBJPROP_YDISTANCE, PanelY + 5);
ObjectSetInteger(0, panelName + "Title", OBJPROP_CORNER, CORNER_LEFT_UPPER);
ObjectSetString(0, panelName + "Title", OBJPROP_TEXT, "RSI Reversal");
ObjectSetInteger(0, panelName + "Title", OBJPROP_COLOR, PanelText);
ObjectSetInteger(0, panelName + "Title", OBJPROP_FONTSIZE, 10);
// Create score labels
CreateScoreLabel("RSI", "RSI: ", 0);
CreateScoreLabel("Position", "Position: ", 1);
CreateScoreLabel("Spread", "Spread: ", 2);
CreateScoreLabel("Session", "Session: ", 3);
CreateScoreLabel("SL", "Stop Loss: ", 4);
CreateScoreLabel("TP", "Take Profit: ", 5);
CreateScoreLabel("Cross", "Cross: ", 6);
}
//+------------------------------------------------------------------+
//| Create score label |
//+------------------------------------------------------------------+
void CreateScoreLabel(string name, string text, int index)
{
ObjectCreate(0, panelName + name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, panelName + name, OBJPROP_XDISTANCE, PanelX + 5);
ObjectSetInteger(0, panelName + name, OBJPROP_YDISTANCE, PanelY + 30 + index * (labelHeight + labelSpacing));
ObjectSetInteger(0, panelName + name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
ObjectSetString(0, panelName + name, OBJPROP_TEXT, text);
ObjectSetInteger(0, panelName + name, OBJPROP_COLOR, PanelText);
ObjectSetInteger(0, panelName + name, OBJPROP_FONTSIZE, 8);
}
//+------------------------------------------------------------------+
//| Update panel values |
//+------------------------------------------------------------------+
void UpdatePanel(double rsi, string position, int spread, string session, double sl, double tp, string crossInfo)
{
ObjectSetString(0, panelName + "RSI", OBJPROP_TEXT, "RSI: " + DoubleToString(rsi, 2));
ObjectSetString(0, panelName + "Position", OBJPROP_TEXT, "Position: " + position);
ObjectSetString(0, panelName + "Spread", OBJPROP_TEXT, "Spread: " + IntegerToString(spread) + " pips");
ObjectSetString(0, panelName + "Session", OBJPROP_TEXT, "Session: " + session);
ObjectSetString(0, panelName + "SL", OBJPROP_TEXT, "Stop Loss: " + IntegerToString(StopLossPips) + " pips");
ObjectSetString(0, panelName + "TP", OBJPROP_TEXT, "Take Profit: " + IntegerToString(TakeProfitPips) + " pips");
ObjectSetString(0, panelName + "Cross", OBJPROP_TEXT, "Cross: " + crossInfo);
}
//+------------------------------------------------------------------+
//| Check if current time is in Asian session |
//+------------------------------------------------------------------+
bool IsAsianSession()
{
datetime currentTime = TimeCurrent();
MqlDateTime timeStruct;
TimeToStruct(currentTime, timeStruct);
return (timeStruct.hour >= AsianSessionStart && timeStruct.hour < AsianSessionEnd);
}
//+------------------------------------------------------------------+
//| Get current session name |
//+------------------------------------------------------------------+
string GetCurrentSession()
{
datetime currentTime = TimeCurrent();
MqlDateTime timeStruct;
TimeToStruct(currentTime, timeStruct);
if(timeStruct.hour >= AsianSessionStart && timeStruct.hour < AsianSessionEnd)
return "Asian";
else if(timeStruct.hour >= 8 && timeStruct.hour < 16)
return "London";
else if(timeStruct.hour >= 13 && timeStruct.hour < 21)
return "New York";
else
return "Other";
}
//+------------------------------------------------------------------+
//| Check if trading is allowed |
//+------------------------------------------------------------------+
bool IsTradingAllowed()
{
// Check if market is open
if(!SymbolInfoInteger(_Symbol, SYMBOL_TRADE_MODE) == SYMBOL_TRADE_MODE_FULL)
{
return false;
}
// Check if we have enough money
if(AccountInfoDouble(ACCOUNT_MARGIN_FREE) <= 0)
{
return false;
}
return true;
}
//+------------------------------------------------------------------+
//| Check RSI crossover conditions |
//+------------------------------------------------------------------+
void CheckRSICrossover()
{
// Reset crossover flags
rsiCrossedOverbought = false;
rsiCrossedOversold = false;
rsiCrossedExitLevel = false;
// Check for overbought crossover (RSI crosses above overbought level)
if(rsiPrevious < OverboughtLevel && rsiCurrent >= OverboughtLevel)
{
rsiCrossedOverbought = true;
}
// Check for oversold crossover (RSI crosses below oversold level)
if(rsiPrevious > OversoldLevel && rsiCurrent <= OversoldLevel)
{
rsiCrossedOversold = true;
}
// Check for exit level crossover
if(rsiPrevious < RSIExitLevel && rsiCurrent >= RSIExitLevel)
{
rsiCrossedExitLevel = true;
}
else if(rsiPrevious > RSIExitLevel && rsiCurrent <= RSIExitLevel)
{
rsiCrossedExitLevel = true;
}
}
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Initialize RSI indicator
rsiHandle = iRSI(_Symbol, PERIOD_M15, RSIPeriod, PRICE_CLOSE);
if(rsiHandle == INVALID_HANDLE)
{
return(INIT_FAILED);
}
// Wait a bit for the indicator to be ready
Sleep(100);
// Initialize RSI values with retry logic
double rsi[];
ArraySetAsSeries(rsi, true);
int retryCount = 0;
bool rsiInitialized = false;
while(retryCount < 10 && !rsiInitialized)
{
int copied = CopyBuffer(rsiHandle, 0, 0, 3, rsi);
if(copied >= 3)
{
rsiCurrent = rsi[0];
rsiPrevious = rsi[1];
rsiPrevious2 = rsi[2];
rsiInitialized = true;
}
else
{
retryCount++;
Sleep(100);
}
}
if(!rsiInitialized)
{
// Don't fail initialization, just set default values
rsiCurrent = 50.0;
rsiPrevious = 50.0;
rsiPrevious2 = 50.0;
}
// Create panel
CreatePanel();
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Release indicator handles
IndicatorRelease(rsiHandle);
// Remove panel objects
ObjectsDeleteAll(0, panelName);
}
//+------------------------------------------------------------------+
//| Close all trades for the current symbol |
//+------------------------------------------------------------------+
bool CloseAllTrades(string reason = "")
{
bool allClosed = true;
int totalPositions = PositionsTotal();
if(totalPositions == 0)
return true;
// Check if there are any positions with our magic number
bool hasOurPositions = false;
for(int i = 0; i < totalPositions; i++)
{
if(PositionGetSymbol(i) == _Symbol && PositionGetInteger(POSITION_MAGIC) == 123456)
{
hasOurPositions = true;
break;
}
}
for(int i = totalPositions - 1; i >= 0; i--)
{
if(PositionGetSymbol(i) == _Symbol)
{
// Try to close position with retry logic
int retryCount = 0;
bool positionClosed = false;
while(retryCount < 3 && !positionClosed)
{
if(trade.PositionClose(_Symbol))
{
isPositionOpen = false;
positionClosed = true;
}
else
{
int error = GetLastError();
// If error is 4756 (Trade disabled), wait longer before retry
if(error == 4756)
{
Sleep(5000); // Wait 5 seconds before retry
retryCount++;
}
else
{
// For other errors, break the loop
break;
}
}
}
if(!positionClosed)
{
allClosed = false;
}
}
}
return allClosed;
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Check if trading is allowed
if(!IsTradingAllowed())
{
return;
}
// Check if we're in Asian session
if(!IsAsianSession())
{
// Close all positions if outside Asian session and CloseOutsideSession is true
if(CloseOutsideSession && !sessionCloseAttempted)
{
CloseAllTrades("Outside Asian session");
sessionCloseAttempted = true;
}
return;
}
else
{
// Reset the session close attempt flag when we enter Asian session
sessionCloseAttempted = false;
}
// Get current spread
double spread = SymbolInfoDouble(_Symbol, SYMBOL_ASK) - SymbolInfoDouble(_Symbol, SYMBOL_BID);
int spreadInPips = (int)(spread / _Point);
// Check if spread is too high
if(spreadInPips > MaxSpread)
{
return;
}
// Get RSI values from bar data
double rsi[];
ArraySetAsSeries(rsi, true);
int copied = CopyBuffer(rsiHandle, 0, 0, 3, rsi);
if(copied < 3)
{
return;
}
// Update RSI values
rsiPrevious2 = rsiPrevious;
rsiPrevious = rsiCurrent;
rsiCurrent = rsi[0];
// Validate RSI values
if(rsiCurrent == 0 || rsiPrevious == 0)
{
return;
}
// Check for RSI crossovers
CheckRSICrossover();
// Get current prices
double currentBid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double currentAsk = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
// Get position status
string positionStatus = "None";
for(int i = 0; i < PositionsTotal(); i++)
{
if(PositionGetSymbol(i) == _Symbol)
{
ENUM_POSITION_TYPE posType = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
positionStatus = (posType == POSITION_TYPE_BUY) ? "Long" : "Short";
break;
}
}
// Calculate stop loss and take profit levels
double sl = 0;
double tp = 0;
// Prepare crossover info for panel
string crossInfo = "None";
if(rsiCrossedOverbought) crossInfo = "Overbought";
else if(rsiCrossedOversold) crossInfo = "Oversold";
else if(rsiCrossedExitLevel) crossInfo = "Exit";
// Update panel
UpdatePanel(rsiCurrent, positionStatus, spreadInPips, GetCurrentSession(), sl, tp, crossInfo);
// Check for open position
bool hasOpenPosition = false;
for(int i = 0; i < PositionsTotal(); i++)
{
if(PositionGetSymbol(i) == _Symbol)
{
hasOpenPosition = true;
// Get position details
double positionProfit = PositionGetDouble(POSITION_PROFIT);
double positionVolume = PositionGetDouble(POSITION_VOLUME);
double openPrice = PositionGetDouble(POSITION_PRICE_OPEN);
ENUM_POSITION_TYPE posType = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
// Check for RSI exit if enabled
if(UseRSIExit && rsiCrossedExitLevel)
{
bool shouldExit = false;
// For long positions, exit when RSI crosses above exit level
if(posType == POSITION_TYPE_BUY && rsiCurrent >= RSIExitLevel && rsiPrevious < RSIExitLevel)
{
shouldExit = true;
}
// For short positions, exit when RSI crosses below exit level
else if(posType == POSITION_TYPE_SELL && rsiCurrent <= RSIExitLevel && rsiPrevious > RSIExitLevel)
{
shouldExit = true;
}
if(shouldExit)
{
CloseAllTrades("RSI Exit Crossover");
return;
}
}
// Check for timeout
if(TimeCurrent() - positionOpenTime > MaxDuration * 3600)
{
CloseAllTrades("Timeout");
return;
}
break;
}
}
// If no position is open, look for entry signals based on RSI crossover
if(!hasOpenPosition)
{
// Place buy order if RSI crosses below oversold level (oversold crossover)
if(rsiCrossedOversold)
{
double sl = UseStopLoss ? currentBid - StopLossPips * _Point : 0;
double tp = UseTakeProfit ? currentBid + TakeProfitPips * _Point : 0;
if(UseStopLoss && sl >= currentBid)
return;
if(UseTakeProfit && tp <= currentBid)
return;
// Set trade parameters
trade.SetDeviationInPoints(3);
trade.SetTypeFilling(ORDER_FILLING_IOC);
trade.SetExpertMagicNumber(123456);
// Place buy order using CTrade
if(trade.Buy(MaxLotSize, _Symbol, currentAsk, sl, tp, "RSI Oversold Crossover Buy"))
{
isPositionOpen = true;
positionOpenPrice = currentAsk;
positionOpenTime = TimeCurrent();
lastPositionType = POSITION_TYPE_BUY;
}
}
// Place sell order if RSI crosses above overbought level (overbought crossover)
else if(rsiCrossedOverbought)
{
double sl = UseStopLoss ? currentAsk + StopLossPips * _Point : 0;
double tp = UseTakeProfit ? currentAsk - TakeProfitPips * _Point : 0;
if(UseStopLoss && sl <= currentAsk)
return;
if(UseTakeProfit && tp >= currentAsk)
return;
// Set trade parameters
trade.SetDeviationInPoints(3);
trade.SetTypeFilling(ORDER_FILLING_IOC);
trade.SetExpertMagicNumber(123456);
// Place sell order using CTrade
if(trade.Sell(MaxLotSize, _Symbol, currentBid, sl, tp, "RSI Overbought Crossover Sell"))
{
isPositionOpen = true;
positionOpenPrice = currentBid;
positionOpenTime = TimeCurrent();
lastPositionType = POSITION_TYPE_SELL;
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

@@ -5,34 +5,24 @@
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.02"
#property version "1.00"
#include <Trade\Trade.mqh>
#include "../_united/MagicNumberHelpers.mqh"
//--- Input parameters
input ENUM_TIMEFRAMES TimeFrame = PERIOD_H1; // Timeframe for Analysis
//--- Input parameters — synced with Desktop 123.set (2026.05.13)
input ENUM_TIMEFRAMES TimeFrame = PERIOD_M20; // Timeframe for Analysis
input int RSI_Period = 14; // RSI Period
input ENUM_APPLIED_PRICE RSI_Applied_Price = PRICE_CLOSE; // RSI Applied Price
input double RSI_Overbought = 71; // RSI Overbought Level
input double RSI_Oversold = 57; // RSI Oversold Level
input bool UseEntrySlopeFilter = false; // require RSI momentum on entry bars
input double EntryMinSlopePerBar = 1.0; // minimum RSI delta per bar for entry
input double RSI_Target_Buy = 80; // RSI Target for Buy Exit
input double RSI_Target_Sell = 57; // RSI Target for Sell Exit
input int BarsToWait = 4; // Bars to wait when RSI goes against position
input double LotSize = 0.1; // Lot Size
input double RSI_Overbought = 32; // RSI Overbought Level
input double RSI_Oversold = 86; // RSI Oversold Level
input double RSI_Target_Buy = 100; // RSI Target for Buy Exit
input double RSI_Target_Sell = 24; // RSI Target for Sell Exit
input int BarsToWait = 34; // Bars to wait when RSI goes against position
input double LotSize = 5; // Lot Size
input int MagicNumber = 129102315; // Magic Number
input int Slippage = 3; // Slippage in points
input group "=== Reversal escape (intrabar, multi-signal) ==="
input bool UseReversalEscape = true; // run while in position every tick
input int ReversalATRPeriod = 14; // ATR lookback on signal timeframe
input double ReversalAdverseAtrMult = 5.25; // close if price vs entry >= this * ATR
input int ReversalSignsRequired = 2; // how many independent signs must align
input double ReversalRsiVelocity = 16.0; // RSI points drop (long) / rise (short) vs prior buffer
input double ReversalBodyAtrMult = 5.1; // last closed bar body >= this * ATR counts as one sign
//--- Global variables
CTrade trade;
int rsi_handle;
@@ -82,32 +72,35 @@ void OnDeinit(const int reason)
//+------------------------------------------------------------------+
void OnTick()
{
// Check if we have enough bars
if(Bars(_Symbol, TimeFrame) < RSI_Period + 2)
{
return;
const datetime current_bar_time = iTime(_Symbol, TimeFrame, 0);
const bool new_bar = (current_bar_time != last_bar_time);
const bool in_pos = position_open || PositionExistsByMagic(_Symbol, (ulong)MagicNumber);
if(!in_pos && !new_bar)
return;
if(!UpdateRSI())
return;
if(in_pos && UseReversalEscape)
TryReversalEscape();
if(!new_bar)
return;
}
// Check if this is a new bar
datetime current_bar_time = iTime(_Symbol, TimeFrame, 0);
if(current_bar_time == last_bar_time)
{
return; // Still the same bar, don't process
}
last_bar_time = current_bar_time;
ResyncPositionFromMarket();
// Update RSI values
if(!UpdateRSI())
{
return;
}
// Check for existing position
CheckExistingPosition();
if(!position_open && !PositionExistsByMagic(_Symbol, (ulong)MagicNumber))
// Check for new entry signals - only if no position exists for THIS EA (magic number) on THIS symbol
if(!position_open && !PositionExistsByMagic(_Symbol, MagicNumber))
{
CheckEntrySignals();
}
}
//+------------------------------------------------------------------+
@@ -127,120 +120,6 @@ bool UpdateRSI()
return true;
}
//+------------------------------------------------------------------+
//| Wilder ATR in price units (signal timeframe) |
//+------------------------------------------------------------------+
double ATRPriceOnTF(const int period)
{
if(period < 1)
return 0.0;
MqlRates rates[];
const int need = period + 2;
if(CopyRates(_Symbol, TimeFrame, 0, need, rates) < need)
return 0.0;
ArraySetAsSeries(rates, true);
double sum = 0.0;
for(int i = 1; i <= period; i++)
{
const double hl = rates[i].high - rates[i].low;
const double hc = MathAbs(rates[i].high - rates[i + 1].close);
const double lc = MathAbs(rates[i].low - rates[i + 1].close);
sum += MathMax(hl, MathMax(hc, lc));
}
return sum / (double)period;
}
//+------------------------------------------------------------------+
//| Independent adverse signs (need ReversalSignsRequired to exit) |
//+------------------------------------------------------------------+
int CountReversalEscapeSigns(const ENUM_POSITION_TYPE ptype, const double atr)
{
if(atr <= 0.0)
return 0;
const double entry = PositionGetDouble(POSITION_PRICE_OPEN);
const double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
const double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
int signs = 0;
if(ptype == POSITION_TYPE_BUY)
{
if(entry - bid >= ReversalAdverseAtrMult * atr)
signs++;
if(rsi_prev - rsi_current >= ReversalRsiVelocity)
signs++;
}
else if(ptype == POSITION_TYPE_SELL)
{
if(ask - entry >= ReversalAdverseAtrMult * atr)
signs++;
if(rsi_current - rsi_prev >= ReversalRsiVelocity)
signs++;
}
else
return 0;
MqlRates r[];
if(CopyRates(_Symbol, TimeFrame, 0, 4, r) >= 4)
{
ArraySetAsSeries(r, true);
const double body = MathAbs(r[1].close - r[1].open);
if(body >= ReversalBodyAtrMult * atr)
{
if(ptype == POSITION_TYPE_BUY && r[1].close < r[1].open)
signs++;
else if(ptype == POSITION_TYPE_SELL && r[1].close > r[1].open)
signs++;
}
if(ptype == POSITION_TYPE_BUY)
{
if(r[1].close < r[2].close && r[2].close < r[3].close)
signs++;
}
else
{
if(r[1].close > r[2].close && r[2].close > r[3].close)
signs++;
}
}
return signs;
}
//+------------------------------------------------------------------+
//| Cut losers fast on violent reversals (evaluated every tick) |
//+------------------------------------------------------------------+
void TryReversalEscape()
{
if(!PositionSelectByMagic(_Symbol, (ulong)MagicNumber))
return;
const ENUM_POSITION_TYPE ptype = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
const double atr = ATRPriceOnTF(ReversalATRPeriod);
if(atr <= 0.0)
return;
const int n = CountReversalEscapeSigns(ptype, atr);
if(n < ReversalSignsRequired)
return;
ClosePosition();
Print("RSIScalpingXAUUSD: reversal escape signs=", n, " need=", ReversalSignsRequired,
" ATR=", DoubleToString(atr, (int)SymbolInfoInteger(_Symbol, SYMBOL_DIGITS)));
}
void ResyncPositionFromMarket()
{
if(position_open)
return;
ulong t = GetPositionTicketByMagic(_Symbol, (ulong)MagicNumber);
if(t == 0 || !PositionSelectByTicket(t))
return;
position_ticket = (int)t;
position_open = true;
current_position_type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
}
//+------------------------------------------------------------------+
//| Check existing position for exit conditions |
//+------------------------------------------------------------------+
@@ -251,8 +130,8 @@ void CheckExistingPosition()
return;
}
// Check if position still exists with correct magic number
if(!PositionSelectByTicketAndMagic(position_ticket, MagicNumber))
// Check if position still exists with correct magic number AND symbol for THIS EA
if(!PositionSelectByTicketSymbolAndMagic(position_ticket, _Symbol, MagicNumber))
{
position_open = false;
position_ticket = 0;
@@ -345,21 +224,14 @@ void CheckExistingPosition()
//+------------------------------------------------------------------+
void CheckEntrySignals()
{
const double upSlope1 = rsi_prev - rsi_two_bars_ago; // older->prev
const double upSlope2 = rsi_current - rsi_prev; // prev->current
const double dnSlope1 = rsi_two_bars_ago - rsi_prev; // older->prev
const double dnSlope2 = rsi_prev - rsi_current; // prev->current
const bool buySlopeOk = (!UseEntrySlopeFilter) || (upSlope1 >= EntryMinSlopePerBar && upSlope2 >= EntryMinSlopePerBar);
const bool sellSlopeOk = (!UseEntrySlopeFilter) || (dnSlope1 >= EntryMinSlopePerBar && dnSlope2 >= EntryMinSlopePerBar);
// Buy signal: RSI crosses from oversold to above oversold (checking the actual crossover)
if(rsi_two_bars_ago <= RSI_Oversold && rsi_prev > RSI_Oversold && buySlopeOk)
if(rsi_two_bars_ago <= RSI_Oversold && rsi_prev > RSI_Oversold)
{
OpenBuyPosition();
}
// Sell signal: RSI crosses from overbought to below overbought (checking the actual crossover)
if(rsi_two_bars_ago >= RSI_Overbought && rsi_prev < RSI_Overbought && sellSlopeOk)
if(rsi_two_bars_ago >= RSI_Overbought && rsi_prev < RSI_Overbought)
{
OpenSellPosition();
}
@@ -370,13 +242,31 @@ void CheckEntrySignals()
//+------------------------------------------------------------------+
void OpenBuyPosition()
{
// Verify no position exists for THIS EA (magic number) on THIS symbol before opening
if(PositionExistsByMagic(_Symbol, MagicNumber))
{
return; // Position already exists for this EA
}
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
if(trade.Buy(LotSize, _Symbol, ask, 0, 0, "RSI Scalping Buy"))
{
position_ticket = trade.ResultOrder();
position_open = true;
current_position_type = POSITION_TYPE_BUY;
ulong new_ticket = trade.ResultOrder();
if(new_ticket > 0)
{
// Verify position was opened for THIS EA (magic number) on THIS symbol
if(PositionSelectByTicketSymbolAndMagic(new_ticket, _Symbol, MagicNumber))
{
position_ticket = new_ticket;
position_open = true;
current_position_type = POSITION_TYPE_BUY;
}
else
{
Print("Error: Position opened but doesn't match EA magic number or symbol");
}
}
}
}
@@ -385,13 +275,31 @@ void OpenBuyPosition()
//+------------------------------------------------------------------+
void OpenSellPosition()
{
// Verify no position exists for THIS EA (magic number) on THIS symbol before opening
if(PositionExistsByMagic(_Symbol, MagicNumber))
{
return; // Position already exists for this EA
}
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
if(trade.Sell(LotSize, _Symbol, bid, 0, 0, "RSI Scalping Sell"))
{
position_ticket = trade.ResultOrder();
position_open = true;
current_position_type = POSITION_TYPE_SELL;
ulong new_ticket = trade.ResultOrder();
if(new_ticket > 0)
{
// Verify position was opened for THIS EA (magic number) on THIS symbol
if(PositionSelectByTicketSymbolAndMagic(new_ticket, _Symbol, MagicNumber))
{
position_ticket = new_ticket;
position_open = true;
current_position_type = POSITION_TYPE_SELL;
}
else
{
Print("Error: Position opened but doesn't match EA magic number or symbol");
}
}
}
}
@@ -400,22 +308,20 @@ void OpenSellPosition()
//+------------------------------------------------------------------+
void ClosePosition()
{
if(ClosePositionByMagic(trade, _Symbol, (ulong)MagicNumber))
// Close position using helper that verifies symbol AND magic number for THIS EA
if(ClosePositionByMagic(trade, _Symbol, MagicNumber))
{
position_open = false;
position_ticket = 0;
rsi_against_position = false;
bars_against_count = 0;
return;
}
if(!PositionExistsByMagic(_Symbol, (ulong)MagicNumber))
else
{
// Position doesn't exist or wrong magic number - reset tracking
position_open = false;
position_ticket = 0;
rsi_against_position = false;
bars_against_count = 0;
return;
}
Print("RSIScalpingXAUUSD: close failed (will retry on next bar). retcode=",
trade.ResultRetcode(), " lastError=", GetLastError());
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

+10 -10
View File
@@ -10,17 +10,17 @@
#include <Trade\Trade.mqh>
#include "../_united/MagicNumberHelpers.mqh"
//--- Input parameters
input ENUM_TIMEFRAMES TimeFrame = PERIOD_M15; // Timeframe for Analysis
input int RSI_Period = 8; // RSI Period
//--- Input parameters — synced with Desktop 123.set (2026.05.13)
input ENUM_TIMEFRAMES TimeFrame = PERIOD_M20; // Timeframe for Analysis
input int RSI_Period = 14; // RSI Period
input ENUM_APPLIED_PRICE RSI_Applied_Price = PRICE_CLOSE; // RSI Applied Price
input double RSI_Overbought = 36; // RSI Overbought Level
input double RSI_Oversold = 38; // RSI Oversold Level
input double RSI_Target_Buy = 90; // RSI Target for Buy Exit
input double RSI_Target_Sell = 70; // RSI Target for Sell Exit
input int BarsToWait = 5; // Bars to wait when RSI goes against position
input double LotSize = 50; // Lot Size
input int MagicNumber = 12345; // Magic Number
input double RSI_Overbought = 6; // RSI Overbought Level
input double RSI_Oversold = 66; // RSI Oversold Level
input double RSI_Target_Buy = 98; // RSI Target for Buy Exit
input double RSI_Target_Sell = 52; // RSI Target for Sell Exit
input int BarsToWait = 12; // Bars to wait when RSI goes against position
input double LotSize = 5; // Lot Size
input int MagicNumber = 129102315; // Magic Number
input int Slippage = 3; // Slippage in points
//--- Global variables
+9 -9
View File
@@ -10,17 +10,17 @@
#include <Trade\Trade.mqh>
#include "../_united/MagicNumberHelpers.mqh"
//--- Input parameters
input ENUM_TIMEFRAMES TimeFrame = PERIOD_H1; // Timeframe for Analysis
//--- Input parameters — synced with Desktop 123.set (2026.05.13)
input ENUM_TIMEFRAMES TimeFrame = PERIOD_M20; // Timeframe for Analysis
input int RSI_Period = 14; // RSI Period
input ENUM_APPLIED_PRICE RSI_Applied_Price = PRICE_CLOSE; // RSI Applied Price
input double RSI_Overbought = 54; // RSI Overbought Level
input double RSI_Oversold = 73; // RSI Oversold Level
input double RSI_Target_Buy = 87; // RSI Target for Buy Exit
input double RSI_Target_Sell = 33; // RSI Target for Sell Exit
input int BarsToWait = 1; // Bars to wait when RSI goes against position
input double LotSize = 50; // Lot Size
input int MagicNumber = 125421321; // Magic Number
input double RSI_Overbought = 32; // RSI Overbought Level
input double RSI_Oversold = 86; // RSI Oversold Level
input double RSI_Target_Buy = 100; // RSI Target for Buy Exit
input double RSI_Target_Sell = 24; // RSI Target for Sell Exit
input int BarsToWait = 34; // Bars to wait when RSI goes against position
input double LotSize = 5; // Lot Size
input int MagicNumber = 129102315; // Magic Number
input int Slippage = 3; // Slippage in points
//--- Global variables
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

@@ -1,36 +0,0 @@
; SuperEMA — defaults aligned with lab/EAs/SuperEMA.mq5 (v1.01)
; Load from Strategy Tester → Inputs → context menu → Load
;
; === Market ===
InpSymbol=
InpTimeframe=15||15||0||49153||N
InpLots=0.01||0.01||0.01||0.10||N
InpSlippagePoints=55||20||5||120||Y
InpMagic=940001||940001||1||9400010||N
; === EMA (trend & structure) ===
InpEmaFast=40||20||10||120||Y
InpEmaMid=180||60||15||200||Y
InpEmaSlow=125||100||25||400||Y
InpEmaTrendBars=3||1||1||3||Y
; === CCI ===
InpCciPeriod=17||7||1||28||Y
InpCciOverbought=80.0||80.0||10.0||140.0||Y
InpCciOversold=-140.0||-140.0||10.0||-80.0||Y
InpPullbackCciLookback=20||4||2||24||Y
; === MACD (histogram = main - signal) ===
InpMacdFast=14||8||2||20||Y
InpMacdSlow=38||20||2||40||Y
InpMacdSignal=9||5||1||15||Y
; === Strategy ===
InpEntryStyle=1||0||1||2||Y
InpOneTradeOnly=true||false||0||true||N
InpUseStructuralSL=false||false||0||true||Y
InpSlBufferPoints=110.0||20.0||10.0||200.0||Y
; === Exits (so trades do not run forever) ===
InpExitOnTrendFlip=false||false||0||true||Y
InpExitOnMacdFlip=false||false||0||true||Y
InpExitOnCciZeroCross=true||false||0||true||Y
InpMaxHoldingBars=168||48||24||480||Y
InpExitBelowMidEma=false||false||0||true||Y
; === Debug ===
InpDebugLogs=false||false||0||true||N
-448
View File
@@ -1,448 +0,0 @@
//+------------------------------------------------------------------+
//| SuperEMA.mq5 |
//| EMA + CCI + MACD histogram — trend filter, momentum confirmation |
//+------------------------------------------------------------------+
#property strict
#property version "1.01"
#include <Trade/Trade.mqh>
enum ENUM_ENTRY_STYLE
{
ENTRY_CCIZERO_MACD = 0, // EMA trend + CCI crosses zero + MACD histogram agrees
ENTRY_LAMBERT = 1, // EMA trend + CCI crosses ±100 + MACD histogram agrees
ENTRY_PULLBACK = 2 // Uptrend: pullback to fast EMA + CCI was oversold + CCI crosses up through 0 + MACD > 0 (mirror for sells)
};
input group "=== Market ==="
input string InpSymbol = "";
input ENUM_TIMEFRAMES InpTimeframe = PERIOD_M15;
input double InpLots = 0.01;
input int InpSlippagePoints = 55;
input int InpMagic = 940001;
input group "=== EMA (trend & structure) ==="
input int InpEmaFast = 40;
input int InpEmaMid = 180;
input int InpEmaSlow = 125;
input int InpEmaTrendBars = 3; // closed bar shift for EMA reads
input group "=== CCI ==="
input int InpCciPeriod = 17;
input double InpCciOverbought = 80.0;
input double InpCciOversold = -140.0;
input int InpPullbackCciLookback = 20; // bars to check prior CCI oversold/overbought
input group "=== MACD (histogram = main - signal) ==="
input int InpMacdFast = 14;
input int InpMacdSlow = 38;
input int InpMacdSignal = 9;
input group "=== Strategy ==="
input ENUM_ENTRY_STYLE InpEntryStyle = ENTRY_LAMBERT;
input bool InpOneTradeOnly = true;
input bool InpUseStructuralSL = false;
input double InpSlBufferPoints = 110;
input group "=== Exits (so trades do not run forever) ==="
input bool InpExitOnTrendFlip = false; // close when price vs slow EMA flips against position
input bool InpExitOnMacdFlip = false; // close when MACD histogram flips against position
input bool InpExitOnCciZeroCross = true; // long: CCI crosses below 0; short: CCI crosses above 0
input int InpMaxHoldingBars = 168; // 0 = disabled (e.g. ~8 days M15)
input bool InpExitBelowMidEma = false; // long: close if close < mid EMA (invalidation)
input group "=== Debug ==="
input bool InpDebugLogs = false;
CTrade trade;
datetime g_lastBarTime = 0;
string WorkSymbol()
{
return (InpSymbol == "" || InpSymbol == NULL) ? _Symbol : InpSymbol;
}
void Log(const string s)
{
if(InpDebugLogs)
Print("[SuperEMA] ", s);
}
bool IsNewBar(const string sym, const ENUM_TIMEFRAMES tf)
{
datetime t = iTime(sym, tf, 0);
if(t <= 0 || t == g_lastBarTime)
return false;
g_lastBarTime = t;
return true;
}
double EmaAt(const string sym, const ENUM_TIMEFRAMES tf, const int period, const int shift)
{
int h = iMA(sym, tf, period, 0, MODE_EMA, PRICE_CLOSE);
if(h == INVALID_HANDLE)
return 0.0;
double b[1];
if(CopyBuffer(h, 0, shift, 1, b) <= 0)
{
IndicatorRelease(h);
return 0.0;
}
IndicatorRelease(h);
return b[0];
}
double CciAt(const string sym, const ENUM_TIMEFRAMES tf, const int period, const int shift)
{
int h = iCCI(sym, tf, period, PRICE_TYPICAL);
if(h == INVALID_HANDLE)
return 0.0;
double b[1];
if(CopyBuffer(h, 0, shift, 1, b) <= 0)
{
IndicatorRelease(h);
return 0.0;
}
IndicatorRelease(h);
return b[0];
}
bool MacdHistAt(const string sym, const ENUM_TIMEFRAMES tf, const int fast, const int slow, const int signal, const int shift, double &hist)
{
int h = iMACD(sym, tf, fast, slow, signal, PRICE_CLOSE);
if(h == INVALID_HANDLE)
return false;
double mainLine[1], sigLine[1];
if(CopyBuffer(h, 0, shift, 1, mainLine) <= 0 || CopyBuffer(h, 1, shift, 1, sigLine) <= 0)
{
IndicatorRelease(h);
return false;
}
IndicatorRelease(h);
hist = mainLine[0] - sigLine[0];
return true;
}
bool TrendUp(const string sym, const int sh)
{
double c = iClose(sym, InpTimeframe, sh);
double emaS = EmaAt(sym, InpTimeframe, InpEmaSlow, sh);
return (emaS > 0.0 && c > emaS);
}
bool TrendDown(const string sym, const int sh)
{
double c = iClose(sym, InpTimeframe, sh);
double emaS = EmaAt(sym, InpTimeframe, InpEmaSlow, sh);
return (emaS > 0.0 && c < emaS);
}
bool CciCrossAboveZero(const string sym)
{
double c1 = CciAt(sym, InpTimeframe, InpCciPeriod, 1);
double c2 = CciAt(sym, InpTimeframe, InpCciPeriod, 2);
return (c2 <= 0.0 && c1 > 0.0);
}
bool CciCrossBelowZero(const string sym)
{
double c1 = CciAt(sym, InpTimeframe, InpCciPeriod, 1);
double c2 = CciAt(sym, InpTimeframe, InpCciPeriod, 2);
return (c2 >= 0.0 && c1 < 0.0);
}
bool CciCrossAbove100(const string sym)
{
double c1 = CciAt(sym, InpTimeframe, InpCciPeriod, 1);
double c2 = CciAt(sym, InpTimeframe, InpCciPeriod, 2);
return (c2 < InpCciOverbought && c1 > InpCciOverbought);
}
bool CciCrossBelowMinus100(const string sym)
{
double c1 = CciAt(sym, InpTimeframe, InpCciPeriod, 1);
double c2 = CciAt(sym, InpTimeframe, InpCciPeriod, 2);
return (c2 > InpCciOversold && c1 < InpCciOversold);
}
bool HadCciOversoldRecently(const string sym)
{
for(int i = 2; i <= InpPullbackCciLookback + 1; i++)
{
double v = CciAt(sym, InpTimeframe, InpCciPeriod, i);
if(v <= InpCciOversold)
return true;
}
return false;
}
bool HadCciOverboughtRecently(const string sym)
{
for(int i = 2; i <= InpPullbackCciLookback + 1; i++)
{
double v = CciAt(sym, InpTimeframe, InpCciPeriod, i);
if(v >= InpCciOverbought)
return true;
}
return false;
}
bool PullbackNearFastEmaLong(const string sym)
{
double emaF = EmaAt(sym, InpTimeframe, InpEmaFast, 1);
double lo = iLow(sym, InpTimeframe, 1);
if(emaF <= 0.0)
return false;
return (lo <= emaF + InpSlBufferPoints * _Point * 3.0);
}
bool PullbackNearFastEmaShort(const string sym)
{
double emaF = EmaAt(sym, InpTimeframe, InpEmaFast, 1);
double hi = iHigh(sym, InpTimeframe, 1);
if(emaF <= 0.0)
return false;
return (hi >= emaF - InpSlBufferPoints * _Point * 3.0);
}
int PositionsByMagic(const string sym, const int magic)
{
int n = 0;
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong t = PositionGetTicket(i);
if(t == 0)
continue;
if(PositionGetString(POSITION_SYMBOL) == sym && (int)PositionGetInteger(POSITION_MAGIC) == magic)
n++;
}
return n;
}
void ComputeSLTP(const bool isBuy, const double entry, double &sl, double &tp)
{
const string sym = WorkSymbol();
sl = 0.0;
tp = 0.0;
if(!InpUseStructuralSL)
return;
double emaM = EmaAt(sym, InpTimeframe, InpEmaMid, InpEmaTrendBars);
double buf = InpSlBufferPoints * _Point;
if(isBuy)
sl = emaM - buf;
else
sl = emaM + buf;
}
int BarsSinceOpen(const string sym, const datetime openTime)
{
if(openTime <= 0)
return 0;
int sh = iBarShift(sym, InpTimeframe, openTime, false);
if(sh < 0)
return 999999;
return sh;
}
void ClosePositionTicket(const ulong ticket, const string reason)
{
trade.SetExpertMagicNumber(InpMagic);
if(trade.PositionClose(ticket))
Log("Close: " + reason);
}
void ManageSuperEMAExits(const string sym)
{
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong ticket = PositionGetTicket(i);
if(ticket == 0)
continue;
if(!PositionSelectByTicket(ticket))
continue;
if(PositionGetString(POSITION_SYMBOL) != sym)
continue;
if((int)PositionGetInteger(POSITION_MAGIC) != InpMagic)
continue;
ENUM_POSITION_TYPE ptype = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
datetime openTime = (datetime)PositionGetInteger(POSITION_TIME);
double h1 = 0.0;
if(!MacdHistAt(sym, InpTimeframe, InpMacdFast, InpMacdSlow, InpMacdSignal, 1, h1))
continue;
bool closeLong = false;
bool closeShort = false;
string reason = "";
if(InpMaxHoldingBars > 0)
{
int held = BarsSinceOpen(sym, openTime);
if(held >= InpMaxHoldingBars)
{
if(ptype == POSITION_TYPE_BUY)
closeLong = true;
else
closeShort = true;
reason = "time stop (max bars)";
}
}
if(ptype == POSITION_TYPE_BUY)
{
if(InpExitOnTrendFlip && TrendDown(sym, InpEmaTrendBars))
{
closeLong = true;
reason = "trend flip (below slow EMA)";
}
if(InpExitOnMacdFlip && h1 < 0.0)
{
closeLong = true;
reason = "MACD histogram < 0";
}
if(InpExitOnCciZeroCross && CciCrossBelowZero(sym))
{
closeLong = true;
reason = "CCI crossed below zero";
}
if(InpExitBelowMidEma)
{
double c = iClose(sym, InpTimeframe, 1);
double emaM = EmaAt(sym, InpTimeframe, InpEmaMid, 1);
if(emaM > 0.0 && c < emaM)
{
closeLong = true;
reason = "close below mid EMA";
}
}
if(closeLong)
ClosePositionTicket(ticket, reason);
}
else if(ptype == POSITION_TYPE_SELL)
{
if(InpExitOnTrendFlip && TrendUp(sym, InpEmaTrendBars))
{
closeShort = true;
reason = "trend flip (above slow EMA)";
}
if(InpExitOnMacdFlip && h1 > 0.0)
{
closeShort = true;
reason = "MACD histogram > 0";
}
if(InpExitOnCciZeroCross && CciCrossAboveZero(sym))
{
closeShort = true;
reason = "CCI crossed above zero";
}
if(InpExitBelowMidEma)
{
double c = iClose(sym, InpTimeframe, 1);
double emaM = EmaAt(sym, InpTimeframe, InpEmaMid, 1);
if(emaM > 0.0 && c > emaM)
{
closeShort = true;
reason = "close above mid EMA";
}
}
if(closeShort)
ClosePositionTicket(ticket, reason);
}
}
}
int OnInit()
{
string sym = WorkSymbol();
if(!SymbolSelect(sym, true))
{
Print("SuperEMA: cannot select symbol ", sym);
return INIT_FAILED;
}
trade.SetExpertMagicNumber(InpMagic);
trade.SetDeviationInPoints(InpSlippagePoints);
return INIT_SUCCEEDED;
}
void OnTick()
{
string sym = WorkSymbol();
if(_Symbol != sym)
{
static datetime lastLog = 0;
datetime tb = iTime(_Symbol, PERIOD_M1, 0);
if(tb != lastLog && InpDebugLogs)
{
lastLog = tb;
Log("Chart symbol differs from WorkSymbol; attach to " + sym + " or set InpSymbol empty.");
}
return;
}
if(!IsNewBar(sym, InpTimeframe))
return;
// Exits must run every bar; do not skip when a position exists (otherwise trades never close with SL=0/TP=0).
ManageSuperEMAExits(sym);
if(InpOneTradeOnly && PositionsByMagic(sym, InpMagic) > 0)
return;
const int sh = InpEmaTrendBars;
double h1 = 0.0, h2 = 0.0;
if(!MacdHistAt(sym, InpTimeframe, InpMacdFast, InpMacdSlow, InpMacdSignal, 1, h1) ||
!MacdHistAt(sym, InpTimeframe, InpMacdFast, InpMacdSlow, InpMacdSignal, 2, h2))
return;
bool up = TrendUp(sym, sh);
bool dn = TrendDown(sym, sh);
bool wantBuy = false;
bool wantSell = false;
switch(InpEntryStyle)
{
case ENTRY_CCIZERO_MACD:
if(up && CciCrossAboveZero(sym) && h1 > 0.0)
wantBuy = true;
if(dn && CciCrossBelowZero(sym) && h1 < 0.0)
wantSell = true;
break;
case ENTRY_LAMBERT:
if(up && CciCrossAbove100(sym) && h1 > 0.0)
wantBuy = true;
if(dn && CciCrossBelowMinus100(sym) && h1 < 0.0)
wantSell = true;
break;
case ENTRY_PULLBACK:
if(up && HadCciOversoldRecently(sym) && CciCrossAboveZero(sym) && h1 > 0.0 && PullbackNearFastEmaLong(sym))
wantBuy = true;
if(dn && HadCciOverboughtRecently(sym) && CciCrossBelowZero(sym) && h1 < 0.0 && PullbackNearFastEmaShort(sym))
wantSell = true;
break;
}
MqlTick tick;
if(!SymbolInfoTick(sym, tick))
return;
double sl = 0.0, tp = 0.0;
if(wantBuy && !wantSell)
{
ComputeSLTP(true, tick.ask, sl, tp);
if(trade.Buy(InpLots, sym, tick.ask, sl, tp, "SuperEMA long"))
Log(StringFormat("BUY ask=%.5f sl=%.5f cci=%.2f macdHist=%.5f", tick.ask, sl,
CciAt(sym, InpTimeframe, InpCciPeriod, 1), h1));
}
else if(wantSell && !wantBuy)
{
ComputeSLTP(false, tick.bid, sl, tp);
if(trade.Sell(InpLots, sym, tick.bid, sl, tp, "SuperEMA short"))
Log(StringFormat("SELL bid=%.5f sl=%.5f cci=%.2f macdHist=%.5f", tick.bid, sl,
CciAt(sym, InpTimeframe, InpCciPeriod, 1), h1));
}
}