This tool is designed to help traders visualize key price levels based on the previous day's market activity. By analyzing historical data, it automatically identifies and plots three significant price points onto your chart: the daily High, the daily Low, and the midpoint between them.
Core Functionality
The script scans through a specific number of past candles (or your entire history) to identify where one trading day ends and another begins. Once it identifies a completed day, it extracts three critical pieces of information:
- Resistance (High): The highest price reached during the previous day.
- Support (Low): The lowest price reached during the previous day.
- Pivot Point (Midpoint): The mathematical average between yesterday's High and Low.
How It Works on Your Chart
Instead of just showing you a single number, the tool draws three distinct lines across your current chart:
- The Resistance Line: Plotted at the previous day's highest price to help identify areas where selling pressure might increase.
- The Support Line: Plotted at the previous day's lowest price to help identify areas where buying interest might be strongest.
- The Midpoint Line: Plotted exactly halfway between the High and Low, providing a balanced "center of gravity" for the market.
Key Features
- Automated Calculations: The script handles all the math automatically, updating these levels every time a new day begins.
- Customizable Depth: You can choose how far back into the past the indicator should look (the number of bars to count), allowing you to focus only on recent data or your entire trading history.
- On-Screen Display: The tool includes an optional text comment that appears directly on the chart. This provides a real-time snapshot of the current High, Low, Midpoint, and the total price distance (range) between the High and Low in points.
- Timeframe Protection: To ensure accuracy, the script is designed to work only on lower timeframes (anything smaller than a Daily chart), as it relies on tracking daily transitions.
This indicator serves as a foundational tool for traders who use "Pivot Point" style analysis, helping them quickly see where the market boundaries were set during the previous session.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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; // comments on the chart (0 - no, 1 - yes)
extern int how_long=1000; // bars to be counted (-1 - all the bars)
//---- 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