Day Filling

Download script
Author: Copyright © 2021, Vladimir Karputov

This script is designed as a visual trading tool for the MetaTrader 5 platform. Its primary purpose is to provide traders with a clear, visual representation of the highest and lowest price points reached during a specific daily timeframe, making it easier to identify significant support and resistance levels.

Core Functionality

The tool identifies the "Day High" and "Day Low" prices. Instead of just displaying these as static numbers, it creates a visual "filling" effect on your chart. This helps traders see the price boundaries of the current day at a glance without having to manually check historical data.

How the Logic Works

The script operates through the following logical steps:

1. Environment Verification Before performing any calculations, the script checks if it is being used on an appropriate timeframe. It is designed to work on charts smaller than one day (such as 1-minute, 5-minute, or 1-hour charts). If a user attempts to run it on a Daily chart or higher, the script will trigger a notification alert to inform them that the timeframe is incompatible.

2. Data Synchronization The tool continuously monitors the current price action and synchronizes it with the daily data. It looks at the specific "Daily Bar" that corresponds to the time shown on your current chart. By doing this, it ensures that even if you are looking at a very small timeframe (like 1 minute), the visual boundaries remain locked to the daily high/low limits.

3. Dynamic Calculation The script performs a real-time check of the daily price movement:

  • It retrieves the opening, closing, high, and low prices for the current day.
  • It compares the daily "Open" price against the "Close" price to determine the market trend for that day.
  • It then assigns these values to two separate visual buffers (Buffer 1 and Buffer 2).

4. Visual Rendering The final result is a visual "fill" on your screen. Because it uses a filling style, it shades the area between the daily high and low. This creates a shaded zone that clearly defines the trading range for the day. As the day progresses and new highs or lows are reached, these boundaries update automatically to reflect the most recent price action.

5. Intelligent Updates The script is optimized to handle data updates smoothly. It contains logic to ensure that the visual elements do not "stretch" or display incorrectly when transitioning between different days. It clears previous data points correctly so that the transition from one trading day to the next remains clean and accurate on your chart.

Price Data Components
Miscellaneous
It issuies visual alerts to the screen
14 Views
0 Downloads
0 Favorites
Day Filling
ÿþ//+------------------------------------------------------------------+

//|                                                  Day Filling.mq5 |

//|                              Copyright © 2021, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43516 |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2021, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43516"

#property version   "1.000"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   1

//--- plot Day

#property indicator_label1  "Day"

#property indicator_type1   DRAW_FILLING

#property indicator_color1  clrLimeGreen,clrLavender

//--- indicator buffers

double   DayBuffer1[];

double   DayBuffer2[];

//---

bool     m_init_error               = false;    // error on InInit

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,DayBuffer1,INDICATOR_DATA);

   SetIndexBuffer(1,DayBuffer2,INDICATOR_DATA);

//--- INDICATOR_EMPTY_VALUE (empty value) will not participate in calculation of

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//--- set the display of the symbol

   PlotIndexSetString(0,PLOT_LABEL,"Day High;"+"Day Low;");

//---

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

//---

   if(Period()>=PERIOD_D1)

     {

      string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")?

                      "5@8>4 3@0D8:0 =5 <>65B 1KBL >= D1!":

                      "Chart period cannot be >= D1!";

      if(MQLInfoInteger(MQL_TESTER)) // when testing, we will only output to the log about incorrect input parameters

         Print(__FILE__," ",__FUNCTION__,", ERROR: ",err_text);

      else // if the Expert Advisor is run on the chart, tell the user about the error

         Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text);

      //---

      m_init_error=true;

      return(INIT_SUCCEEDED);

     }

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

   if(rates_total<10)

      return(0);

   if(m_init_error)

      return(0);

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      DayBuffer1[0]=0.0;

      DayBuffer2[0]=0.0;

      limit=1;

     }

   for(int i=limit; i<rates_total; i++)

     {

      //--- get index of the bar corresponding to the specified time (time[i])

      int bar_shift_d1=iBarShift(Symbol(),PERIOD_D1,time[i],false);

      if(bar_shift_d1<0)

         return(0);

      //--- get index of the bar corresponding to the specified time (time[i-1])

      int bar_shift_d1_prev=iBarShift(Symbol(),PERIOD_D1,time[i-1],false);

      if(bar_shift_d1_prev<0)

         return(0);

      if(bar_shift_d1!=bar_shift_d1_prev)

        {

         int d=0;

        }

      //--- gets history data PERIOD_D1

      MqlRates rates_d1[];

      ArraySetAsSeries(rates_d1,true);

      if(CopyRates(Symbol(),PERIOD_D1,bar_shift_d1,1,rates_d1)<1)

         return(0);

      //---

      if(rates_d1[0].open<rates_d1[0].close)

        {

         DayBuffer1[i]=rates_d1[0].low;

         DayBuffer2[i]=rates_d1[0].high;

        }

      else

        {

         DayBuffer1[i]=rates_d1[0].high;

         DayBuffer2[i]=rates_d1[0].low;

        }

      //---

      if(bar_shift_d1_prev!=bar_shift_d1)

        {

         DayBuffer1[i-1]=0.0;

         DayBuffer2[i-1]=0.0;

        }

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments