Pivot_RS_session
Download scriptThis script is designed as a technical analysis tool for the MetaTrader platform. Its primary purpose is to automatically identify and plot key price levels—specifically Pivot Points, Support, and Resistance zones—based on historical price action from a specific time window each day.
Core Logic Overview
The script operates by looking back at a predefined period of trading activity to calculate where significant "turning points" in the market might occur. It simplifies complex price movements into three main components: the highest price reached, the lowest price reached, and the closing price during a specific timeframe.
How the Calculation Works
-
Timeframe Identification: The tool looks at a specific window of time (defined by the user, such as a 9-hour period). It adjusts for different time zones to ensure that the data being analyzed corresponds to the correct market session (like the Asian or American sessions).
-
Data Extraction: During this identified window, the script scans the price history to find three critical values:
- High (H): The highest price reached during that period.
- Low (L): The lowest price reached during that period.
- Close (C): The price at which the market closed at the very beginning of the period.
-
Pivot Point Calculation: The script uses these three values to calculate a "Pivot Point" (P). This is essentially the mathematical average of the High, Low, and Close prices, representing the central balance point of that trading session.
-
Support and Resistance Generation: Once the Pivot Point is established, the script applies a standard formula to project six additional levels:
- Resistance Levels (R1, R2, R3): These represent potential ceilings where the price might face selling pressure.
- Support Levels (S1, S2, S3): These represent potential floors where the price might find buying interest.
Visual Display Options
The script provides two distinct ways to view this data on your trading chart depending on your preference:
- Mode 1 (High Visibility): If configured for "Visible" mode, the chart will highlight the extreme High and Low points, the Pivot Point, and the closing price. It also draws vertical lines to clearly mark the start and end of the analyzed time period.
- Mode 2 (Technical Levels): If configured for the standard Support/Resistance view, the script hides the individual highs and lows and instead plots the full grid of six levels (R1-R3 and S1-S3) along with the central Pivot Point. This provides a roadmap of potential zones where price action may reverse or stall in the future.
Summary for the User
Essentially, this tool automates the "manual math" traders usually do at the start of a session. Instead of you having to calculate where the support and resistance levels are based on yesterday's highs and lows, the script identifies those boundaries automatically and draws them on your screen as clear visual guides.
//+------------------------------------------------------------------+
//| Akcel_RS_9_session.mq |
//| Copyright © 2006, dvyu@mail.ru |
//| http://www..net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, DVYU inc."
#property link "http://www..net"
//----
#property indicator_chart_window
//----
extern int GOfset=0;//ðàçíèöà âðåìåíè ÄÖ è GMT.
extern int GOfset_m=0; //0-60 ìèí.
extern int Visible=0;
extern string Tstart="01:00:00";
extern int period=9;
//extern int t=9;
string TD,TD1;
datetime td,end_time,go_time,ten;
string timeGo,timeEnd,te,tg;
double H,L,C,P;
double R1,R2,R3,S1,S2,S3;
int D,n;
string Tgo,Ten;
//C÷èòàåì ïèâîò è óðîâíè çà ïðåäûäóùóþ ñåññèþ, äëÿ àçèè- àìåðèêà,
//äëÿ åâðîïû àçèÿ, äëÿ àìåðèêè êîíåö àçèè è åâðîïà
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
ObjectDelete("Pivot");
ObjectDelete("C");
ObjectDelete("Ï");
ObjectDelete("R11");
ObjectDelete("R12");
ObjectDelete("R13");
ObjectDelete("S11");
ObjectDelete("S12");
ObjectDelete("S13");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("P");
ObjectDelete("C");
ObjectDelete("Ï");
ObjectDelete("Start1");
ObjectDelete("End1");
ObjectDelete("R11");
ObjectDelete("R12");
ObjectDelete("R13");
ObjectDelete("S11");
ObjectDelete("S12");
ObjectDelete("S13");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{D=DayOfWeek();
if(D==1)n=3;
else
n=1;
//Print("NN",n);
//Print("DAY",D);
TD1=TimeToStr(CurTime(),TIME_DATE);
td=StrToTime(TD1);//-24*60*60;
TD=TimeToStr(td,TIME_DATE);
//
int T_Hour=TimeHour(CurTime());
//Print(T_Hour);
if(T_Hour>0&&T_Hour<23)
{Tgo=Tstart;
tg=StringConcatenate(TD," ",Tgo);
ten=StrToTime(TD1)-period*60*60;
Ten=TimeToStr(ten);
}
//Óñòàíàâëèâàåì âðåìÿ
string timeGo=Tgo;
tg=StringConcatenate(TD," ",Tgo);
//----
datetime td1=StrToTime(tg)-GOfset*60*60-GOfset_m*60;
string t1=TimeToStr(td1,TIME_DATE|TIME_MINUTES);
go_time=StrToTime(t1);
end_time=StrToTime(Ten);
//**********************************************************
//Íàõîäèì íà÷àëüíûé áàð - íîìåð áàðà îò òåêóùåãî
int BarGo=iBarShift(NULL,0,go_time,false);
//Print( "BarGo",BarGo);
//Íàõîäèì áàð 06:00 GMT
int BarEnd=iBarShift(NULL,0,end_time,false);
//Print("BarEnd",BarEnd);
//**********************************************************
//Íàõîäèì áàð ñ âûñøåé öåíîé
int h=Highest(NULL,0,MODE_HIGH,BarEnd-BarGo,BarGo);
//Íàõîäèì ñîáñòâåííî öåíó High
H=iHigh(NULL,0,h);
//Print("H day",H);
//Àíàëîãè÷íî äëÿ íèçøåé öåíû Low
int l=Lowest(NULL,0,MODE_LOW,BarEnd-BarGo,BarGo);
L=iLow(NULL,0,l);
//Print("L day",L);
//Íàõîäèì öåíó çàêðûòèÿ íà 6:00 GMT
C=iClose(NULL,0,BarGo);
//Íàõîäèì êîîðäèíàòó ëèíèè ðàçâîðîòà:
//Print("Close"," ",C);
P=NormalizeDouble((L+H+C)/3,4);
//*******************************************************+
//Âû÷èñëÿåì R & S;
R1=2*P-L;
S1=2*P-H;
R2=P+(H-L);
R3=2*P-2*L+H;
S2=P-H+L;
S3=2*P-2*H+L;
//Ðèñóåì ëèíèè:Eñëè Visible=1, ðàçâîðîò, õàé è ëîó äíÿ,
//Åñëè Visible==0, ðèñóåì ïîääåðæêó è ñîïðîòèâëåíèå.
//Print("Close",C);
if (Visible==1)
{
ObjectCreate("Pivot",OBJ_HLINE,0,0,C);//Close
ObjectCreate("Ï",OBJ_HLINE,0,0,L);//Ïîääåðæêà
ObjectCreate("C",OBJ_HLINE,0,0,H);//Ñîïðîòèâëåíèå
ObjectCreate("Start1",OBJ_VLINE,0,go_time,0);//Íà÷àëî ïåðèîäà 00:00 GMT
ObjectCreate("End1",OBJ_VLINE,0,end_time,0);// Êîíåö ïåðèîäà 06:00 GMT
ObjectSet( "Start1",OBJPROP_COLOR,Blue);
ObjectSet( "End1",OBJPROP_COLOR,Blue );
ObjectSet( "Pivot",OBJPROP_COLOR,DarkBlue );
ObjectSet( "C",OBJPROP_COLOR,Gold );
ObjectSet( "Ï",OBJPROP_COLOR,CornflowerBlue);
ObjectSet("Start1",OBJPROP_WIDTH,1);
ObjectSet("End1",OBJPROP_WIDTH,1);
ObjectSet("Pivot",OBJPROP_WIDTH,2);
ObjectSet("Ï",OBJPROP_WIDTH,2);
ObjectSet("C",OBJPROP_WIDTH,2);
ObjectsRedraw();
}
if (Visible==0)
//*******************************************************************+
//Ðèñóåì Support & Resistance
{
ObjectCreate("Pivot",OBJ_HLINE,0,go_time,P);//Ëèíèÿ ðàçâîðîòà
ObjectCreate("R11",OBJ_HLINE,0,go_time,R1);
ObjectCreate("R12",OBJ_HLINE,0,go_time,R2);
ObjectCreate("R13",OBJ_HLINE,0,go_time,R3);
ObjectCreate("S11",OBJ_HLINE,0,go_time,S1);
ObjectCreate("S12",OBJ_HLINE,0,go_time,S2);
ObjectCreate("S13",OBJ_HLINE,0,go_time,S3);
ObjectCreate("Start1",OBJ_VLINE,0,go_time,0);//Íà÷àëî ïåðèîäà 00:00 GMT
ObjectCreate("End1",OBJ_VLINE,0,end_time,0);// Êîíåö ïåðèîäà 06:00 GMT
ObjectSet( "Start1",OBJPROP_COLOR,Blue);
ObjectSet( "End1",OBJPROP_COLOR,Blue );
ObjectSet( "Pivot",OBJPROP_COLOR,DarkBlue );
ObjectSet( "R11",OBJPROP_COLOR,DarkOrange);
ObjectSet( "R12",OBJPROP_COLOR,DarkOrange);
ObjectSet( "R13",OBJPROP_COLOR,DarkOrange);
ObjectSet( "S11",OBJPROP_COLOR,DarkOrange);
ObjectSet( "S12",OBJPROP_COLOR,DarkOrange);
ObjectSet( "S13",OBJPROP_COLOR,DarkOrange);
ObjectSet("Start1",OBJPROP_WIDTH,1);
ObjectSet("End1",OBJPROP_WIDTH,1);
ObjectSet("Pivot",OBJPROP_WIDTH,2);
ObjectsRedraw();
}
return(0);
}
//+------------------------------------------------------------------+
Comments