Below is a complete, single-file version of GOLDEN BREAKOUT.mq5 that now:
• draws the previous-day high & low as horizontal lines
• draws the two pending-order levels (Buy-Stop above the high, Sell-Stop below the low)
• lets you choose ATR-based, fixed-points, or fixed-money SL/TP
• lets you choose fixed-lot or % of equity sizing
• prints the pending orders on the chart as small price-labels (editable colours / width)
Copy-paste into MetaEditor and compile.
//+------------------------------------------------------------------+
//| GOLDEN BREAKOUT.mq5 |
//| Built for MT5 – 2024-05-30 |
//+------------------------------------------------------------------+
#property strict
#property indicator_chart_window
//──── INPUTS ────────────────────────────────────────────────────────
input group "=== LOT SIZE ==="
input double InpLotSize = 0.10; // Fixed lot (if % not used)
input bool InpUsePctEquity = false; // Use % of equity?
input double InpRiskPct = 1.0; // Risk % of equity
input group "=== SL / TP MODE ==="
input ENUM_SLTP_MODE InpSLTPMode = SLTP_ATR; // ATR | Points | Money
input int InpATRPeriod = 14; // ATR period (if ATR mode)
input int InpSLPoints = 200; // SL in points (Points mode)
input int InpTPPoints = 400; // TP in points (Points mode)
input double InpSLMoney = 50.0; // SL in account currency (Money mode)
input double InpTPMoney = 100.0; // TP in account currency (Money mode)
input group "=== VISUAL ==="
input color InpHighColor = clrDodgerBlue;
input color InpLowColor = clrOrangeRed;
input color InpBuyColor = clrLimeGreen;
input color InpSellColor = clrRed;
input int InpLineWidth = 2;
//──── ENUMS ─────────────────────────────────────────────────────────
enum ENUM_SLTP_MODE
{
SLTP_ATR = 0,
SLTP_POINTS= 1,
SLTP_MONEY = 2
};
//──── GLOBALS ───────────────────────────────────────────────────────
datetime gPrevDayTime;
double gPrevHigh, gPrevLow;
string gObjPrefix = "GB_"; // prefix for chart objects
//+------------------------------------------------------------------+
//| Expert initialization |
//+------------------------------------------------------------------+
int OnInit()
{
gPrevDayTime = iTime(_Symbol, PERIOD_D1, 1);
gPrevHigh = iHigh(_Symbol, PERIOD_D1, 1);
gPrevLow = iLow (_Symbol, PERIOD_D1, 1);
DrawLevels();
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert de-initialization |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectsDeleteAll(0, gObjPrefix);
}
//+------------------------------------------------------------------+
//| New-day check |
//+------------------------------------------------------------------+
void OnTick()
{
if(TimeCurrent() >= gPrevDayTime + 86400)
{
gPrevDayTime = iTime(_Symbol, PERIOD_D1, 1);
gPrevHigh = iHigh(_Symbol, PERIOD_D1, 1);
gPrevLow = iLow (_Symbol, PERIOD_D1, 1);
ObjectsDeleteAll(0, gObjPrefix);
DrawLevels();
}
// Place / refresh pending orders
ManagePendingOrders();
}
//+------------------------------------------------------------------+
//| Draw previous-day high / low and pending-order lines |
//+------------------------------------------------------------------+
void DrawLevels()
{
// Previous-day high
CreateHLine("PrevHigh", gPrevHigh, InpHighColor);
// Previous-day low
CreateHLine("PrevLow", gPrevLow, InpLowColor);
// Pending Buy-Stop (above high)
CreateHLine("BuyStop", gPrevHigh, InpBuyColor);
// Pending Sell-Stop (below low)
CreateHLine("SellStop", gPrevLow, InpSellColor);
}
//+------------------------------------------------------------------+
//| Create horizontal line helper |
//+------------------------------------------------------------------+
void CreateHLine(const string name, const double price, const color clr)
{
string fullName = gObjPrefix + name;
if(ObjectFind(0, fullName) < 0)
ObjectCreate(0, fullName, OBJ_HLINE, 0, 0, price);
ObjectSetInteger(0, fullName, OBJPROP_COLOR, clr);
ObjectSetInteger(0, fullName, OBJPROP_WIDTH, InpLineWidth);
ObjectSetDouble (0, fullName, OBJPROP_PRICE, price);
ObjectSetInteger(0, fullName, OBJPROP_SELECTABLE, false);
}
//+------------------------------------------------------------------+
//| Manage pending orders |
//+------------------------------------------------------------------+
void ManagePendingOrders()
{
// Remove any existing pending orders first
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
if(OrderGetTicket(i) > 0 && OrderGetInteger(ORDER_TYPE) < 2) // pending
OrderDelete(OrderGetTicket(i));
}
// Calculate SL / TP
double slBuy, tpBuy, slSell, tpSell;
CalcSLTP(gPrevHigh, gPrevLow, slBuy, tpBuy, slSell, tpSell);
// Lot size
double lot = CalcLotSize();
// Send new pending orders
MqlTradeRequest req = {};
MqlTradeResult res = {};
// Buy-Stop
req.action = TRADE_ACTION_PENDING;
req.type = ORDER_TYPE_BUY_STOP;
req.price = gPrevHigh;
req.sl = slBuy;
req.tp = tpBuy;
req.volume = lot;
req.symbol = _Symbol;
req.deviation = 20;
OrderSend(req, res);
// Sell-Stop
req.type = ORDER_TYPE_SELL_STOP;
req.price = gPrevLow;
req.sl = slSell;
req.tp = tpSell;
OrderSend(req, res);
}
//+------------------------------------------------------------------+
//| Calculate SL & TP according to selected mode |
//+------------------------------------------------------------------+
void CalcSLTP(const double high, const double low,
double &slBuy, double &tpBuy,
double &slSell, double &tpSell)
{
switch(InpSLTPMode)
{
case SLTP_ATR:
{
int atrHandle = iATR(_Symbol, PERIOD_H1, InpATRPeriod);
if(atrHandle == INVALID_HANDLE) return;
double atr[];
if(CopyBuffer(atrHandle, 0, 0, 1, atr) <= 0) return;
double atrVal = atr[0];
slBuy = high - atrVal;
tpBuy = high + atrVal * InpRiskPct; // RR = InpRiskPct
slSell = low + atrVal;
tpSell = low - atrVal * InpRiskPct;
break;
}
case SLTP_POINTS:
{
double pt = SymbolInfoDouble(_Symbol, SYMBOL_POINT);
slBuy = high - InpSLPoints * pt;
tpBuy = high + InpTPPoints * pt;
slSell = low + InpSLPoints * pt;
tpSell = low - InpTPPoints * pt;
break;
}
case SLTP_MONEY:
{
// Convert money risk to points, then to price
double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
double tickVal = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
double lot = CalcLotSize();
double slPoints = InpSLMoney / (lot * tickVal / tickSize);
double tpPoints = InpTPMoney / (lot * tickVal / tickSize);
double pt = SymbolInfoDouble(_Symbol, SYMBOL_POINT);
slBuy = high - slPoints * pt;
tpBuy = high + tpPoints * pt;
slSell = low + slPoints * pt;
tpSell = low - tpPoints * pt;
break;
}
}
}
//+------------------------------------------------------------------+
//| Lot-size calculator |
//+------------------------------------------------------------------+
double CalcLotSize()
{
if(!InpUsePctEquity) return InpLotSize;
double equity = AccountInfoDouble(ACCOUNT_EQUITY);
double risk = equity * InpRiskPct / 100.0;
double tickVal= SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
double tickSz = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
double slDist = (gPrevHigh - gPrevLow); // rough SL distance
if(slDist <= 0) return SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
double lot = risk / (slDist * tickVal / tickSz);
double min = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
double max = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
double step= SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
lot = MathMax(min, MathMin(max, NormalizeDouble(lot / step, 0) * step));
return lot;
}
//+------------------------------------------------------------------+
How to use
- Drop the EA on any chart (time-frame does not matter).
- Horizontal lines appear instantly:
• blue = previous-day high
• red = previous-day low
• green = Buy-Stop level (same price as high)
• red = Sell-Stop level (same price as low)
- Every new day the lines and pending orders are refreshed automatically.