To the traders who are asking for MQL5 version, here is the code that you can copy paste into your MQL5 MetaEditor. note I just modified the code to work on MQL5 only colors were changed and timing windows were changed, EVERY THING belongs to the original author (KimIV). NOTE: the session timings in right now are based on FTMO America servers, you'll have to convert it to your own timings. but I only use New York time. Asia- 8pm - 11pm | London 11pm - 2am | NewYork 8am - 11am. GOOD LUCK.
//+------------------------------------------------------------------+//| i-Sessions_mq5.mq5|//| Converted from MQL4 version|//| Original by KimIV, Russia|//| https://www.kimiv.ru|//| |//| Indicator of trading sessions (visual)|//+------------------------------------------------------------------+#property copyright"Copyright 2005-2025, KimIV, converted to MQL5"#property link"https://www.kimiv.ru"#property version"1.00"#property indicator_chart_window//--- Input parameters inputint NumberOfDays = 10; // Number of days to displayinputstring AsiaBegin = "03:00"; // Asia session start time -- it is in FTMO broker time NY 8pminputstring AsiaEnd = "06:00"; // Asia session end time -- NY 11pminputcolor AsiaColor = clrCyan; // Asia session rectangle colorinputstring EurBegin = "09:00"; // European session start time --NY 2aminputstring EurEnd = "12:00"; // European session end time -- NY 5aminputcolor EurColor = clrPink; // European session rectangle colorinputstring USABegin = "15:00"; // US session start time --NY 8aminputstring USAEnd = "18:00"; // US session end time -- NY 11aminputcolor USAColor = clrYellow; // US session rectangle color//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Custom indicator deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
ObjectsDeleteAll(0, "SS_");
Comment("");
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
RefreshSessions();
return(rates_total);
}
//+------------------------------------------------------------------+//| Refresh all session rectangles |//+------------------------------------------------------------------+void RefreshSessions()
{
datetime dt = TimeCurrent();
for(int i = 0; i < NumberOfDays; i++)
{
DrawSession(dt, "SS_AS_" + IntegerToString(i), AsiaBegin, AsiaEnd, AsiaColor);
DrawSession(dt, "SS_EU_" + IntegerToString(i), EurBegin, EurEnd, EurColor);
DrawSession(dt, "SS_US_" + IntegerToString(i), USABegin, USAEnd, USAColor);
dt = PrevTradingDay(dt);
}
}
//+------------------------------------------------------------------+//| Draw a single session rectangle |//+------------------------------------------------------------------+void DrawSession(datetime dt, string objName, string startTimeStr, string endTimeStr, color clr)
{
string datePart = TimeToString(dt, TIME_DATE);
datetime t1 = StringToTime(datePart + " " + startTimeStr);
datetime t2 = StringToTime(datePart + " " + endTimeStr);
// Handle overnight sessions (e.g., 22:00 to 06:00 next day)if(t2 <= t1)
t2 += 86400;
double highPrice = 0, lowPrice = 0;
if(!GetSessionHighLow(t1, t2, highPrice, lowPrice))
return;
UpdateRectangle(objName, t1, t2, highPrice, lowPrice, clr);
}
//+------------------------------------------------------------------+//| Retrieve highest high and lowest low between two times |//+------------------------------------------------------------------+bool GetSessionHighLow(datetime t1, datetime t2, double &highPrice, double &lowPrice)
{
double highArray[];
int highCount = CopyHigh(_Symbol, PERIOD_CURRENT, t1, t2, highArray);
if(highCount <= 0)
returnfalse;
double lowArray[];
int lowCount = CopyLow(_Symbol, PERIOD_CURRENT, t1, t2, lowArray);
if(lowCount <= 0)
returnfalse;
highPrice = highArray[ArrayMaximum(highArray)];
lowPrice = lowArray[ArrayMinimum(lowArray)];
returntrue;
}
//+------------------------------------------------------------------+//| Create or update a rectangle object |//+------------------------------------------------------------------+void UpdateRectangle(string name, datetime t1, datetime t2, double highPrice, double lowPrice, color clr)
{
if(ObjectFind(0, name) < 0)
{
ObjectCreate(0, name, OBJ_RECTANGLE, 0, t1, highPrice, t2, lowPrice);
ObjectSetInteger(0, name, OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_BACK, true);
ObjectSetInteger(0, name, OBJPROP_FILL, true);
ObjectSetInteger(0, name, OBJPROP_WIDTH, 1);
}
else
{
ObjectSetInteger(0, name, OBJPROP_TIME, 0, t1);
ObjectSetDouble(0, name, OBJPROP_PRICE, 0, highPrice);
ObjectSetInteger(0, name, OBJPROP_TIME, 1, t2);
ObjectSetDouble(0, name, OBJPROP_PRICE, 1, lowPrice);
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
}
}
//+------------------------------------------------------------------+//| Returns the previous trading day (Monday to Friday) |//+------------------------------------------------------------------+datetime PrevTradingDay(datetime dt)
{
MqlDateTime dtStruct;
dt -= 86400;
TimeToStruct(dt, dtStruct);
// day_of_week: 0=Sunday, 1=Monday, ..., 6=Saturdaywhile(dtStruct.day_of_week == 0 || dtStruct.day_of_week == 6)
{
dt -= 86400;
TimeToStruct(dt, dtStruct);
}
return dt;
}
//+------------------------------------------------------------------+
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
To the traders who are asking for MQL5 version, here is the code that you can copy paste into your MQL5 MetaEditor. note I just modified the code to work on MQL5 only colors were changed and timing windows were changed, EVERY THING belongs to the original author (KimIV). NOTE: the session timings in right now are based on FTMO America servers, you'll have to convert it to your own timings. but I only use New York time. Asia- 8pm - 11pm | London 11pm - 2am | NewYork 8am - 11am. GOOD LUCK.