TimeLines
Download scriptThe TimeLines script is a visual tool designed to enhance chart readability by automatically marking specific time intervals with vertical lines. It serves as a structural guide for traders, helping them identify key milestones on a price chart without having to manually calculate where certain hours, days, or weeks begin.
Core Functionality
The primary purpose of this script is to divide your trading screen into organized segments. Depending on the settings you choose, it automatically identifies and draws vertical lines at regular intervals. This allows for a much cleaner visual experience, as it highlights the transition between different time periods (such as every hour, every day, or specific 4-hour blocks).
How the Logic Works
The script operates based on several key logic pillars:
- Dynamic Time Recognition: The tool is programmed to understand various timeframes. It can recognize standard intervals like minutes (M5, M15, M30), hours (H1, H4), days (D1), and even larger spans like weekly (W1) or monthly (MN) transitions.
- Smart Interval Detection: Instead of just drawing lines at random, the script checks the specific time of each candle. For example:
- On an Hour (H1) setting, it looks for the start of every hour.
- On a 4-Hour (H4) setting, it identifies specific 4-hour blocks (e.g., 00:00, 04:00, 08:00, etc.).
- On Daily or Weekly settings, it pinpoint the exact moment the new day or week begins.
- Automatic Chart Marking: As the price moves and new candles appear, the script continuously scans the history. It places a vertical line at the start of each designated period and labels it clearly with the relevant time information.
- Historical Depth: The tool can look back into the past (based on your "History" setting) to populate previous charts with these markers, giving you a consistent visual history of time transitions.
Key Features for the User
- Visual Customization: You can easily adjust the color, thickness, and style of the lines to ensure they are visible but not distracting.
- Background Positioning: There is an option to place these lines in the background of the chart, which helps keep the primary price action and candles as the main focus.
- Time Alerts: The script can be configured to provide a notification alert at specific time marks, ensuring you don't miss important session changes or transitions while away from the screen.
- Automatic Cleanup: When the indicator is removed from the chart, it includes a specialized routine to automatically delete the lines it created, leaving your chart clean and original.
Summary for Traders
Essentially, this tool acts as a "grid" for time. By providing clear visual boundaries for hours, days, or specific intervals, it helps traders stay oriented within the market's timeline, making it easier to analyze sessions and historical price movements at a glance.
//+------------------------------------------------------------------+
//| TimeLines.mq4 |
//| Denis Orlov |
//| http://denis-or-love.narod.ru |
/*
Àâòîìàòè÷åñêàÿ ðàçëèíîâêà ãðàôèêà ïî âðåìåíè è òàéìåð.
Ïîäðîáíî:
http://codebase.mql4.com/ru/6093
Automatic marking of the chart by the time and the timer.
In detail:
http://codebase.mql4.com/6095
***
Âñå ìîè èíäèêàòîðû:
http://codebase.mql4.com/ru/author/denis_orlov
***
ÏÎËÜÇÓÉÒÅÑÜ È ÏÐÎÖÂÅÒÀÉÒÅ!
***
All my indicators:
http://codebase.mql4.com/author/denis_orlov
***
USE AND PROSPER!
*/
//+------------------------------------------------------------------+
#property copyright "Denis Orlov"
#property link "http://denis-or-love.narod.ru"
#property indicator_chart_window
#define Pr "TimeLines "
extern int period=15;
extern color LineColor=Blue;
extern int LineWidth=1;
extern int LineStyle=2;
extern int History=100;
extern bool TimeAlert=false;
extern bool Back=true;//Ðèñîâàòü êà ôîí
int per;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
/*if(period<=Period()|| period<5)
Alert(
"Èíäèêàòîð TimeLines íå áóäåò ðàáîòàòü íà ýòîì ÒÔ"+"\n"+
"ñî çíà÷åíèåì \"period\"="+period+"\n"+
"Èçìåíèòå ýòî çíà÷åíèå, ïîæàëóéñòà."+"\n"+
"Indicator TimeLines will not work on this TF"+"\n"+
"with the value of the \"period\"="+period+"\n"+
"Change this value, please.");*/
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
Delete_My_Obj(Pr+PeriodToStr(period));
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if(period<=Period()|| period<5) return(0);
int Counted_bars=IndicatorCounted();
if(Counted_bars>0)
{
if (per == Time[0]) return;
per = Time[0];
CheckAndDraw(Time[0]);
return;
}
int i=Bars-Counted_bars-1; // Èíäåêñ ïåðâîãî íåïîñ÷èòàííîãî
if (History>0&&i>History-1) // Åñëè ìíîãî áàðîâ òî ..
i=History-1;
while(i>=0) // Öèêë ïî íåïîñ÷èòàííûì áàðàì
{
CheckAndDraw(Time[i]);
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
void CheckAndDraw(datetime t)
{
int TM=TimeMinute(t), TH=TimeHour(t) ;
bool draw=false;
if(period==5)
{
if( TM==0 || TM==5 ||TM==10 ||TM==15 ||TM==20||TM==25 ||TM==30
||TM==35 ||TM==40 ||TM==45||TM==50||TM==55)
draw=true;
}
if(period==15)
{
if( TM==0 || TM==15 ||TM==30 ||TM==45)
draw=true;
}
if(period==30)
{
if( TM==0 || TM==30)
draw=true;
}
if(period==60)
{
if( TM==0)
draw=true;
}
if(period==240)
{
if(TM==0 && (TH==0 ||TH==4||TH==8||TH==12||TH==16||TH==20||TH==24) )
draw=true;
}
if(period==1440)
{
if(TH==0 && TM==0)
draw=true;
}
if(period==10080)
{
if(TH==0 && TM==0 && TimeDayOfWeek(t)==1 )
draw=true;
}
if(period==43200)
{
if(TH==0 && TM==0 && TimeDay(t)==1 )
draw=true;
}
string LName=Pr+PeriodToStr(period)+" "+TimeToStr(t,TIME_DATE|TIME_MINUTES);
if(draw && ObjectFind(LName)<0)
{
ObjectCreate( LName,OBJ_VLINE,0,t,0);
ObjectSet( LName, OBJPROP_COLOR , LineColor);
ObjectSet( LName, OBJPROP_WIDTH , LineWidth);
if(Back==true)ObjectSet( LName, OBJPROP_BACK, Back);
if(LineWidth<2)
ObjectSet( LName, OBJPROP_STYLE , LineStyle);
// ObjectSetText( LName, DoubleToStr(TM,0));
}
string AlStr=Symbol()+" "+PeriodToStr(Period())+" : "+LName;
int nt=t+period*60;
LName=Pr+PeriodToStr(period)+" "+TimeToStr(nt,TIME_DATE|TIME_MINUTES);
if(draw && ObjectFind(LName)<0)
{
if(TimeAlert && Time[0]==t) Alert(AlStr);
ObjectCreate( LName,OBJ_VLINE,0,nt,0);
ObjectSet( LName, OBJPROP_COLOR , LineColor);
ObjectSet( LName, OBJPROP_WIDTH , LineWidth);
if(Back==true)ObjectSet( LName, OBJPROP_BACK, Back);
if(LineWidth<2)
ObjectSet( LName, OBJPROP_STYLE , LineStyle);
// ObjectSetText( LName, DoubleToStr(TM,0));
}
}
//----------------------
void Delete_My_Obj(string Prefix)
{//Alert(ObjectsTotal());
for(int k=ObjectsTotal()-1; k>=0; k--) // Ïî êîëè÷åñòâó âñåõ îáúåêòîâ
{
string Obj_Name=ObjectName(k); // Çàïðàøèâàåì èìÿ îáúåêòà
string Head=StringSubstr(Obj_Name,0,StringLen(Prefix));// Èçâëåêàåì ïåðâûå ñèì
if (Head==Prefix)// Íàéäåí îáúåêò, ..
{
ObjectDelete(Obj_Name);
//Alert(Head+";"+Prefix);
}
}
}
//-------------------------------
string PeriodToStr(int Per)
{
switch(Per) // Ðàñ÷¸ò äëÿ..
{ // .. ðàçëè÷íûõ ÒÔ
case 1: return("M1"); break;// Òàéìôðåéì Ì1
case 5: return("M5"); break;// Òàéìôðåéì Ì5
case 15: return("M15"); break;// Òàéìôðåéì Ì15
case 30: return("M30"); break;// Òàéìôðåéì Ì30
case 60: return("H1"); break;// Òàéìôðåéì H1
case 240: return("H4"); break;// Òàéìôðåéì H4
case 1440: return("D1"); break;// Òàéìôðåéì D1
case 10080: return("W1"); break;// Òàéìôðåéì W1
case 43200: return("ÌN"); break;// Òàéìôðåéì ÌN
}
}
Comments