mql5
//+------------------------------------------------------------------+
//| ICT_EA.mq5 |
//| ICT Unicorn Strategy (Simplified v1.00) |
//+------------------------------------------------------------------+
#property strict
#include <Trade\Trade.mqh>
CTrade trade;
//+------------------------------------------------------------------+
//| Input parameters |
//+------------------------------------------------------------------+
input int swingLength = 10;
input double RiskUSD = 1000; // Risk per trade in USD
input double MaxLots = 1.0; // Max lots
input double RRRatio = 2.0; // Reward:RISK (e.g., 2.0)
input double ATRMultiplier = 0.5; // FVG size (relative to ATR)
input bool EnableBull = true;
input bool EnableBear = true;
//+------------------------------------------------------------------+
//| Global Variables |
//+------------------------------------------------------------------+
datetime lastBarTime = 0;
//+------------------------------------------------------------------+
//| Calculate lot size based on risk amount & SL distance |
//+------------------------------------------------------------------+
double CalculateLotSize(double entry, double stopLoss)
{
double slPoints = MathAbs(entry - stopLoss);
if (slPoints <= 0) return (0.0);
double tickValue;
if (!SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE, tickValue))
tickValue = 1.0;
double contractSize;
SymbolInfoDouble(_Symbol, SYMBOL_TRADE_CONTRACT_SIZE, contractSize);
double valuePerPoint = tickValue / _Point;
double lots = RiskUSD / (slPoints * valuePerPoint);
double minLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
double stepLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
lots = MathFloor(lots / stepLot) * stepLot;
return MathMin(MathMax(lots, minLot), MaxLots);
}
//+------------------------------------------------------------------+
//| Bullish FVG Detection (Simplified MK1 version) |
//+------------------------------------------------------------------+
bool IsBullFVG(double atr)
{
if (Bars < 5) return false;
double gapSize = Low[2] - High[4];
return (gapSize > (atr * ATRMultiplier) &&
Close[1] > High[4] && // Confirmation candle
Close[1] > Open[1]);
}
//+------------------------------------------------------------------+
//| Bearish FVG Detection |
//+------------------------------------------------------------------+
bool IsBearFVG(double atr)
{
if (Bars < 5) return false;
double gapSize = Low[4] - High[2];
return (gapSize < -(atr * ATRMultiplier) &&
Close[1] < Low[4] && // Confirmation candle
Close[1] < Open[1]);
}
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Avoid executing on the same candle multiple times
if (Time[0] == lastBarTime) return;
lastBarTime = Time[0];
double atr = iATR(_Symbol, PERIOD_CURRENT, 14, 0);
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
// Bullish Logic (simplified entry on confirmation)
if (EnableBull && IsBullFVG(atr))
{
double sl = Low[swingLength];
double entry = ask;
double tp = entry + (entry - sl) * RRRatio;
double lots = CalculateLotSize(entry, sl);
if (lots > 0 && PositionsTotal() == 0)
{
trade.Buy(lots, _Symbol, entry, sl, tp, "Bull ICT Entry");
}
}
// Bearish Logic (simplified)
if (EnableBear && IsBearFVG(atr))
{
double sl = High[swingLength];
double entry = bid;
double tp = entry - (sl - entry) * RRRatio;
double lots = CalculateLotSize(entry, sl);
if (lots > 0 && PositionsTotal() == 0)
{
trade.Sell(lots, _Symbol, entry, sl, tp, "Bear ICT Entry");
}
}
}
//+------------------------------------------------------------------+