Market_Open

Download script
Market_Open

This script is designed to act as a visual session tracker for traders using the MetaTrader platform. Its primary purpose is to automatically identify and mark specific market opening and closing times on your trading chart, allowing you to see exactly when major global financial hubs become active without having to manually calculate time zones.

Core Functionality

The script scans your price history and identifies key geographic markets, including:

  • Major Sessions: New York, London, Tokyo, Hong Kong, Frankfurt, Sydney, and Auckland.
  • Economic Events: A specific marker for US News.

When the script identifies one of these designated times, it draws a vertical line directly on your chart. This provides an immediate visual cue of when market volatility typically shifts or when high-volume trading periods begin.

Key Features

  • Customizable Visibility: You can toggle each global market on or off individually through the settings. This allows you to customize your workspace to only show the sessions relevant to your specific trading strategy.
  • Visual Distinction: The script uses different colors and line styles (solid, dotted, and dashed) to differentiate between different types of events, such as market opens versus market closes.
  • Advance Notice Alerts: There is an optional "30-minute advance notice" feature. When enabled, the script places dashed lines on the chart a few minutes before a major session begins, giving you a visual heads-up to prepare for upcoming price action.
  • Automatic Labeling: To ensure clarity, the script places text labels along these vertical lines (e.g., "London Open" or "New York Close"). These labels are automatically rotated 90 degrees to sit neatly on the side of your chart without obstructing the price candles.
  • Smart Time Adjustments: The logic includes an internal "Time Adjust" system. This ensures that when the script calculates closing times or advance notices, it handles the math correctly (such as wrapping around midnight) so that the lines appear accurately regardless of the day.

User Experience

The tool is designed to keep your chart organized and clutter-free. It is programmed to stop drawing if you switch to a timeframe larger than one hour (to prevent the screen from becoming overcrowded), ensuring that your visual workspace remains clean and easy to read while providing the essential timing data needed for professional trading.

11 Views
0 Downloads
0 Favorites
Market_Open

#property indicator_chart_window

extern bool NY=true;
extern bool London=true;
extern bool Auckland=true;
extern bool Sydney=true;
extern bool Tokyo=true;
extern bool HongKong=true;
extern bool Frankfurt=true;
extern bool USNews=false;
extern bool t30MinAdvanceNotice=false;     //display dashed line 30 minutes before opening?

//Data provider times for openings
extern int NYOpenDataTime=15;
extern int LondonOpenDataTime=10;
extern int AucklandOpenDataTime=23;
extern int SydneyOpenDataTime=1;
extern int TokyoOpenDataTime=2;
extern int HongKongOpenDataTime=3;
extern int FrankfurtOpenDataTime=8;
extern int USNewsOpenDataTime=15;

extern int BarsToCount=1000;

extern color NYColor=Crimson;
extern color LondonColor=Crimson;
extern color AucklandColor=DimGray;
extern color SydneyColor=DimGray;
extern color TokyoColor=Crimson;
extern color HKColor=DimGray;
extern color FrankfurtColor=DimGray;
extern color USNewsColor=DimGray;
double val1,val2;

int deinit()
  {
   int bars_count=BarsPerWindow(), i;
   for (i=0;i<bars_count;i++)
      {
      ObjectDelete("VLL"+DoubleToStr(i,0));
      ObjectDelete("VL"+DoubleToStr(i,0));
      
      }
   return(0);
  }
