DJ_Lines_v1
Download scriptThis script is designed to function as a visual trading tool that automatically identifies and maps out key price levels on your chart. Its primary purpose is to calculate and display significant "Pivot Points"—specific price boundaries that traders often use to determine where the market might face resistance (selling pressure) or support (buying interest).
The logic follows a structured sequence to ensure accurate data representation:
Core Logic & Methodology
The tool operates by analyzing historical price data from previous trading sessions to project levels for the current day. It specifically looks at three main statistics from the preceding day:
- The highest price reached (High)
- The lowest price reached (Low)
- The final price at the end of the session (Close)
How the Calculations Work
Once the script identifies a new day has started, it takes those three values from yesterday to perform a series of mathematical projections:
- Primary Pivot Point: It calculates a central "balance" point by averaging the previous day's High, Low, and Close. This serves as the baseline for the current day's price action.
- Support and Resistance Levels: Using the primary pivot, it generates several additional levels (labeled in the logic as P1, C1, P2, C2, P3, and C3). These represent various "floors" and "ceilings." For example, some levels are calculated to show where the price might struggle to break upward, while others indicate where a falling price might find enough buying interest to stop dropping.
Visual and Functional Features
- Dynamic Updating: The script scans through your historical bars (based on a user-defined length) to ensure all daily levels are drawn correctly across the timeline.
- Real-Time Monitoring: As new price data comes in, the script continuously updates the high and low of the current day, ensuring that the projected lines remain relevant to the latest market activity.
- On-Screen Information: The tool includes an optional display feature that prints a summary on your chart. This gives you a quick glance at the current High, Low, and various calculated pivot values without needing to manually hover over the lines.
- Timeframe Safety: To ensure accuracy, the script includes a built-in check to prevent it from running on daily or weekly charts, as its logic is specifically optimized for intraday trading (timeframes smaller than one day).
In summary, this script automates the complex math of Pivot Point charting, transforming raw historical data into a visual map of potential price turning points to help navigate market trends more effectively.
//+------------------------------------------------------------------+
//| DJ_Lines.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
/*
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