DJ_Lines
Download scriptThis tool is designed to provide traders with a visual map of potential support and resistance levels based on historical price action from the previous trading day. It automates the calculation of complex mathematical pivots, allowing you to see key "zones" where the price might react or reverse.
Core Logic and Functionality
The script operates by analyzing daily price extremes—specifically the highest point (High), the lowest point (Low), and the closing price—to generate a series of projected lines for the current day.
1. Data Processing The indicator scans historical data to identify when a new day begins. Once it identifies the previous day's completion, it captures three essential data points:
- Yesterday's High: The peak price reached.
- Yesterday's Low: The lowest price reached.
- Yesterday's Close: The final price at the end of the session.
2. Pivot Calculations Using these three numbers, the script calculates a "Base Pivot" (an average of the high, low, and close). From this base, it derives several distinct levels:
- Primary Pivots: These represent the immediate balance points for the current day.
- Secondary & Tertiary Levels: The script uses the relationship between the High and Low to project deeper support and resistance lines (often referred to as Pivot 2, Pivot 3, and their corresponding "C" levels).
3. Visual Representation The logic draws seven distinct lines on your chart:
- These lines act as horizontal guides.
- They represent the calculated mathematical equilibrium points for the current trading session.
- By looking at these lines, a trader can see where the "floor" (support) and "ceiling" (resistance) are likely to be based on yesterday's volatility and range.
4. User Features
- Timeframe Protection: The script includes a safety check to ensure it is only used on timeframes smaller than one day, as its logic is specifically tied to daily price transitions.
- Data Window: You can choose how far back into the past the indicator should calculate (the history depth).
- Live Dashboard: There is an optional "Comment" feature that displays the exact numerical values of these levels in the corner of your screen, allowing for quick reference without needing to hover over the lines.
Summary for the Trader
Instead of manually calculating where the price might turn, this script automatically plots a "map" of the day's territory. It takes yesterday’s behavior and projects it forward, giving you a visual guide on where significant price action is mathematically expected to occur.
//+------------------------------------------------------------------+
//| DJ_Lines.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| HiLoClose.mq4 |
//+------------------------------------------------------------------+
/*
Name := HiLoClose
Author := hawt and PUMBA
Link := hawt77@bigmir.net
*/
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 White
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Yellow
#property indicator_color5 Yellow
#property indicator_color6 LimeGreen
#property indicator_color7 LimeGreen
//---- input parameters5
extern int show_comment=1; // ðèñîâàòü ëè êîììåíòàðèé (0 - íåò, 1 - äà)
extern int how_long=1000; // ñêîëüêî áàðîâ îáðàáàòûâàòü (-1 - âñå)
//---- indicator buffers
double E2[];
double ff[];
double E4[];
double E5[];
double E6[];
double E7[];
double E8[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0, E2);
SetIndexBuffer(1, ff);
SetIndexBuffer(2, E4);
SetIndexBuffer(3, E5);
SetIndexBuffer(4, E6);
SetIndexBuffer(5, E7);
SetIndexBuffer(6, E8);
SetIndexStyle(0, DRAW_LINE,1,2);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_LINE);
SetIndexStyle(3, DRAW_LINE);
SetIndexStyle(4, DRAW_LINE);
SetIndexStyle(5, DRAW_LINE);
SetIndexStyle(6, 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, P1, P2, P3, C1, C2, C3;
// ïðàâèëüíûå òàéìôðåìû äëÿ íàøåãî èíäèêàòîðà - âñå, ÷òî ìåíüøå 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 + yesterday_close) / 3;
R = yesterday_high;
S = yesterday_low;
P1 = 2 * P - S;
C1 = 2 * P - R;
P2 = P + (P1 - C1);
C2 = P - (P1 - C1);
P3 = R + (2 * (P - S));
C3 = S - (2 * (R - P));
// ò.ê. íà÷àëñÿ íîâûé äåíü, òî èíèöèèðóåì ìàêñ. è ìèí. òåêóùåãî (óæå) äíÿ
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-ëèíèþ ïî çíà÷åíèþ, âû÷èñëåííîìó ïî ïàðàìåòðàì â÷åðàøíåãî äíÿ
E2[cnt] = P;
ff[cnt] = P1;
E4[cnt] = C1;
E5[cnt] = P2;
E6[cnt] = C2;
E7[cnt] = P3;
E8[cnt] = C3;
// ðèñóåì ëèíèè ñîïðîòèâëåíèÿ è ïîääåðæêè óðîâíÿ 1,2 èëè 3
}
if (show_comment == 1) {
P = (yesterday_high + yesterday_low + yesterday_close) / 3;
R = yesterday_high;
S = yesterday_low;
P1 = 2 * P - S;
C1 = 2 * P - R;
P2 = P + (P1 - C1);
C2 = P - (P1 - C1);
P3 = R + (2 * (P - S));
C3 = S - (2 * (R - P));
Comment("Current H=", R, ", L=", S, ", HLÑ/3=", P, " C2=", C2, ", H-L=", (R-S)/Point );
}
return(0);
}
//+-----------------------------------------------------------------
Comments