//----------------------------------------------------------------------------------------
int start()
   {
   int counted_bars=IndicatorCounted();
   int bars_count=BarsToCount,i,h,m;
   bool drawvl;
   if (Period()>PERIOD_H1) 
      {
         return(0);    //If time > 1 hour clutters up screen
      }
   for (i=0;i<bars_count;i++)
      {
         drawvl=false;
         h=TimeHour(Time[i]);
         m=TimeMinute(Time[i]);
         if (London==true)
            {
               if ((h==LondonOpenDataTime) && (m==0)) {drawvl=true;VerticalLine("London Open + Sydney Close",i,STYLE_SOLID,LondonColor);}
               if ((h==TimeAdjust(LondonOpenDataTime,0)) && (m==0)) {drawvl=true;VerticalLine("London Close",i,STYLE_DOT,LondonColor);}
               if (t30MinAdvanceNotice==true)
                  {
                     if ((h==TimeAdjust(LondonOpenDataTime,1)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,LondonColor);}
                     if ((h==TimeAdjust(LondonOpenDataTime,2)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,LondonColor);}
                  }
            }
         if (NY==true)
            {
               if ((h==NYOpenDataTime) && (m==0)) {drawvl=true;VerticalLine("New York Open",i,STYLE_SOLID,NYColor);}
               if ((h==TimeAdjust(NYOpenDataTime,0)) && (m==0)) {drawvl=true;VerticalLine("New York Close",i,STYLE_DOT,NYColor);}
               if (t30MinAdvanceNotice==true)
                  {
                     if ((h==TimeAdjust(NYOpenDataTime,1)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,NYColor);}
                     if ((h==TimeAdjust(NYOpenDataTime,2)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,NYColor);}
                  }

            }
         if (Auckland==true)
            {
               if ((h==AucklandOpenDataTime) && (m==0)) {drawvl=true;VerticalLine("Auckland Open",i,STYLE_DOT,AucklandColor);}
               //if ((h==TimeAdjust(AucklandOpenDataTime,0)) && (m==0)) {drawvl=true;VerticalLine("Auckland Close",i,STYLE_SOLID,AucklandColor);}
               if (t30MinAdvanceNotice==true)
                  {
                     if ((h==TimeAdjust(AucklandOpenDataTime,1)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,AucklandColor);}
                     if ((h==TimeAdjust(AucklandOpenDataTime,2)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,AucklandColor);}
                  }
            }
         if (Sydney==true)
            {
               if ((h==SydneyOpenDataTime) && (m==0)) {drawvl=true;VerticalLine("Sydney Open",i,STYLE_DOT,SydneyColor);}
               //if ((h==TimeAdjust(SydneyOpenDataTime,0)) && (m==0)) {drawvl=true;VerticalLine("Sydney Close",i,STYLE_SOLID,SydneyColor);}  //TURNED OFF so London Open shows
               if (t30MinAdvanceNotice==true)
                  {
                     if ((h==TimeAdjust(SydneyOpenDataTime,1)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,SydneyColor);}
                     if ((h==TimeAdjust(SydneyOpenDataTime,2)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,SydneyColor);}
                  }
            }
         if (Tokyo==true)
            {
               if ((h==TokyoOpenDataTime) && (m==0)) {drawvl=true;VerticalLine("Tokyo Open",i,STYLE_SOLID,TokyoColor);}
               if ((h==TimeAdjust(TokyoOpenDataTime,0)) && (m==0)) {drawvl=true;VerticalLine("Tokyo Close",i,STYLE_DOT,TokyoColor);}
               if (t30MinAdvanceNotice==true)
                  {
                     if ((h==TimeAdjust(TokyoOpenDataTime,1)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,TokyoColor);}
                     if ((h==TimeAdjust(TokyoOpenDataTime,2)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,TokyoColor);}
                  }
           //Added in Frankfurt       
             }     
          if (Frankfurt==true)
            {
            if ((h==FrankfurtOpenDataTime) && (m==0)) {drawvl=true;VerticalLine("Frankfurt Open + Auckland Close",i,STYLE_DOT,FrankfurtColor);}
            if (t30MinAdvanceNotice==true)                                       
            {
                     if ((h==TimeAdjust(FrankfurtOpenDataTime,1)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,FrankfurtColor);}
                     if ((h==TimeAdjust(FrankfurtOpenDataTime,2)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,FrankfurtColor);}
                  }  
                      
            }
         if (HongKong==true)
            {
               if ((h==HongKongOpenDataTime) && (m==0)) {drawvl=true;VerticalLine("Hong Kong Open",i,STYLE_DOT,HKColor);}
               if ((h==TimeAdjust(HongKongOpenDataTime,0)) && (m==0)) {drawvl=true;VerticalLine("Hong Kong Close",i,STYLE_DOT,HKColor);}
               if (t30MinAdvanceNotice==true)
                  {
                     if ((h==TimeAdjust(HongKongOpenDataTime,1)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,HKColor);}
                     if ((h==TimeAdjust(HongKongOpenDataTime,2)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,HKColor);}
                  }
                     }
         if (USNews==true)
            {
               if ((h==USNewsOpenDataTime) && (m==30)) {drawvl=true;VerticalLine("NEWS",i,STYLE_DASHDOT,USNewsColor);}
               //if ((h==TimeAdjust(USNewsOpenDataTime,0)) && (m==30)) {drawvl=true;VerticalLine("NEWS",i,STYLE_DOT,USNewsColor);}
               if (t30MinAdvanceNotice==true)
                  {
                     if ((h==TimeAdjust(USNewsOpenDataTime,1)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,USNewsColor);}
                     if ((h==TimeAdjust(USNewsOpenDataTime,2)) && (m==30)) {drawvl=true;VerticalLine("",i,STYLE_DASH,USNewsColor);}
                  }
            }
      }
   return(0);
   }
