Virtual stop-loss (invisible to the broker)
Keeps the exit level in memory and closes at market when it's crossed — the SL never appears on the server. Reserve it for cases where the EA runs 24/7 on a VPS.
Prerequisites
MetaTrader 5, CTrade, VPS recommandé
MQL5
struct VirtualStop { ulong ticket; double slPrice; };
VirtualStop g_vstops[];
void CheckVirtualStops()
{
for(int i = ArraySize(g_vstops) - 1; i >= 0; i--)
{
if(!PositionSelectByTicket(g_vstops[i].ticket))
{
ArrayRemove(g_vstops, i, 1); // position déjà fermée
continue;
}
long type = PositionGetInteger(POSITION_TYPE);
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
bool hit = (type == POSITION_TYPE_BUY && bid <= g_vstops[i].slPrice)
|| (type == POSITION_TYPE_SELL && ask >= g_vstops[i].slPrice);
if(hit && trade.PositionClose(g_vstops[i].ticket))
ArrayRemove(g_vstops, i, 1);
}
}Result
2026.06.10 13:11:42.310 VStop (XAUUSD,M5) SL virtuel armé : #812448450 BUY @ 2378.50 (invisible serveur) 2026.06.10 13:26:08.774 VStop (XAUUSD,M5) bid 2378.45 <= 2378.50 : niveau virtuel franchi 2026.06.10 13:26:08.841 VStop (XAUUSD,M5) PositionClose #812448450 exécutée @ 2378.41 : P&L -38.20 USD 2026.06.10 13:26:08.842 VStop (XAUUSD,M5) Stop retiré de la liste (1 SL virtuel restant)
SL VirtuelStop HuntingCTradeVPS