PIVOTS
Download scriptOverview of the PIVOTS Indicator Logic
The PIVOTS indicator is a technical analysis tool designed to identify key price levels on your trading chart. It automatically calculates and visualizes "Pivot Points," which are used by traders to determine potential support (where price might stop falling) and resistance (where price might stop rising) for a specific period—in this case, daily levels.
By using historical data from the previous day, the script projects these levels onto your current chart to help you visualize where significant market reactions might occur.
Core Functional Logic
1. Data Source & Filtering
The script specifically looks at the high, low, and closing prices of the previous daily session (24-hour period). It is designed to work on lower timeframes; if you attempt to use it on a timeframe larger than 4 hours, the script will not execute to ensure the data remains relevant to the daily calculations.
2. Pivot Point Calculations
The indicator generates three distinct sets of price levels:
- Standard Pivot Levels: The "Central Pivot" is the baseline, calculated as the average of the previous day's high, low, and close. From this baseline, the script calculates standard Resistance (R1, R2, R3) and Support (S1, S2, S3) levels.
- Mid-Point (M) Levels: The script further breaks down the space between the main pivots to create "Intermediate" or Mid-point levels (M0 through M5). These are calculated by finding the mathematical midpoints between the various Resistance and Support levels, providing a more granular view of the price action.
- Daily High/Low: Optionally, the script can mark the exact high and low points reached during the previous day to provide a clear boundary for the current session's range.
3. Visual Display & Customization
The logic is designed to be highly customizable through several visual features:
- Dynamic Labeling: The script places text labels on the chart (e.g., "R1", "S2", "P") so you can immediately identify which price level is which. These labels include the actual numerical price for easy reference.
- Visual Styling: You can customize the thickness, style (solid vs. dashed), and colors of both the main Pivot lines and the Mid-point lines independently.
- Time Offsets: The script includes a "Shift" logic that allows you to project these lines into the past or future on your chart, helping you align the levels with specific historical price movements.
Summary for the User
When you apply this script, it effectively takes the "footprint" of yesterday's trading activity and overlays it onto today's chart. It identifies the "floor" (Support) and "ceiling" (Resistance) that the market is likely to respect, while the additional Mid-point lines provide extra detail for traders who need more precise entry or exit zones within those larger ranges.
//+------------------------------------------------------------------+
//| PIVOTS.mq4 |
//| Copyright © 2006, cjatradingtools.com|
//+------------------------------------------------------------------+
#property copyright " By cja - http://cjatradingtools.com/"
#property indicator_chart_window
extern bool Show_PivotLines = true;
extern bool Show_M_PivotLines = true;
extern int Shift_Lines_START = -20;
extern int Shift_Lines_END = -100;
extern int SHIFT_PivotPointText = -30;
extern int SHIFT_M_PivotText = -30;
extern color PivotLabel_Col = DimGray;
extern color CentralPivot_Color = DarkSlateGray;
extern int CentralPivot_width = 2;
extern int Pivots_width = 1;
extern int Pivots_style= 0;
extern color MainLabel_Col= DimGray;
extern color R3_Color = DarkSlateGray;
extern color R2_Color = DarkSlateGray;
extern color R1_Color = DarkSlateGray;
extern color S1_Color = DarkSlateGray;
extern color S2_Color = DarkSlateGray;
extern color S3_Color = DarkSlateGray;
extern int MPivots_width = 1;
extern int MPivots_style= 2;
extern color MLabel_Col = DimGray;
extern color M5_Color = DarkSlateGray;
extern color M4_Color = DarkSlateGray;
extern color M3_Color = DarkSlateGray;
extern color M2_Color = DarkSlateGray;
extern color M1_Color = DarkSlateGray;
extern color M0_Color = DarkSlateGray;
extern bool Show_Daily_HILOW = false;
#define PP1 "PP1"
#define RR3 "RR3"
#define RR2 "RR2"
#define RR1 "RR1"
#define SS1 "SS1"
#define SS2 "SS2"
#define SS3 "SS3"
#define MM1 "MM1"
#define MM2 "MM2"
#define MM3 "MM3"
#define MM4 "MM4"
#define MM5 "MM5"
#define MM0 "MM0"
#define HI "DailyHI"
#define LO "DailyLO"
double x;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorShortName("PIVOTS");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete(PP1);ObjectDelete(RR3); ObjectDelete(RR3);ObjectDelete(RR2); ObjectDelete(RR1);ObjectDelete(SS1);
ObjectDelete(SS2);ObjectDelete(SS3);ObjectDelete(MM1);ObjectDelete(MM2);ObjectDelete(MM3);ObjectDelete(MM4);
ObjectDelete(MM5); ObjectDelete(MM0);
ObjectDelete(HI);ObjectDelete(LO);
ObjectDelete("P");ObjectDelete("R3"); ObjectDelete("R2"); ObjectDelete("R1");ObjectDelete("S1");
ObjectDelete("S2");ObjectDelete("S3");ObjectDelete("M1");ObjectDelete("M2");ObjectDelete("M3");ObjectDelete("M4");
ObjectDelete("M5"); ObjectDelete("M0");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars= IndicatorCounted();
x = Period();
if(x > 240) return(-1);
//----
CreatePVT();
}
void CreatePivot(string Pivot, double start, double end,double w, double s,color clr)
{
ObjectCreate(Pivot, OBJ_TREND, 0, CustomTime(Shift_Lines_END), start, CustomTime(Shift_Lines_START), end);
ObjectSet(Pivot, OBJPROP_COLOR, clr);
ObjectSet(Pivot,OBJPROP_RAY,false);
ObjectSet(Pivot,OBJPROP_WIDTH,w);
ObjectSet(Pivot,OBJPROP_STYLE,s);
}
void DeletePivot()
{
ObjectDelete(PP1); ObjectDelete(RR3); ObjectDelete(RR2); ObjectDelete(RR1); ObjectDelete(SS1); ObjectDelete(SS2);
ObjectDelete(SS3);
ObjectDelete(MM1); ObjectDelete(MM2); ObjectDelete(MM3); ObjectDelete(MM4); ObjectDelete(MM5); ObjectDelete(MM0);
ObjectDelete(HI);ObjectDelete(LO);
}
void CreatePVT()
{
DeletePivot();
double P = (iHigh(NULL,1440,1) + iLow(NULL,1440,1) + iClose(NULL,1440,1)) / 3;
double rr3 = ( 2 * P ) + ( iHigh(NULL,1440,1) - ( 2 * iLow(NULL,1440,1) ));
double rr2 = P + ( iHigh(NULL,1440,1) - iLow(NULL,1440,1) );
double rr1 = ( 2 * P ) - iLow(NULL,1440,1);
double ss1 = ( 2 * P ) - iHigh(NULL,1440,1);
double ss2 = P - ( iHigh(NULL,1440,1)- iLow(NULL,1440,1));
double ss3 = ( 2 * P ) - ( ( 2 * iHigh(NULL,1440,1) ) - iLow(NULL,1440,1) );
double mm0 = (ss2 + ss3)/2;
double mm1 = (ss1 + ss2)/2;
double mm2 = (P + ss1)/2;
double mm3 = (P + rr1)/2;
double mm4 = (rr1 + rr2)/2;
double mm5 = (rr2 + rr3)/2;
double D_HI=iHigh(NULL,1440,1);
double D_LO=iLow(NULL,1440,1);
{
if (Show_PivotLines==true)
{
ObjectDelete("P");
if(ObjectFind("P") != 0){
ObjectCreate("P", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), P);
ObjectSetText("P", "Pivot "+DoubleToStr(P,Digits)+"", 8, "Arial", PivotLabel_Col);
}else{ObjectMove("P", 0, CustomTime(SHIFT_PivotPointText), P);}
ObjectDelete("S3");
if(ObjectFind("S3") != 0){
ObjectCreate("S3", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), ss3);
ObjectSetText("S3", "S3 "+DoubleToStr(ss3,Digits)+"", 8, "Arial", MainLabel_Col);
}else{ObjectMove("S3", 0, CustomTime(SHIFT_PivotPointText), ss3);}
ObjectDelete("S2");
if(ObjectFind("S2") != 0){
ObjectCreate("S2", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), ss2);
ObjectSetText("S2", "S2 "+DoubleToStr(ss2,Digits)+"", 8, "Arial", MainLabel_Col);
}else{ObjectMove("S2", 0, CustomTime(SHIFT_PivotPointText), ss2);}
ObjectDelete("S1");
if(ObjectFind("S1") != 0){
ObjectCreate("S1", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), ss1);
ObjectSetText("S1", "S1 "+DoubleToStr(ss1,Digits)+"", 8, "Arial", MainLabel_Col);
}else{ObjectMove("S1", 0, CustomTime(SHIFT_PivotPointText), ss1);}
ObjectDelete("R1");
if(ObjectFind("R1") != 0){
ObjectCreate("R1", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), rr1);
ObjectSetText("R1", "R1 "+DoubleToStr(rr1,Digits)+"", 8, "Arial", MainLabel_Col);
}else{ObjectMove("R1", 0, CustomTime(SHIFT_PivotPointText), rr1);}
ObjectDelete("R2");
if(ObjectFind("R2") != 0){
ObjectCreate("R2", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), rr2);
ObjectSetText("R2", "R2 "+DoubleToStr(rr2,Digits)+"", 8, "Arial", MainLabel_Col);
}else{ObjectMove("R2", 0, CustomTime(SHIFT_PivotPointText), rr2);}
ObjectDelete("R3");
if(ObjectFind("R3") != 0){
ObjectCreate("R3", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), rr3);
ObjectSetText("R3", "R3 "+DoubleToStr(rr3,Digits)+"", 8, "Arial", MainLabel_Col);
}else{ObjectMove("R3", 0, CustomTime(SHIFT_PivotPointText), rr3);}
}
if (Show_M_PivotLines==true)
{
ObjectDelete("M5");
if(ObjectFind("M5") != 0){
ObjectCreate("M5", OBJ_TEXT, 0, CustomTime(SHIFT_M_PivotText), mm5);
ObjectSetText("M5", "M5 "+DoubleToStr(mm5,Digits)+"", 8, "Arial", MLabel_Col);
}else{ObjectMove("M5", 0, CustomTime(SHIFT_M_PivotText), mm5);}
ObjectDelete("M4");
if(ObjectFind("M4") != 0){
ObjectCreate("M4", OBJ_TEXT, 0, CustomTime(SHIFT_M_PivotText), mm4);
ObjectSetText("M4", "M4 "+DoubleToStr(mm4,Digits)+"", 8, "Arial", MLabel_Col);
}else{ObjectMove("M4", 0, CustomTime(SHIFT_M_PivotText), mm4);}
ObjectDelete("M3");
if(ObjectFind("M3") != 0){
ObjectCreate("M3", OBJ_TEXT, 0, CustomTime(SHIFT_M_PivotText), mm3);
ObjectSetText("M3", "M3 "+DoubleToStr(mm3,Digits)+"", 8, "Arial", MLabel_Col);
}else{ObjectMove("M3", 0, CustomTime(SHIFT_M_PivotText), mm3);}
ObjectDelete("M2");
if(ObjectFind("M2") != 0){
ObjectCreate("M2", OBJ_TEXT, 0, CustomTime(SHIFT_M_PivotText), mm2);
ObjectSetText("M2", "M2 "+DoubleToStr(mm2,Digits)+"", 8, "Arial", MLabel_Col);
}else{ObjectMove("M2", 0, CustomTime(SHIFT_M_PivotText), mm2);}
ObjectDelete("M1");
if(ObjectFind("M1") != 0){
ObjectCreate("M1", OBJ_TEXT, 0, CustomTime(SHIFT_M_PivotText), mm1);
ObjectSetText("M1", "M1 "+DoubleToStr(mm1,Digits)+"", 8, "Arial", MLabel_Col);
}else{ObjectMove("M1", 0, CustomTime(SHIFT_M_PivotText), mm1);}
ObjectDelete("M0");
if(ObjectFind("M0") != 0){
ObjectCreate("M0", OBJ_TEXT, 0, CustomTime(SHIFT_M_PivotText), mm0);
ObjectSetText("M0", "M0 "+DoubleToStr(mm0,Digits)+"", 8, "Arial", MLabel_Col);
}else{ObjectMove("M0", 0, CustomTime(SHIFT_M_PivotText), mm0);}
}
if(Show_Daily_HILOW==true){
CreatePivot(HI,D_HI,D_HI,1,2, Lime);
CreatePivot(LO,D_LO,D_LO,1,2, Red);}
CreatePivot(PP1,P,P,CentralPivot_width,0,CentralPivot_Color);
CreatePivot(RR3,rr3,rr3,Pivots_width,Pivots_style, R3_Color );
CreatePivot(RR2,rr2,rr2,Pivots_width,Pivots_style, R2_Color );
CreatePivot(RR1,rr1,rr1,Pivots_width,Pivots_style, R1_Color );
CreatePivot(SS1,ss1,ss1,Pivots_width,Pivots_style, S1_Color);
CreatePivot(SS2,ss2,ss2,Pivots_width,Pivots_style, S2_Color);
CreatePivot(SS3,ss3,ss3,Pivots_width,Pivots_style, S3_Color);
}
if (Show_M_PivotLines==true)
{
CreatePivot(MM1,mm1,mm1,MPivots_width,MPivots_style, M1_Color);
CreatePivot(MM2,mm2,mm2,MPivots_width,MPivots_style, M2_Color);
CreatePivot(MM3,mm3,mm3,MPivots_width,MPivots_style, M3_Color);
CreatePivot(MM4,mm4,mm4,MPivots_width,MPivots_style, M4_Color);
CreatePivot(MM5,mm5,mm5,MPivots_width,MPivots_style, M5_Color);
CreatePivot(MM0,mm0,mm0,MPivots_width,MPivots_style, M0_Color);
}
//----
return(0);
}
int CustomTime(int a)
{
if(a<0)
return(Time[0]+Period()*60*MathAbs(a));
else return(Time[a]);
}
//+------------------------------------------------------------------+
Comments