Save this file in your MT5 data folder under MQL5/Indicators/HolidayWarning.mq5 and compile in MetaEditor.
Code: Select all
//+------------------------------------------------------------------+
//| HolidayWarning.mq5 |
//| Copyright 2026, Scalping Setup |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026"
#property link ""
#property version "1.00"
#property indicator_chart_window
#property indicator_plots 0
// --- INPUTS ---
input group "=== Holiday Window ==="
input int InpStartMonth = 12; // Start Month
input int InpStartDay = 20; // Start Day
input int InpEndMonth = 1; // End Month
input int InpEndDay = 3; // End Day
input group "=== Spread & Warning ==="
input double InpMaxSpreadPips = 2.5; // Alert Spread Threshold (Pips)
input color InpBgColor = C'130,20,20';// Banner Background Color
input color InpTextColor = clrWhite; // Text Color
#define PREFIX "HW5_OVERLAY_"
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
DeleteUI();
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
DeleteUI();
ChartRedraw(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
datetime current = TimeCurrent();
bool isHoliday = CheckHolidayDate(current, InpStartMonth, InpStartDay, InpEndMonth, InpEndDay);
long rawSpread = SymbolInfoInteger(_Symbol, SYMBOL_SPREAD);
int digits = (int)SymbolInfoInteger(_Symbol, SYMBOL_DIGITS);
double pipMult = (digits == 3 || digits == 5) ? 10.0 : 1.0;
double currentSpreadPips = (double)rawSpread / pipMult;
bool isSpreadBlown = (currentSpreadPips >= InpMaxSpreadPips);
if(isHoliday || isSpreadBlown)
{
RenderWarningBanner(isHoliday, currentSpreadPips);
}
else
{
DeleteUI();
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| Date evaluation supporting Dec -> Jan year wrap |
//+------------------------------------------------------------------+
bool CheckHolidayDate(datetime t, int sMon, int sDay, int eMon, int eDay)
{
MqlDateTime dt;
TimeToStruct(t, dt);
bool afterStart = (dt.mon > sMon) || (dt.mon == sMon && dt.day >= sDay);
bool beforeEnd = (dt.mon < eMon) || (dt.mon == eMon && dt.day <= eDay);
if(sMon > eMon)
return (afterStart || beforeEnd);
else
return (afterStart && beforeEnd);
}
//+------------------------------------------------------------------+
//| Render warning box and text labels |
//+------------------------------------------------------------------+
void RenderWarningBanner(bool isHoliday, double spreadPips)
{
int chartWidth = (int)ChartGetInteger(0, CHART_WIDTH_IN_PIXELS);
int boxWidth = 440;
int boxHeight = 95;
int xPos = MathMax(20, (chartWidth - boxWidth) / 2);
int yPos = 40;
// 1. Background Box
string bgName = PREFIX + "BG";
if(ObjectFind(0, bgName) < 0)
{
ObjectCreate(0, bgName, OBJ_RECTANGLE_LABEL, 0, 0, 0);
ObjectSetInteger(0, bgName, OBJPROP_CORNER, CORNER_LEFT_UPPER);
ObjectSetInteger(0, bgName, OBJPROP_BORDER_TYPE, BORDER_FLAT);
ObjectSetInteger(0, bgName, OBJPROP_COLOR, clrRed);
ObjectSetInteger(0, bgName, OBJPROP_WIDTH, 2);
}
ObjectSetInteger(0, bgName, OBJPROP_XDISTANCE, xPos);
ObjectSetInteger(0, bgName, OBJPROP_YDISTANCE, yPos);
ObjectSetInteger(0, bgName, OBJPROP_XSIZE, boxWidth);
ObjectSetInteger(0, bgName, OBJPROP_YSIZE, boxHeight);
ObjectSetInteger(0, bgName, OBJPROP_BGCOLOR, InpBgColor);
// 2. Title Label
string titleText = isHoliday ? "[!] HOLIDAY NO-TRADE ZONE [!]" : "[!] WARNING: SPREAD BLOWN [!]";
UpdateLabel(PREFIX + "TITLE", titleText, xPos + 20, yPos + 12, "Arial Bold", 13, clrWhite);
// 3. Status Line
string status = isHoliday ? "THIN LIQUIDITY -- OBSERVE & JOURNAL ONLY" : "EXECUTION CONDITIONS COMPROMISED";
UpdateLabel(PREFIX + "STATUS", status, xPos + 20, yPos + 40, "Arial", 9, clrYellow);
// 4. Spread Line
string spreadText = StringFormat("Live Spread: %.1f pips (Max Allowed: %.1f pips)", spreadPips, InpMaxSpreadPips);
color spreadColor = (spreadPips >= InpMaxSpreadPips) ? clrRed : clrLime;
UpdateLabel(PREFIX + "SPREAD", spreadText, xPos + 20, yPos + 62, "Arial Bold", 10, spreadColor);
ChartRedraw(0);
}
//+------------------------------------------------------------------+
//| Update or Create Label Object |
//+------------------------------------------------------------------+
void UpdateLabel(string name, string text, int x, int y, string font, int fontSize, color col)
{
if(ObjectFind(0, name) < 0)
{
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
}
ObjectSetString(0, name, OBJPROP_TEXT, text);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);
ObjectSetString(0, name, OBJPROP_FONT, font);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, fontSize);
ObjectSetInteger(0, name, OBJPROP_COLOR, col);
}
//+------------------------------------------------------------------+
//| Clean up screen objects |
//+------------------------------------------------------------------+
void DeleteUI()
{
ObjectsDeleteAll(0, PREFIX);
}