dayHL_v4

This script is designed to automatically identify and display key price levels based on the previous day's trading activity. It helps traders visualize historical boundaries—specifically highs, lows, and midpoints—to understand where significant price action occurred in the past.

Core Logic Overview

The indicator scans through historical price data to pinpoint the "High" and "Low" points of each trading day. Once it identifies these values for a completed day, it projects three specific levels onto your current chart:

  • Resistance Level: This is marked at the highest price reached during the previous day. It acts as a ceiling that the price may struggle to break through.
  • Support Level: This is marked at the lowest price reached during the previous day. It acts as a floor where price might find buying interest.
  • Midpoint (Pivot): The script calculates the exact halfway point between yesterday's high and low. This serves as a balanced equilibrium line for the current session.

Key Features and Behavior

  • Dynamic Updates: As each new day begins, the script automatically resets its calculations to focus on the newly completed day. It constantly monitors the highest and lowest prices of the current day to prepare for the next transition.
  • Customizable History: Users can choose how far back into the past the indicator should calculate these levels (either a specific number of bars or the entire available history).
  • Visual On-Screen Data: The script includes an optional information display that shows the exact numerical values for the current High, Low, and Midpoint directly on the chart screen.
  • Timeframe Compatibility: To ensure accuracy, the logic is designed to work on intraday charts (any timeframe smaller than one day). It will provide a warning if used on a daily or higher timeframe where these calculations would no longer be applicable.

How it assists the user

By visually plotting these lines, the script eliminates the need for manual calculation. Traders can quickly see where yesterday's "boundaries" were established and use those levels as references for potential entry points, profit targets, or areas of high volatility.

Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
dayHL_v4
//+------------------------------------------------------------------+
//| dayHL_Average.mq4                                                |
//+------------------------------------------------------------------+
/*
Name := dayHL_Average
Author := KCBT
Link := http://www.kcbt.ru/forum/index.php?
*/
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color3 Red
//---- input parameters5
extern int show_comment=1; // ðèñîâàòü ëè êîììåíòàðèé (0 - íåò, 1 - äà)
extern int how_long=1000; // ñêîëüêî áàðîâ îáðàáàòûâàòü (-1 - âñå)
//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(2, DRAW_LINE);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   Comment("");
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int cnt=0; // ñ÷åò÷èê áàðîâ
   int begin_bar=0; // áàð, ñ êîòîðîãî íà÷èíàåò ðàáîòó èíäèêàòîð
   int prev_day, cur_day; // èäåíòèôèêàòîðû òåêóùåãî è ïðåäûäóùåãî äíÿ
   double day_high=0; // äíåâíîé high
   double day_low=0; // äíåâíîé low
   double yesterday_high=0; // íàèáîëüøàÿ öåíà ïðåäûäóùåãî äíÿ
   double yesterday_low=0; // íàèìåíüøàÿ öåíà ïðåäûäóùåãî äíÿ
   double yesterday_close=0; // öåíà çàêðûòèÿ ïðåäûäóùåãî äíÿ
   double P, S, R;
   // ïðàâèëüíûå òàéìôðåìû äëÿ íàøåãî èíäèêàòîðà - âñå, ÷òî ìåíüøå D1
     if (Period()>=PERIOD_D1) 
     {
      Comment("WARNING: Invalid timeframe! Valid value < D1.");
      return(0);
     }
   // ðåøàåì ñ êàêîãî áàðà ìû íà÷íåì ñ÷èòàòü íàø èíäèêàòîð
     if (how_long==-1) 
     {
      begin_bar=Bars;
      }
       else 
      {
      begin_bar=how_long;
     }
   // îáõîäèì áàðû ñëåâà íàïðàâî (0-é áàð òîæå èñïîëüçóåì, ò.ê. èç íåãî ìû áåð¸ì òîëüêî high è low)
     for(cnt=begin_bar; cnt>=0; cnt--) 
     {
      cur_day=TimeDay(Time[cnt]);
        if (prev_day!=cur_day) 
        {
         yesterday_close=Close[cnt+1];
         yesterday_high=day_high;
         yesterday_low=day_low;
         P=(yesterday_high + yesterday_low )/2;
         R=yesterday_high;
         S=yesterday_low;
         // ò.ê. íà÷àëñÿ íîâûé äåíü, òî èíèöèèðóåì ìàêñ. è ìèí. òåêóùåãî (óæå) äíÿ
         day_high=High[cnt];
         day_low=Low[cnt];
         // çàïîìíèì äàííûé äåíü, êàê òåêóùèé
         prev_day=cur_day;
        }
      // ïðîäîëæàåì íàêàïëèâàòü äàííûå
      day_high=MathMax(day_high, High[cnt]);
      day_low=MathMin(day_low, Low[cnt]);
      // ðèñóåì pivot-ëèíèþ ïî çíà÷åíèþ, âû÷èñëåííîìó ïî ïàðàìåòðàì â÷åðàøíåãî äíÿ
      ExtMapBuffer2[cnt]=P;
      // ðèñóåì ëèíèè ñîïðîòèâëåíèÿ è ïîääåðæêè óðîâíÿ 1,2 èëè 3
      ExtMapBuffer1[cnt]=R; // ñîïðîòèâëåíèå
      ExtMapBuffer3[cnt]=S; // ïîääåðæêà
     }
     if (show_comment==1) 
     {
      P=(yesterday_high + yesterday_low )/2;
      R=yesterday_high;
      S=yesterday_low;
      Comment("Current H=", R, ", L=", S, ", HL/2=", P, ", H-L=", (R-S)/Point );
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments