Summary: EURUSD TriCore EA is an MQL4 expert advisor for EURUSD that integrates EMA trend, stochastic oscillator and candlestick confirmation. Designed for stable, low-risk operation on H1.




EURUSD TriCore EA integrates three complementary logics: trend following (EMA), momentum/mean reversion (Stochastic) and price action confirmation (candlestick patterns). The EA only enters trades when all three conditions align, reducing false signals. It includes ATR-based volatility filtering, daily loss limit, spread control and Friday close protection. The strategy aims for steady, compounding growth rather than high-frequency trading.

Recommended Timeframe: H1
Trading Logic:
1. Trend Filter: EMA(50) determines direction (price above = long only, below = short only).
2. Stochastic Filter: Stochastic(14,3,3) must be below 20 for long (oversold) or above 80 for short (overbought).
3. Candlestick Confirmation: Bullish engulfing or hammer for long; bearish engulfing or shooting star for short.
4. Risk Management: Fixed stop loss (250 points), take profit (450 points). Maximum 1 trade at a time, daily loss limit 5%, max spread 25 points.

```mql4
//+------------------------------------------------------------------+
//| EURUSDTriCoreEA.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)
input int StopLossPoints = 250; // Stop loss in points (25 pips)
input int TakeProfitPoints = 450; // Take profit in points (45 pips)
input int TrendMAPeriod = 50; // EMA period for trend filter
input int StochK = 14; // Stochastic %K period
input int StochD = 3; // Stochastic %D period
input int StochSlowing = 3; // Stochastic slowing
input int StochOversold = 20; // Stochastic oversold level (buy zone)
input int StochOverbought = 80; // Stochastic overbought level (sell zone)
input int ATRPeriod = 14; // ATR period for volatility filter
input double MaxATRMultiplier = 1.8; // Max ATR multiplier (skip if ATR > avgATR * this)
input int MagicNumber = 202416; // Unique EA identifier
input int MaxSpread = 25; // Maximum allowed spread in points
input double DailyLossLimit = 5.0; // Daily loss limit as percentage of balance
input bool UseFridayClose = true; // Close trades before Friday 21:00 GMT

//--- global variables
double dailyStartBalance = 0;
datetime lastBarTime = 0;
bool fridayCloseExecuted = false;
double avgATR = 0;

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
dailyStartBalance = AccountBalance();
lastBarTime = 0;
fridayCloseExecuted = false;
avgATR = iATR(Symbol(), PERIOD_H1, ATRPeriod, 1);
if(avgATR <= 0) avgATR = 120 * Point;
return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}

//+------------------------------------------------------------------+
//| Check bullish candlestick pattern |
//+------------------------------------------------------------------+
bool IsBullishCandle()
{
double open = iOpen(Symbol(), PERIOD_H1, 1);
double close = iClose(Symbol(), PERIOD_H1, 1);
double high = iHigh(Symbol(), PERIOD_H1, 1);
double low = iLow(Symbol(), PERIOD_H1, 1);
double body = close - open;
double upperShadow = high - close;
double lowerShadow = open - low;

// Bullish engulfing (previous candle bearish, current bullish and covers previous)
double prevOpen = iOpen(Symbol(), PERIOD_H1, 2);
double prevClose = iClose(Symbol(), PERIOD_H1, 2);
bool engulfing = (prevClose < prevOpen) && (close > open) && (close > prevOpen) && (open < prevClose);

// Hammer: long lower shadow, small upper shadow, body near top
bool hammer = (lowerShadow > 2 * body) && (upperShadow < body) && (body > 0);

return (engulfing || hammer);
}

//+------------------------------------------------------------------+
//| Check bearish candlestick pattern |
//+------------------------------------------------------------------+
bool IsBearishCandle()
{
double open = iOpen(Symbol(), PERIOD_H1, 1);
double close = iClose(Symbol(), PERIOD_H1, 1);
double high = iHigh(Symbol(), PERIOD_H1, 1);
double low = iLow(Symbol(), PERIOD_H1, 1);
double body = open - close;
double upperShadow = high - open;
double lowerShadow = close - low;

// Bearish engulfing (previous candle bullish, current bearish and covers previous)
double prevOpen = iOpen(Symbol(), PERIOD_H1, 2);
double prevClose = iClose(Symbol(), PERIOD_H1, 2);
bool engulfing = (prevClose > prevOpen) && (close < open) && (close < prevOpen) && (open > prevClose);

// Shooting star: long upper shadow, small lower shadow, body near bottom
bool shootingStar = (upperShadow > 2 * body) && (lowerShadow < body) && (body > 0);

return (engulfing || shootingStar);
}

//+------------------------------------------------------------------+
//| 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(UseFridayClose && !fridayCloseExecuted)
{
datetime currentTime = TimeCurrent();
if(TimeDayOfWeek(currentTime) == 5 && TimeHour(currentTime) >= 21)
{
CloseAllOrders();
fridayCloseExecuted = true;
return;
}
if(TimeDayOfWeek(currentTime) != 5)
fridayCloseExecuted = false;
}

// Spread filter
if(MarketInfo(Symbol(), MODE_SPREAD) > MaxSpread)
{
Comment("Spread too high: ", MarketInfo(Symbol(), MODE_SPREAD));
return;
}

// New bar logic (H1)
if(Time[0] == lastBarTime)
return;
lastBarTime = Time[0];

// Check existing position
if(CountPositions() > 0)
return;

// Calculate indicators
double ema = iMA(Symbol(), PERIOD_H1, TrendMAPeriod, 0, MODE_EMA, PRICE_CLOSE, 1);
double close1 = iClose(Symbol(), PERIOD_H1, 1);
double stochMain = iStochastic(Symbol(), PERIOD_H1, StochK, StochD, StochSlowing, MODE_SMA, 0, MODE_MAIN, 1);
double atr = iATR(Symbol(), PERIOD_H1, ATRPeriod, 1);

// Update average ATR for volatility filter
if(atr > 0) avgATR = (avgATR * 0.95) + (atr * 0.05);

// Volatility filter: skip if current ATR is too high
if(atr > avgATR * MaxATRMultiplier && avgATR > 0)
{
Comment("Volatility too high. ATR: ", atr);
return;
}

int cmd = -1;
double sl = 0, tp = 0;
double ask = Ask;
double bid = Bid;

// Long condition: price above EMA, Stochastic oversold, bullish candlestick
if(close1 > ema && stochMain < StochOversold && IsBullishCandle())
{
cmd = OP_BUY;
sl = bid - StopLossPoints * Point;
tp = bid + TakeProfitPoints * Point;
}
// Short condition: price below EMA, Stochastic overbought, bearish candlestick
else if(close1 < ema && stochMain > StochOverbought && IsBearishCandle())
{
cmd = OP_SELL;
sl = ask + StopLossPoints * Point;
tp = ask - TakeProfitPoints * Point;
}

if(cmd != -1)
{
int ticket = OrderSend(Symbol(), cmd, LotSize, (cmd==OP_BUY?ask:bid), 3, sl, tp, "EURUSD TriCore", 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 substantial risk. This EA is provided as-is without any guarantee of profit. Test thoroughly on a demo account before live trading. Past performance does not guarantee future results.