Affichage JOUR

Author: � RickD 2006
Affichage JOUR

This script is a visual enhancement tool designed for the MetaTrader platform. Its primary purpose is to improve chart readability by automatically labeling and highlighting different trading days, allowing users to quickly identify chronological periods on their price charts.

Core Functionality

The script organizes your trading screen by identifying when a new day begins. It performs two main visual tasks:

  • Day Labeling: It identifies the start of each day and places a text label (such as "mon", "tue", etc., depending on the language settings) at the top of the chart. Each day is assigned a specific color, making it easy to distinguish between different trading sessions at a glance.
  • Visual Zoning (Background Boxes): For certain timeframes (specifically lower than 4-hour charts), the script draws semi-transparent rectangular blocks that span the entire duration of a single day. These boxes highlight the high and low price ranges for that specific 24-hour period, providing a clear visual "zone" for each day's activity.

Key Features & Customization

The script is designed to be highly flexible, allowing users to customize the visual layout without needing to modify any underlying logic:

  • Customizable Visibility: You can choose to show or hide specific days of the week if you only want to monitor certain trading windows.
  • Visual Formatting: Users can modify the font size, font type, and the specific colors used for both the text labels and the background boxes to match their preferred aesthetic or color-coding system.
  • Timeframe Awareness: The script is intelligent enough to recognize your current chart timeframe. It automatically calculates how many bars represent a full day (based on minutes, 15-minute blocks, hours, etc.) to ensure the boxes are drawn accurately regardless of whether you are viewing M1, H1, or H4 charts.
  • Automated Cleanup: The script includes a management system that ensures old labels and boxes are cleared properly when the indicator is removed or reset, preventing your chart from becoming cluttered with obsolete data.

Target Audience Benefit

For a trader, this tool simplifies the navigation of historical data. Instead of manually counting bars to figure out which day you are looking at, the script provides an immediate, color-coded map of the trading week. It helps in identifying daily price action ranges and provides a cleaner, more organized environment for technical analysis.

9 Views
0 Downloads
0 Favorites
Affichage JOUR
//+------------------------------------------------------------------+
//|                                               Affichage JOUR.mq4 |
//|                            Copyright © 2007, GwadaTradeBoy Corp. |
//|                                            racooni_1975@yahoo.fr |
//+------------------------------------------------------------------+
//|                                                      i-5days.mq4 |
//|                                          Copyright © 2007, RickD |
//|                                                   www.e2e-fx.net |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, GwadaTradeBoy Corp."
#property link      "racooni_1975@yahoo.fr"
#property copyright "© RickD 2006"
#property link      "www.e2e-fx.net"

//----
#define major   1
#define minor   0

//----
#property indicator_chart_window

extern string __1__ = "";
extern int MaxDays = 20;
extern int FontSize = 16;
extern string FontName = "System";
extern int Offset = 16;
extern string __2__ = "";
/*//--- Français
extern string Text1 = "Lun";
extern string Text2 = "Mar";
extern string Text3 = "Mer";
extern string Text4 = "Jeu";
extern string Text5 = "Ven";
--- English
extern string Text1 = "mon";
extern string Text2 = "tue";
extern string Text3 = "wed";
extern string Text4 = "thu";
extern string Text5 = "fri";*/
//--- Portuguese-Brazilian
extern string Text1 = "seg";
extern string Text2 = "ter";
extern string Text3 = "qua";
extern string Text4 = "qui";
extern string Text5 = "sex";

extern string __3__ = "";
extern color Color1 = DodgerBlue;
extern color Color2 = DeepPink;
extern color Color3 = ForestGreen;
extern color Color4 = FireBrick;
extern color Color5 = MediumPurple;
extern string __4__ = "";
extern bool ShowDay1 = true;
extern bool ShowDay2 = true;
extern bool ShowDay3 = true;
extern bool ShowDay4 = true;
extern bool ShowDay5 = true;
extern string __5__ = "";
extern bool ShowDayBox = true;
extern color DayColor1 = SkyBlue;
extern color DayColor2 = Pink;
extern color DayColor3 = SpringGreen;
extern color DayColor4 = LightCoral;
extern color DayColor5 = Plum;
//----
string Text[5];
color Color[5];
bool ShowDay[5];
string prefix = "5days_";

//---- Variables - Affichage jour
int P, cnt, i, res, day;
string name = "";

