Pivot_Star
Download scriptThis script is designed to function as a dynamic visual guide for traders, providing automated "Pivot Point" levels on a trading chart. Pivot points are used by market participants to identify potential areas of support (where prices might stop falling) and resistance (where prices might stop rising).
Core Functionality
The tool automatically calculates and draws several key price levels based on historical data from specific timeframes (such as hourly, daily, or weekly). Instead of manually calculating these figures, the script does the math in the background and places visual lines on your screen.
Key Features and Logic
1. Multiple Calculation Methods The script is versatile and allows users to switch between five different professional forecasting models:
- Standard: The traditional calculation for pivot points.
- Fibonacci: Uses the golden ratio proportions to determine levels.
- Camarilla: A popular method used by day traders to identify breakout levels.
- Woodie’s: A variation that places more weight on the closing price of a period.
- Demark: A calculation that varies based on whether the market closed higher or lower than it opened.
2. Dynamic Visual Indicators
- Support and Resistance Lines: It identifies several levels (labeled R1, R2, R3 for Resistance and S1, S2, S3 for Support).
- Previous Day Context: If enabled, the script also marks the High and Low prices from the previous day, helping traders see where "big money" might have moved yesterday.
- Customizable Aesthetics: Users can choose the colors, thickness, and line styles of each level to suit their personal visual preferences.
3. Real-Time Status Dashboard One of the unique features of this script is the "Label" system. It creates a text dashboard on the corner of your chart that:
- Identifies exactly which calculation mode and timeframe are currently active.
- Displays the numerical value of every price level.
- Directional Cues: It includes an intelligent pointer (like ">" or "<") that moves automatically based on the current market price. This tells you at a glance which zone the price is currently in relative to the pivot points.
4. Smart Display Logic The script is programmed to be "context-aware." For example, if you are looking at a very small timeframe (like 1-minute charts), it may simplify the display to avoid cluttering your screen, ensuring that only the most relevant information is shown based on the period you have selected.
Summary for the User
Essentially, this script acts as an automated "map" for your chart. It takes complex mathematical formulas used by professional traders, calculates them instantly based on your chosen timeframe, and draws a clean, color-coded map of where price might struggle to move next, while providing a live text readout of those values in the corner of your screen.
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2012, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
/*
Created by Asteris, modified by Cubicrey [March, 2010]
Website: http://www.indo-investasi.com
Converted to Pivot Star by rkdius [Dec 2016]
*/
#property version "1.2"
#property strict
#property indicator_chart_window
//--- input parameters
enum mode
{
Standard,
Fibonacci,
Camarilla,
Woodie,
Demark
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
enum lbCorner
{
TopLeft=0, // Top Left
TopRight=1, // Top Right
BottomLeft=2, // Bottom Left
BottomRight=3 // Bottom Right
};
extern mode Pmode = Standard; // Pivot Mode
extern ENUM_TIMEFRAMES inpPeriod = PERIOD_H1; // Pivot Time Frame
extern bool HLINE = false; // Full Horizontal Lines
extern int xShift = 3; // X-Axis Shift
extern int xLen = 25; // Line Length
extern lbCorner LabelCorner = TopRight; // Label Corner
extern color LevelPP = SpringGreen; // Pivot Point
extern ENUM_LINE_STYLE StylePP = 0; // Line Style
extern int WidthPP = 1; // Line Width
extern color LevelR1 = Crimson; // R1
extern ENUM_LINE_STYLE StyleR1 = 2; // Line Style
extern int WidthR1 = 1; // Line Width
extern color LevelR2 = Crimson; // R2
extern ENUM_LINE_STYLE StyleR2 = 1; // Line Style
extern int WidthR2 = 1; // Line Width
extern color LevelR3 = Crimson; // R3
extern ENUM_LINE_STYLE StyleR3 = 0; // Line Style
extern int WidthR3 = 1; // Line Width
extern color LevelS1 = DodgerBlue; // S1
extern ENUM_LINE_STYLE StyleS1 = 2; // Line Style
extern int WidthS1 = 1; // Line Width
extern color LevelS2 = DodgerBlue; // S2
extern ENUM_LINE_STYLE StyleS2 = 1; // Line Style
extern int WidthS2 = 1; // Line Width
extern color LevelS3 = DodgerBlue; // S3
extern ENUM_LINE_STYLE StyleS3 = 0; // Line Style
extern int WidthS3 = 1; // Line Width
extern bool displayPrevDayHL = true; // Display Previous Day's Hi/Lo
extern color LevelYH = MediumVioletRed; // Yesterday's High
extern ENUM_LINE_STYLE StyleYH = 2; // Line Style
extern int WidthYH = 3; // Line Width
extern color LevelYL = MediumSlateBlue; // Yesterday's Low
extern ENUM_LINE_STYLE StyleYL = 2; // Line Style
extern int WidthYL = 3; // Line Width
extern string Font = "Arial"; // Font
extern int FontSize = 8; // Font Size
extern int PivotBar = 1; // Bar (EXPERIMENTAL! current=0; default=1)
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double x,xR1,xR2,xR3,xS1,xS2,xS3,xPP;
string pivPeriod;
int LINE_TYPE;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
pivPeriod="M"+IntegerToString(inpPeriod);
if(inpPeriod>=60) pivPeriod = "H"+IntegerToString(inpPeriod/60);
if(inpPeriod>=1440) pivPeriod = "D1";
if(inpPeriod>=10080) pivPeriod = "WK";
if(inpPeriod>=43200) pivPeriod = "MN";
int xOffset=10;
int yOffset=20;
int Line=5+FontSize;
if(HLINE) LINE_TYPE=OBJ_HLINE;
else LINE_TYPE=OBJ_TREND;
if(LabelCorner<2)
{
ObjectMakeLabel(pivPeriod+"-pInfo",xOffset,yOffset);
ObjectMakeLabel(pivPeriod+"-lbR3",xOffset,Line+yOffset);
ObjectMakeLabel(pivPeriod+"-lbR2",xOffset,2*Line+yOffset);
ObjectMakeLabel(pivPeriod+"-lbR1",xOffset,3*Line+yOffset);
ObjectMakeLabel(pivPeriod+"-lbPP",xOffset,4*Line+yOffset);
ObjectMakeLabel(pivPeriod+"-lbS1",xOffset,5*Line+yOffset);
ObjectMakeLabel(pivPeriod+"-lbS2",xOffset,6*Line+yOffset);
ObjectMakeLabel(pivPeriod+"-lbS3",xOffset,7*Line+yOffset);
}
else
{
ObjectMakeLabel(pivPeriod+"-lbS3",xOffset,yOffset);
ObjectMakeLabel(pivPeriod+"-lbS2",xOffset,Line+yOffset);
ObjectMakeLabel(pivPeriod+"-lbS1",xOffset,2*Line+yOffset);
ObjectMakeLabel(pivPeriod+"-lbPP",xOffset,3*Line+yOffset);
ObjectMakeLabel(pivPeriod+"-lbR1",xOffset,4*Line+yOffset);
ObjectMakeLabel(pivPeriod+"-lbR2",xOffset,5*Line+yOffset);
ObjectMakeLabel(pivPeriod+"-lbR3",xOffset,6*Line+yOffset);
ObjectMakeLabel(pivPeriod+"-pInfo",10,7*Line+yOffset);
}
return (0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
DrawLevel(pivPeriod+"-R3",0,StyleR3,WidthR3,LevelR3);
DrawLevel(pivPeriod+"-R2",0,StyleR2,WidthR2,LevelR2);
DrawLevel(pivPeriod+"-R1",0,StyleR1,WidthR1,LevelR1);
DrawLevel(pivPeriod+"-PP",0,StylePP,WidthPP,LevelPP);
DrawLevel(pivPeriod+"-S1",0,StyleS1,WidthS1,LevelS1);
DrawLevel(pivPeriod+"-S2",0,StyleS2,WidthS2,LevelS2);
DrawLevel(pivPeriod+"-S3",0,StyleS3,WidthS3,LevelS3);
if (displayPrevDayHL==true)
{
DrawLevel("Yesterdays High",0,StyleYH,WidthYH,LevelYH);
DrawLevel("Yesterdays Low",0,StyleYL,WidthYL,LevelYL);
}
ObjectDelete(pivPeriod+"-pInfo");
ObjectDelete(pivPeriod+"-lbR3");
ObjectDelete(pivPeriod+"-lbR2");
ObjectDelete(pivPeriod+"-lbR1");
ObjectDelete(pivPeriod+"-lbPP");
ObjectDelete(pivPeriod+"-lbS1");
ObjectDelete(pivPeriod+"-lbS2");
ObjectDelete(pivPeriod+"-lbS3");
return (0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
//--- Yesterday's High/Low
double xYH = iHigh(NULL ,PERIOD_D1,1);
double xYL = iLow(NULL ,PERIOD_D1,1);
//--- Pivot Points
double xOpen=iOpen(NULL,inpPeriod,PivotBar);
double xClose= iClose(NULL,inpPeriod,PivotBar);
double xHigh = iHigh(NULL,inpPeriod,PivotBar);
double xLow=iLow(NULL,inpPeriod,PivotBar);
xPP=(xHigh+xLow+xClose)/3;
double xRange=xHigh-xLow;
//--- Standard Pivot
if(Pmode==Standard)
{
xR1 = (2 * xPP) - xLow;
xS1 = (2 * xPP) - xHigh;
xR2 = xPP + xRange;
xS2 = xPP - xRange;
xR3 = xHigh + 2*(xPP - xLow);
xS3 = xLow - 2*(xHigh - xPP);
}
//--- Fibonacci's Pivot
else if(Pmode==Fibonacci)
{
xR1 = xPP + 0.382 * xRange;
xR2 = xPP + 0.618 * xRange;
xR3 = xPP + 1.000 * xRange;
xS1 = xPP - 0.382 * xRange;
xS2 = xPP - 0.618 * xRange;
xS3 = xPP - 1.000 * xRange;
}
//--- Camarilla Pivot
else if(Pmode==Camarilla)
{
xR1 = xClose + (0.275 * xRange); // H3 Short
xR2 = xClose + (0.55 * xRange); // H4 Long Breakout
xR3 = (xHigh / xLow) * xClose; // H5 LB Target
xS1 = xClose - (0.275 * xRange); // L3 Long
xS2 = xClose - (0.55 * xRange); // L4 Short Breakout
xS3 = xClose - (xR3 - xClose); // L5 SB Target
}
//--- Woodie's Pivot
else if(Pmode==Woodie)
{
xPP = (xHigh + xLow + 2*xClose)/4;
xR1 = 2*xPP - xLow;
xR2 = xPP + xRange;
xR3=0; // Not used
xS1 = 2*xPP - xHigh;
xS2 = xPP - xRange;
xS3=0; // Not used
}
//--- Demark Pivot
else if(Pmode==Demark)
{
if(xClose<xOpen) x = xHigh + (2*xLow) + xClose;
if(xClose>xOpen) x = (2*xHigh) + xLow + xClose;
if(xClose==xOpen) x=xHigh+xLow+(2*xClose);
xPP=0; // Not used
xR3 = x / 2 - xLow;
xS3 = x / 2 - xHigh;
xR1=0; // R1, R2, S1 and S2 Not used
xR2 = 0;
xS1 = 0;
xS2 = 0;
}
//--- Draw Lines
DisplayMode();
if(inpPeriod>=Period())
{
if((Period()<=1440) && (displayPrevDayHL==true))
{
DrawLevel("Yesterdays High",xYH,StyleYH,WidthYH,LevelYH);
DrawLevel("Yesterdays Low",xYL,StyleYL,WidthYL,LevelYL);
}
DrawLevel(pivPeriod+"-R3",xR3,StyleR3,WidthR3,LevelR3);
DrawLevel(pivPeriod+"-R2",xR2,StyleR2,WidthR2,LevelR2);
DrawLevel(pivPeriod+"-R1",xR1,StyleR1,WidthR1,LevelR1);
DrawLevel(pivPeriod+"-PP",xPP,StylePP,WidthPP,LevelPP);
DrawLevel(pivPeriod+"-S1",xS1,StyleS1,WidthS1,LevelS1);
DrawLevel(pivPeriod+"-S2",xS2,StyleS2,WidthS2,LevelS2);
DrawLevel(pivPeriod+"-S3",xS3,StyleS3,WidthS3,LevelS3);
}
else DrawLevel(pivPeriod+"-PP",xPP,StylePP,WidthPP,LevelPP);
return (0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawLevel(string a_name_0,double ad,int a_style,int Width,color a_color)
{
double l_price=ad;
int l_timeA;
int l_timeB;
double diff=Period()*60;
l_timeA=(int)(Time[0] + xShift*diff);
l_timeB=(int)(Time[0] - (xLen-xShift) * diff);
if(ad>0.0)
{
if(ObjectFind(a_name_0)!=0)
{
ObjectCreate(a_name_0,LINE_TYPE,0,l_timeA,l_price,l_timeB,l_price);
ObjectSet(a_name_0,OBJPROP_RAY,False);
ObjectSet(a_name_0,OBJPROP_COLOR,a_color);
ObjectSet(a_name_0,OBJPROP_WIDTH,Width);
ObjectSet(a_name_0,OBJPROP_STYLE,a_style);
ObjectSet(a_name_0,OBJPROP_SELECTABLE,false);
ObjectSet(a_name_0,OBJPROP_HIDDEN,true);
return;
}
ObjectSet(a_name_0,OBJPROP_RAY,False);
ObjectMove(a_name_0,0,l_timeA,l_price);
ObjectMove(a_name_0,1,l_timeB,l_price);
ObjectSet(a_name_0,OBJPROP_COLOR,a_color);
ObjectSet(a_name_0,OBJPROP_WIDTH,Width);
ObjectSet(a_name_0,OBJPROP_STYLE,a_style);
ObjectSet(a_name_0,OBJPROP_SELECTABLE,false);
ObjectSet(a_name_0,OBJPROP_HIDDEN,true);
return;
}
if(ObjectFind(a_name_0)>=0) ObjectDelete(a_name_0);
}
//+--------------------------------------------------------------------------+
//| ObjectMakeLabel: |
//| P4L Clock.mq4 |
//| New rewrite by: Pips4life, a user at forexfactory.com |
//| 2014-Mar-19: v2_12 P4L Clock.mq4 |
//| For lastest version: http://www.forexfactory.com/showthread.php?t=109305 |
//| Previous names: Clock_v1_3.mq4, Clock.mq4, ... |
//| Previous version: Jerome, 4xCoder@gmail.com, ... |
///+-------------------------------------------------------------------------+
int ObjectMakeLabel(string n,int xoff,int yoff)
{
if(!WindowIsVisible(0)) return(-1);
ObjectCreate(n,OBJ_LABEL,0,0,0);
ObjectSet(n,OBJPROP_CORNER,LabelCorner);
ObjectSet(n,OBJPROP_XDISTANCE,xoff);
ObjectSet(n,OBJPROP_YDISTANCE,yoff);
ObjectSet(n,OBJPROP_BACK,false);
ObjectSet(n,OBJPROP_SELECTABLE,false);
ObjectSet(n,OBJPROP_HIDDEN,true);
return(0);
}// end of ObjectMakeLabel
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DisplayMode()
{
string sR3,sR2,sR1,sPP,sS1,sS2,sS3,sPointer;
sR3="";
sR2="";
sR1="";
sPP="";
sS1="";
sS2="";
sS3="";
if(LabelCorner<2) sPointer=">> ";
else sPointer=" <<";
double vbid=MarketInfo(NULL,MODE_BID);
if(vbid>=xR3)
{
sR3=sPointer;
}
else if(vbid>=xR2)
{
sR2=sPointer;
}
else if(vbid>=xR1)
{
sR1=sPointer;
}
else if(vbid>xS1)
{
sPP=sPointer;
if(vbid>xPP)
{
if(LabelCorner<2) sPointer="> ";
else sPointer=" <";
sPP=sPointer;
sR1=sPointer;
}
if(vbid<xPP)
{
if(LabelCorner<2) sPointer="> ";
else sPointer=" <";
sPP=sPointer;
sS1=sPointer;
}
}
else if(vbid<=xS3)
{
sS3=sPointer;
}
else if(vbid<=xS2)
{
sS2=sPointer;
}
else if(vbid<=xS1)
{
sS1=sPointer;
}
string pivInfo=EnumToString(Pmode)+" ("+pivPeriod+")";
if(LabelCorner<2)
{
ObjectSetText(pivPeriod+"-pInfo",pivInfo,8,"Arial",Gray);
ObjectSetText(pivPeriod+"-lbR3",sR3+"R3 = "+DoubleToStr(xR3,Digits),FontSize,Font,LevelR3);
ObjectSetText(pivPeriod+"-lbR2",sR2+"R2 = "+DoubleToStr(xR2,Digits),FontSize,Font,LevelR2);
ObjectSetText(pivPeriod+"-lbR1",sR1+"R1 = "+DoubleToStr(xR1,Digits),FontSize,Font,LevelR1);
ObjectSetText(pivPeriod+"-lbPP",sPP+"PP = "+DoubleToStr(xPP,Digits),FontSize,Font,LevelPP);
ObjectSetText(pivPeriod+"-lbS1",sS1+"S1 = "+DoubleToStr(xS1,Digits),FontSize,Font,LevelS1);
ObjectSetText(pivPeriod+"-lbS2",sS2+"S2 = "+DoubleToStr(xS2,Digits),FontSize,Font,LevelS2);
ObjectSetText(pivPeriod+"-lbS3",sS3+"S3 = "+DoubleToStr(xS3,Digits),FontSize,Font,LevelS3);
}
else
{
ObjectSetText(pivPeriod+"-pInfo",pivInfo,8,"Arial",Gray);
ObjectSetText(pivPeriod+"-lbR3","R3 = "+DoubleToStr(xR3,Digits)+sR3,FontSize,Font,LevelR3);
ObjectSetText(pivPeriod+"-lbR2","R2 = "+DoubleToStr(xR2,Digits)+sR2,FontSize,Font,LevelR2);
ObjectSetText(pivPeriod+"-lbR1","R1 = "+DoubleToStr(xR1,Digits)+sR1,FontSize,Font,LevelR1);
ObjectSetText(pivPeriod+"-lbPP","PP = "+DoubleToStr(xPP,Digits)+sPP,FontSize,Font,LevelPP);
ObjectSetText(pivPeriod+"-lbS1","S1 = "+DoubleToStr(xS1,Digits)+sS1,FontSize,Font,LevelS1);
ObjectSetText(pivPeriod+"-lbS2","S2 = "+DoubleToStr(xS2,Digits)+sS2,FontSize,Font,LevelS2);
ObjectSetText(pivPeriod+"-lbS3","S3 = "+DoubleToStr(xS3,Digits)+sS3,FontSize,Font,LevelS3);
}
}
//+------------------------------------------------------------------+
Comments