Author: AP
DayBorders

This script is designed to automatically enhance your trading chart by visually marking the boundaries of the previous calendar day. It simplifies the way you view historical price action by clearly defining where yesterday started and ended, as well as the key price levels reached during that period.

How the Logic Works:

1. Automated Time Detection The script identifies the current time and calculates the specific start and end points of the most recent completed calendar day. It automatically adjusts for weekends to ensure that the data remains accurate even when the market is closed.

2. Vertical Boundary Markers It places two distinct vertical lines on your chart:

  • DayTimeOpen: Marks the exact moment the previous trading day began.
  • DayTimeClose: Marks the exact moment the previous trading day ended.

3. Horizontal Price Levels In addition to time, the script identifies critical price points from the previous session:

  • DayOpen: A horizontal line representing the opening price of the previous day.
  • DayClose: A horizontal line representing the closing price of the previous day.

4. Dynamic Visual Indicators To help you instantly understand the market sentiment of the previous day, the script includes a "directional" labeling system:

  • If the previous day closed higher than it opened (a bullish trend), specific symbols are displayed on the lines to indicate an upward movement.
  • If the previous day closed lower than it opened (a bearish trend), different symbols are used to indicate a downward movement.

5. Visual Organization The script uses a pre-defined color scheme to keep your chart organized:

  • Time boundaries are marked in Green.
  • The Opening price level is highlighted in Green.
  • The Closing price level is highlighted in Purple.

By using this tool, you can quickly assess the "range" of the previous day at a glance, allowing for better identification of support/resistance levels and daily price trends without having to manually search through historical data.

7 Views
0 Downloads
0 Favorites
DayBorders
//+------------------------------------------------------------------+
//|                                                    DayBorders.mq4 |
//|                                            Aleksandr Pak, Almaty |
//|                                                   ekr-ap@mail.ru |
//+------------------------------------------------------------------+
#property copyright " AP"
#property link      "ekr-ap@mail.ru"
//------------------------------------------------------------------+
/*
Ñêðèïò ðèñóåò ãðàíèöû ïðåäûäóùåãî êàëåíäàðíîãî äíÿ.
Âåðòèêàëüíûå ëèíèè ïðåäûäóùåãî äíÿ ñ ôèêñèðîâàííûìè èìåíàìè DayTimeOpen DayTimeClose
Ãîðèçîíòàëüíûå ëèíèè ñ ôèêñèðîâàííûìèè èìåíàìè DayOpen DayClose
Öâåòà ëèíèé óñòàíàâëèâàþòñÿ ïðè êîìïèëÿöèè.
*/
/*
The script draws borders of the last calendar day.
Vertical lines of the last day with fixed names DayTimeOpen DayTimeClose
Horizontal lines with fixed names DayOpen DayClose
Colors of lines of borders are set at compilation.
*/
color color_Time=Green, color_DayOpen=Green,color_DayClose=Purple; //Set colors of lines

int start()
  {
datetime day=24*60*60;
datetime r=(TimeCurrent()/day)*day;
int      cd=iBarShift(NULL,0,r,FALSE);
datetime r2=r-day;

if(TimeDayOfWeek(r2)==0) r2=r2-day-day;
int cd2=iBarShift(NULL,0,r2,FALSE);

                     if(ObjectFind("DayTimeClose")==-1)    
                              {ObjectCreate  ("DayTimeClose",OBJ_VLINE,0,r,0);                               
                              }
                   else        ObjectSet     ("DayTimeClose",OBJPROP_TIME1,r);
                     if(ObjectFind("DayTimeOpen")==-1)      
                              {ObjectCreate  ("DayTimeOpen",OBJ_VLINE,0,r2,0);                               
                              }
                     else     ObjectSet      ("DayTimeOpen",OBJPROP_TIME1,r2);
                     
if(ObjectFind("DayOpen")==-1)          {ObjectCreate("DayOpen",OBJ_HLINE,0,0,Open[cd2]);                                       
                                       }
                              else     ObjectSet("DayOpen",OBJPROP_PRICE1,Open[cd2]);

if(ObjectFind("DayClose")==-1)          {ObjectCreate("DayClose",OBJ_HLINE,0,0,Close[cd]);                                       
                                       }                                       
                              else     ObjectSet("DayClose",OBJPROP_PRICE1,Open[cd]);
                              
                if(Open[cd2]<Close[cd]) {ObjectSetText("DayOpen","^"); 
                                       ObjectSetText("DayClose","^");
                                          }
                else {ObjectSetText("DayOpen","V");
                     ObjectSetText("DayClose","V");
                     }                              
                              ObjectSet     ("DayTimeClose",OBJPROP_COLOR,color_Time);
                              ObjectSet     ("DayTimeOpen",OBJPROP_COLOR,color_Time);
                              ObjectSet("DayOpen",OBJPROP_COLOR,color_DayOpen);
                              ObjectSet("DayClose",OBJPROP_COLOR,color_DayClose);                                                         
   return(0);
  }
//+------------------------------------------------------------------+

Comments