Summary: EURUSD Stable Trader EA is a low-risk MQL4 expert advisor for EURUSD. It uses RSI mean reversion, ATR volatility filter, and fixed stop loss/take profit. Suitable for H1 timeframe.
EURUSD Stable Trader EA is designed specifically for EURUSD with a low-risk, stable operational approach. It incorporates mean reversion logic based on RSI, volatility-based entry filtering using ATR, and strict money management. The EA trades only when RSI exits overbought/oversold zones and ATR confirms normal volatility levels. Each trade has a fixed stop loss and take profit, with daily equity protection and maximum spread control.
Recommended Timeframe: H1
Trading Logic:
1. Trend Context: 200 EMA as long-term filter (optional bias, but not mandatory for entry).
2. Entry Signal: RSI(14) crosses above 30 (buy) or below 70 (sell) after being in oversold/overbought zone.
3. Volatility Guard: ATR(14) value must be within normal range (not extremely high).
4. Risk Control: Fixed SL (200 points) and TP (400 points), max 1 trade at a time, daily loss limit 5%, maximum spread 25 points.
```mql4
//+------------------------------------------------------------------+
//| EURUSDStableEA.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property version "1.00"
#property strict
//--- input parameters with comments
input double LotSize = 0.01; // Fixed lot size (0.01 lot for EURUSD)
input int StopLossPoints = 200; // Stop loss in points (200 points = 20 pips)
input int TakeProfitPoints = 400; // Take profit in points (2:1 risk-reward)
input int RSIPeriod = 14; // Period for RSI indicator
input int RSIOversold = 30; // RSI oversold level (buy signal)
input int RSIOverbought = 70; // RSI overbought level (sell signal)
input int ATRPeriod = 14; // Period for ATR volatility indicator
input double ATRMaxMultiplier = 1.5; // Maximum ATR multiplier (filter high volatility)
input int MagicNumber = 202412; // Unique EA identifier
input int MaxSpread = 25; // Maximum allowed spread (in points)
input double DailyLossLimit = 5.0; // Daily loss limit in percentage of balance
input bool UseCloseOnFriday = true; // Close all trades before Friday 21:00
//--- global variables
double dailyStartBalance = 0;
datetime lastBarTime = 0;
bool isFridayCloseExecuted = false;
double avgATR = 0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
dailyStartBalance = AccountBalance();
lastBarTime = 0;
isFridayCloseExecuted = false;
avgATR = iATR(Symbol(), PERIOD_H1, ATRPeriod, 1);
if(avgATR <= 0) avgATR = 50;
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Daily equity protection
double currentEquity = AccountEquity();
double lossPercent = (dailyStartBalance - currentEquity) / dailyStartBalance * 100;
if(lossPercent >= DailyLossLimit)
{
Comment("Daily loss limit reached. No new trades.");
return;
}
// Friday close before weekend
if(UseCloseOnFriday && !isFridayCloseExecuted)
{
datetime currentTime = TimeCurrent();
if(TimeDayOfWeek(currentTime) == 5 && TimeHour(currentTime) >= 21)
{
CloseAllOrders();
isFridayCloseExecuted = true;
return;
}
if(TimeDayOfWeek(currentTime) != 5)
isFridayCloseExecuted = false;
}
// Spread filter
if(MarketInfo(Symbol(), MODE_SPREAD) > MaxSpread)
{
Comment("Spread too high");
return;
}
// New bar logic (H1)
if(Time[0] == lastBarTime)
return;
lastBarTime = Time[0];
// Check for existing position
if(CountPositions() > 0)
return;
// Get RSI value on previous closed bar
double rsi = iRSI(Symbol(), PERIOD_H1, RSIPeriod, PRICE_CLOSE, 1);
double rsi_prev = iRSI(Symbol(), PERIOD_H1, RSIPeriod, PRICE_CLOSE, 2);
// Get ATR for volatility filter
double atr = iATR(Symbol(), PERIOD_H1, ATRPeriod, 1);
double atrThreshold = avgATR * ATRMaxMultiplier;
if(atr > atrThreshold && atrThreshold > 0)
{
Comment("Volatility too high, no trade. ATR: ", atr);
return;
}
// Update rolling average ATR
avgATR = (avgATR * 0.9) + (atr * 0.1);
int cmd = -1;
double sl = 0, tp = 0;
// Buy signal: RSI crosses above oversold level from below
if(rsi_prev <= RSIOversold && rsi > RSIOversold)
{
cmd = OP_BUY;
sl = SymbolInfoDouble(Symbol(), SYMBOL_BID) - StopLossPoints * Point;
tp = SymbolInfoDouble(Symbol(), SYMBOL_BID) + TakeProfitPoints * Point;
}
// Sell signal: RSI crosses below overbought level from above
else if(rsi_prev >= RSIOverbought && rsi < RSIOverbought)
{
cmd = OP_SELL;
sl = SymbolInfoDouble(Symbol(), SYMBOL_ASK) + StopLossPoints * Point;
tp = SymbolInfoDouble(Symbol(), SYMBOL_ASK) - TakeProfitPoints * Point;
}
if(cmd != -1)
{
int ticket = OrderSend(Symbol(), cmd, LotSize, (cmd==OP_BUY?Ask:Bid), 3, sl, tp, "EURUSD Stable EA", MagicNumber, 0, clrNONE);
if(ticket < 0)
Print("OrderSend failed: ", GetLastError());
}
}
//+------------------------------------------------------------------+
//| Count open positions with this MagicNumber |
//+------------------------------------------------------------------+
int CountPositions()
{
int count = 0;
for(int i = OrdersTotal()-1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
count++;
}
}
return count;
}
//+------------------------------------------------------------------+
//| Close all orders for this symbol and magic |
//+------------------------------------------------------------------+
void CloseAllOrders()
{
for(int i = OrdersTotal()-1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
if(OrderType() == OP_BUY)
OrderClose(OrderTicket(), OrderLots(), Bid, 3, clrNONE);
else if(OrderType() == OP_SELL)
OrderClose(OrderTicket(), OrderLots(), Ask, 3, clrNONE);
}
}
}
}
//+------------------------------------------------------------------+
```
Reference: Original MQL4 code for educational purposes.
Disclaimer: Trading Forex involves high risk. This EA is provided as-is without any guarantee of profit. Test thoroughly on demo before live trading. Past performance does not guarantee future results.