DTS-Dolly_Trading Times #3
Download scriptThis script is a specialized visual tool for the MetaTrader platform designed to help traders identify key global market sessions on their price charts. Instead of forcing you to keep track of world clocks manually, it automatically plots specific opening and closing times for major financial hubs directly onto your trading screen.
Core Functionality
The primary purpose of this script is to provide a clear "roadmap" of the trading day. It identifies four key milestones:
- Europe Open
- London Open
- US Open
- Europe Closing Session
By visualizing these moments, traders can better understand periods of high volatility, liquidity shifts, and when major global markets enter or exit the field.
How It Works
The logic follows a structured process to ensure the information is both accurate and easy to read:
1. Customization & Configuration The tool allows you to set your specific broker's time offset, choose how many days of historical data you want to see (e.g., looking back at the last 2 days), and toggle which specific market sessions you want to display. You can also customize the colors for each session so they are easily distinguishable at a glance.
2. Automated Plotting The script scans your chart and identifies the exact historical bars corresponding to the times you have configured. It then draws visual markers (lines) on the chart. These markers highlight the highest and lowest price points reached during those specific sessions, helping you see the price range covered by each market's activity.
3. Dynamic Labeling In addition to the lines on the chart, the script generates a clean text dashboard in the corner of your screen (customizable to any corner). This dashboard provides a quick-reference list showing the names of the sessions and their corresponding times, ensuring you always know what is happening currently or coming up next.
4. Smart Date Handling To ensure the visual markers appear correctly even across different months and leap years, the script includes internal logic to calculate "trading days." This prevents errors when the tool moves from one day to the next, ensuring the lines are drawn on the correct dates throughout the calendar year.
Key Benefits for Traders
- Visual Context: Provides an immediate visual history of how different markets influenced price action over the previous days.
- Reduced Complexity: Eliminates the need to manually calculate time zone differences between your local time and global market hours.
- Clarity: By using distinct colors for each session, it allows you to quickly identify which "trading environment" the market is currently operating in.
//+------------------------------------------------------------------+
//| Dolly_Trading Times #3.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property link " Code used from i-ParamonWorkTime.mq4 "
#property indicator_chart_window
// corner - 0 = top left, 1 = top right, 2 = bottom left, 3 = bottom right
extern int corner=3;
extern string Broker_GMT_Offset = "00:00";
extern int TradingTimes_NumberOfDays = 2;
extern string EUROPE_Open = "06:00";
extern color EUROPE_Color = Purple;
extern color EUROPE_TEXT_Color = Purple;
extern bool Show_EUROPE_Open = true;
extern string LONDON_Open = "7:00";
extern color LONDON_Color = MidnightBlue;
extern color LONDON_TEXT_Color = MidnightBlue;
extern bool Show_LONDON_Open = true;
extern string US_Open = "12:00";
extern color US_Color = Indigo;
extern color US_TEXT_Color = Indigo;
extern bool Show_US_Open = true;
extern string EUROPE1_Close = "16:00";
extern color EUROPE1_Color = Maroon;
extern color EUROPE1_TEXT_Color =Maroon;
extern bool Show_EUROPE1_Close = true;
extern bool Show_Daily_Trade_TEXT = true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void init()
{
DeleteObjects();
for (int i=0; i<TradingTimes_NumberOfDays; i++)
{
CreateObjects("DollyTIME1"+i, EUROPE_Color);
CreateObjects("DollyTIME2"+i, LONDON_Color);
CreateObjects("DollyTIME3"+i, US_Color);
CreateObjects("DollyTIME4"+i, EUROPE1_Color);
}
int top = 200;//topOff;
int left = 60;
ObjectMakeLabel( "TT1", left, top );
ObjectMakeLabel( "TT2", 13, top );
ObjectMakeLabel( "TT3", left, top-15 );
ObjectMakeLabel( "TT4", 13, top-15 );
ObjectMakeLabel( "TT5", left, top-30 );
ObjectMakeLabel( "TT6", 13, top-30 );
ObjectMakeLabel( "TT7", left, top-45 );
ObjectMakeLabel( "TT8", 13, top-45 );
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
void deinit()
{
DeleteObjects();
ObjectDelete("TT1");ObjectDelete("TT2");ObjectDelete("TT3");
ObjectDelete("TT4");ObjectDelete("TT5");ObjectDelete("TT6");
ObjectDelete("TT7");ObjectDelete("TT8");
}
//+------------------------------------------------------------------+
void CreateObjects(string TRADETIMES, color cl)
{
ObjectCreate(TRADETIMES, OBJ_TREND, 0, 0,0, 0,0);
ObjectSet(TRADETIMES, OBJPROP_STYLE, STYLE_DOT);
ObjectSet(TRADETIMES, OBJPROP_WIDTH,1);
ObjectSet(TRADETIMES, OBJPROP_COLOR, cl);
ObjectSet(TRADETIMES, OBJPROP_BACK, True);
}
//+------------------------------------------------------------------+
void DeleteObjects()
{
for (int i=0; i<TradingTimes_NumberOfDays; i++) {
ObjectDelete("DollyTIME"+i);
ObjectDelete("DollyTIME"+i);
ObjectDelete("DollyTIME"+i);
ObjectDelete("DollyTIME"+i);
}
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
void start()
{
datetime dt=CurTime();
for (int i=0; i<TradingTimes_NumberOfDays; i++) {
if (Show_EUROPE_Open==true)
{
DrawObjects(dt, "DollyTIME1"+i, EUROPE_Open, EUROPE_Open);}
if (Show_LONDON_Open==true)
{
DrawObjects(dt, "DollyTIME2"+i, LONDON_Open, LONDON_Open);}
if (Show_US_Open==true)
{
DrawObjects(dt, "DollyTIME3"+i, US_Open, US_Open);}
if (Show_EUROPE1_Close==true)
{
DrawObjects(dt, "DollyTIME4"+i, EUROPE1_Close, EUROPE1_Close);}
dt=decDateTradeDay(dt);
while (TimeDayOfWeek(dt)>5) dt=decDateTradeDay(dt);
}
}
//+------------------------------------------------------------------+
void DrawObjects(datetime dt, string TRADETIMES, string tb, string te)
{
datetime t1, t2;
double p1, p2;
int b1, b2;
t1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+tb);
t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+te);
b1=iBarShift(NULL, 0, t1);
b2=iBarShift(NULL, 0, t2);
p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2, b2)];
p2=Low [Lowest (NULL, 0, MODE_LOW , b1-b2, b2)];
ObjectSet(TRADETIMES, OBJPROP_TIME1 , t1);
ObjectSet(TRADETIMES, OBJPROP_PRICE1, p1);
ObjectSet(TRADETIMES, OBJPROP_TIME2 , t2);
ObjectSet(TRADETIMES, OBJPROP_PRICE2, p2);
if (Show_Daily_Trade_TEXT==true)
{
ObjectSetText( "TT1", "EUROPE Open", 8, "Arial", EUROPE_TEXT_Color );
ObjectSetText( "TT2", ""+EUROPE_Open+"", 8, "Arial", Silver );
ObjectSetText( "TT3", "LONDON Open", 8, "Arial", LONDON_TEXT_Color );
ObjectSetText( "TT4", ""+LONDON_Open+"", 8, "Arial", Silver );
ObjectSetText( "TT5", "US Open", 8, "Arial", US_TEXT_Color );
ObjectSetText( "TT6", ""+US_Open+"", 8, "Arial", Silver );
ObjectSetText( "TT7", "EUROPE Open", 8, "Arial", EUROPE_TEXT_Color );
ObjectSetText( "TT8", ""+EUROPE1_Close+"", 8, "Arial", Silver );
}
}
//+------------------------------------------------------------------+
datetime decDateTradeDay (datetime dt) {
int ty=TimeYear(dt);
int tm=TimeMonth(dt);
int td=TimeDay(dt);
int th=TimeHour(dt);
int ti=TimeMinute(dt);
td--;
if (td==0) {
tm--;
if (tm==0) {
ty--;
tm=12;
}
if (tm==1 || tm==3 || tm==5 || tm==7 || tm==8 || tm==10 || tm==12) td=31;
if (tm==2) if (MathMod(ty, 4)==0) td=29; else td=28;
if (tm==4 || tm==6 || tm==9 || tm==11) td=30;
}
return(StrToTime(ty+"."+tm+"."+td+" "+th+":"+ti));
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int ObjectMakeLabel( string n, int xoff, int yoff ) {
ObjectCreate( n, OBJ_LABEL, 0, 0, 0 );
ObjectSet( n, OBJPROP_CORNER, corner );
ObjectSet( n, OBJPROP_XDISTANCE, xoff );
ObjectSet( n, OBJPROP_YDISTANCE, yoff );
ObjectSet( n, OBJPROP_BACK, true );
}
Comments