//----------------------------------------------------------------------------------------------
int VerticalLine(string s,int i,int st,int Col)    //s=Text Label, i = bar, st=Line Style, Col = color
   {
   ObjectDelete("VL"+DoubleToStr(i,0));
   ObjectDelete("VLL"+DoubleToStr(i,0));// added to make sure of delete
   val1=Low[Lowest(NULL,0,MODE_LOW,BarsPerWindow(),0)];
   val2=High[Highest(NULL,0,MODE_HIGH,BarsPerWindow(),0)];
   ObjectCreate("VL"+DoubleToStr(i,0),OBJ_TREND,0,Time[i],0,Time[i],900);
   ObjectSet("VL"+DoubleToStr(i,0),OBJPROP_COLOR,Col);
   ObjectSet("VL"+DoubleToStr(i,0),OBJPROP_WIDTH,1);
   ObjectSet("VL"+DoubleToStr(i,0),OBJPROP_STYLE,st);
   ObjectSet("VL"+DoubleToStr(i,0),OBJPROP_RAY,0);
   ObjectDelete("VLL"+DoubleToStr(i,0));
   ObjectCreate("VLL"+DoubleToStr(i,0),OBJ_TEXT,0,Time[i],val2-Point*80);//val2-Point*16 Brings labels down screen 
   ObjectSetText("VLL"+DoubleToStr(i,0),s,7,"Arial",Col);               //val2+Point*3  =  Org code
    ObjectSet("VLL"+DoubleToStr(i,0), OBJPROP_ANGLE, 90);          //Rotates text 90 degrees
   ObjectsRedraw();
   return(0);
   }

int TimeAdjust(int TimeIn, int ProcessType)  
   {
      if (ProcessType==0)     //Calculate Closing Hour.  Open Hour + 9 hours
         {
            if ((TimeIn>=0) && (TimeIn<=14)){return(TimeIn+9);}
            return(TimeIn-15);
         }   
      if (ProcessType==1)     //Calculate 30MinAdvanceNotice for Opening Hour
         {
            if (TimeIn==0) {return(23);}
            return(TimeIn-1);
         }
      if (ProcessType==2)     //Calculate 30MinAdvanceNotice for Closing Hour
         {
            if ((TimeIn>=0) && (TimeIn<=15)) {return(TimeIn+8);}
            return(TimeIn-16);
         }
   }

Comments