//---- Variables - Affichage rectangle
datetime       DateTrade, TimeBeginObject, TimeEndObject;
int            counted_bars, BarBegin, BarEnd, ResObject;
double         PriceHighObject, PriceLowObject;
string         NameObject;
color          DayColor[5];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
   {
//---- indicators
      Text[0] = Text1;
      Text[1] = Text2;
      Text[2] = Text3;
      Text[3] = Text4;
      Text[4] = Text5;
//----  
      Color[0] = Color1;
      Color[1] = Color2;
      Color[2] = Color3;
      Color[3] = Color4;
      Color[4] = Color5;
      DayColor[0] = DayColor1;
      DayColor[1] = DayColor2;
      DayColor[2] = DayColor3;
      DayColor[3] = DayColor4;
      DayColor[4] = DayColor5;
//----
      ShowDay[0] = ShowDay1;
      ShowDay[1] = ShowDay2;
      ShowDay[2] = ShowDay3;
      ShowDay[3] = ShowDay4;
      ShowDay[4] = ShowDay5;
//----
      clear();
//----
      return(0);
   }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
   {
//----
      clear();
//----
      return(0);
   }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
   {
      counted_bars=IndicatorCounted();
      P = Period();
//----
      if(P > PERIOD_D1) 
         return;
      cnt = MathMin(Bars, PERIOD_D1 / P * MaxDays);
      for(i=0; i < cnt; i++) 
         {
            if(TimeDayOfWeek(Time[i]) != TimeDayOfWeek(Time[i+1]))
               {
                  name = prefix + TimeToStr(Time[i]);
                  res = ObjectFind(name);
                  if(res == -1) 
                     {      
                        day = TimeDayOfWeek(Time[i]);
                        if(!ShowDay[day-1]) 
                           continue;
                        ObjectCreate(name, OBJ_TEXT, 0, Time[i], High[i] + Offset * Point);
                        ObjectSetText(name, Text[day-1], FontSize, FontName, Color[day-1]); 
                     }
                  if(ShowDayBox && P <= PERIOD_H4)
                     {
//---- Définition des variables
                        NameObject = "DayBox"+i;
                        DateTrade = TimeCurrent();
//---- Calcul des valeurs courantes
                        TimeBeginObject = Time[i];
                        switch(Period()) {
                           case PERIOD_M1:
                              TimeEndObject = Time[i+1440]; break;
                           case PERIOD_M5:
                              TimeEndObject = Time[i+288]; break;
                           case PERIOD_M15:
                              TimeEndObject = Time[i+96]; break;
                           case PERIOD_M30:
                              TimeEndObject = Time[i+48]; break;
                           case PERIOD_H1:
                              TimeEndObject = Time[i+24]; break;
                           case PERIOD_H4:
                              TimeEndObject = Time[i+6]; break;
                        }
                        BarBegin=iBarShift(NULL, 0, TimeBeginObject);
                        BarEnd=iBarShift(NULL, 0, TimeEndObject);
                        PriceHighObject = High[iHighest(NULL, 0, MODE_HIGH, BarBegin - BarEnd, BarEnd)];
                        PriceLowObject=Low [iLowest (NULL, 0, MODE_LOW , BarBegin - BarEnd, BarEnd)];
//---- Dessin du rectangle
                        ObjectCreate(NameObject, OBJ_RECTANGLE, 0, TimeBeginObject, PriceHighObject, TimeEndObject, PriceLowObject);
                        ObjectSet(NameObject, OBJPROP_STYLE, STYLE_SOLID);
                        ObjectSet(NameObject, OBJPROP_COLOR, DayColor[day-1]);
                        ObjectSet(NameObject, OBJPROP_BACK, True);
                     }
               }
         }
//----
      return(0);
   }
//+------------------------------------------------------------------+
//----
void clear() 
   {
      P = Period();
      if(P > PERIOD_D1) 
         return;
      cnt = MathMin(Bars, PERIOD_D1 / P * MaxDays);
      for(i=0; i < cnt; i++) 
         {
            name = prefix + TimeToStr(Time[i]);
            NameObject = "DayBox"+i;
            res = ObjectFind(name);
            ResObject = ObjectFind(NameObject);
            if(res != -1) 
               ObjectDelete(name);
            if(ResObject != -1) 
               ObjectDelete(NameObject);
         }
   }

Comments