time2
Download scriptThis script is designed to automate the visual marking of specific trading sessions or significant time milestones on your MetaTrader charts. Instead of manually drawing lines every day, the tool automatically identifies key hours and places colored vertical markers to help you organize your trading day at a glance.
How it Works
The script scans your historical chart data and monitors the current live time to place markers at five specific daily intervals. Each interval is assigned a unique color, allowing you to distinguish between different periods of market activity:
- 08:00 AM: Marked with a Medium Blue line.
- 11:00 AM: Marked with a Blue line.
- 12:30 PM: Marked with a Purple line.
- 02:00 PM (14:00): Marked with an Orange line.
- 05:00 PM (17:00): Marked with a Brown line.
Key Functional Features
- Historical Backfilling: When you first load the script, it automatically reviews your past chart data. It "looks back" through the history and draws these vertical lines on all previous days, ensuring that your historical analysis is clearly segmented into time blocks.
- Real-Time Updates: The tool also operates in real-time. As the current market clock hits any of the specified times, the script will automatically generate a new line for the current day.
- Smart Placement Logic: To prevent the chart from becoming cluttered with duplicate lines, the script uses a "flag" system. This ensures that only one vertical line is drawn for each specific time milestone per day.
- Automatic Reset: The logic includes a built-in reset mechanism. Every night between 00:00 and 10:00, the tool clears its internal memory of the current day's marks, preparing itself to draw a fresh set of lines for the next trading session.
Summary for Traders
This tool acts as a visual "timetable" for your charts. By providing clear, color-coded boundaries at 8:00, 11:00, 12:30, 14:00, and 17:00, it helps you quickly identify high-volatility windows, session opens, or specific times of day where you may prefer to execute (or avoid) trades.
//+------------------------------------------------------------------+
//| time1.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
string t;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
int i,a,b,c,d,e;
i=Bars-1; //Ïðîâåðÿåì âåñü ãðàôèê
while(i>0)
{
t=DoubleToStr(i,0);
if(TimeMinute(Time[i])>=0&&TimeHour(Time[i])==8&&a==0)//Âðåìÿ 8:00
{
ObjectCreate(t, OBJ_VLINE, 0, Time[i],0); //Ðèñóåì âåðòèêàëü
ObjectSet(t, OBJPROP_COLOR,MediumBlue);
a=1; //Ôëàæîê, ÷òîáû ðèñîâàëàñü òîëüêî îäíà ëèíèÿ
}
if(TimeMinute(Time[i])>=0&&TimeHour(Time[i])==11&&b==0)//Âðåìÿ 11:00
{
ObjectCreate(t, OBJ_VLINE, 0, Time[i],0);
ObjectSet(t, OBJPROP_COLOR,Blue);
b=1;
}
if(TimeMinute(Time[i])>=30&&TimeHour(Time[i])==12&&c==0)//Âðåìÿ 12:30
{
ObjectCreate(t, OBJ_VLINE, 0, Time[i], 0);
ObjectSet(t, OBJPROP_COLOR,Purple);
c=1;
}
if(TimeMinute(Time[i])>=0&&TimeHour(Time[i])==14&&d==0)//Âðåìÿ 14:00
{
ObjectCreate(t, OBJ_VLINE, 0, Time[i],0);
ObjectSet(t, OBJPROP_COLOR,Orange);
d=1;
}
if(TimeMinute(Time[i])>=0&&TimeHour(Time[i])==17&&e==0)//Âðåìÿ 17:00
{
ObjectCreate(t, OBJ_VLINE, 0, Time[i],0);
ObjectSet(t, OBJPROP_COLOR,Brown);
e=1;
}
if(TimeHour(Time[i])==00&&TimeMinute(Time[i])>=0&&TimeMinute(Time[i])<=10)//Âðåìÿ 00:00
{
a=0;b=0;c=0;d=0;e=0; //Ñáðàñûâàåì âñå ôëàæêè
}
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
t=TimeToStr(CurTime());
if(TimeMinute(CurTime())==0&&TimeHour(CurTime())==8)
{
ObjectCreate(t, OBJ_VLINE, 0, CurTime(),0);
ObjectSet(t, OBJPROP_COLOR,MediumBlue);
}
if(TimeMinute(CurTime())==0&&TimeHour(CurTime())==11)
{
ObjectCreate(t, OBJ_VLINE, 0,CurTime(),0);
ObjectSet(t, OBJPROP_COLOR,Blue);
}
if(TimeMinute(CurTime())==30&&TimeHour(CurTime())==12)
{
ObjectCreate(t, OBJ_VLINE, 0,CurTime(), 0);
ObjectSet(t, OBJPROP_COLOR,Purple);
}
if(TimeMinute(CurTime())==0&&TimeHour(CurTime())==14)
{
ObjectCreate(t, OBJ_VLINE, 0,CurTime(),0);
ObjectSet(t, OBJPROP_COLOR,Orange);
}
if(TimeMinute(CurTime())==0&&TimeHour(CurTime())==17)
{
ObjectCreate(t, OBJ_VLINE, 0,CurTime(),0);
ObjectSet(t, OBJPROP_COLOR,Brown);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments