^Pivot_PP
Download scriptThis script is designed as a technical analysis tool for the MetaTrader platform, specifically created to identify and plot "Pivot Points" on a trading chart. These points serve as significant price levels that traders often use to determine potential support and resistance areas.
Core Logic Overview
The primary function of this script is to automatically calculate a specific price level based on the price action of the previous trading day. Instead of requiring the user to manually calculate these figures, the script scans historical data to find the high, low, and closing prices of yesterday's session and projects a "Pivot" value onto the current chart.
Key Features and Operations
-
Time Awareness: The script is programmed to recognize the start of a new trading day. It monitors the time stamps on the chart to detect when a calendar day changes, which triggers the calculation for the new set of pivot levels.
-
Historical Data Analysis: To determine the current Pivot Point, the script looks back at the previous day's performance. It identifies:
- The Highest Price reached during that day.
- The Lowest Price reached during that day.
- The Closing Price of that day.
-
Configurable Formulas: The script provides two different mathematical ways to calculate the Pivot Point depending on user preference:
- Standard Method: A balanced average of the previous day's high, low, and closing prices.
- Weighted Method: A variation that gives more weight to the closing price of the previous day, which some traders believe provides a more accurate reflection of market sentiment.
-
Visual Display: The script places these calculated levels onto the chart as visual markers (arrows). This allows traders to see at a glance where the "equilibrium" price sits for the current day, helping them decide whether to enter or exit trades based on how the current price interacts with these historical boundaries.
-
Compatibility Constraints: The script includes logic to ensure it only runs on specific timeframes (lower than 4 hours). This ensures that the pivot points remain relevant and do not become cluttered or inaccurate when viewed on extremely large daily or weekly scales.
//+------------------------------------------------------------------+
//| ^Pivot_PP.mq4 |
//| Modest, Rosh conversed only |
//| http://forexsystems.ru/phpBB/index.php |
//+------------------------------------------------------------------+
#property copyright "Modest, Rosh conversed only"
#property link "http://forexsystems.ru/phpBB/index.php"
//// Ñòðîèì Pivot è Res/Supp ïî FibonacciTrader Journal Issue 6
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DarkGreen
//---- input parameters
extern int Formula=0;
int i=1, shift;
double FP=0.0;
double FH=0.0, FL=0.0;
bool result;
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Ïðîâåðêà íîâîãî äíÿ |
//+------------------------------------------------------------------+
bool isNewDay(int _shift)
{
//----
result=false;
if ( (TimeHour(Time[_shift])==0) && (TimeMinute(Time[_shift])==0) ) result=true;
//----
return(result);
}
//+------------------------------------------------------------------+
//| Ïîëó÷èòü óðîâåíü FP ïðîøåäøåãî äíÿ |
//+------------------------------------------------------------------+
double GetFPofDay(int _shift)
{
int prevDay=TimeDay(Time[_shift+1]);
//----
i=1;
while (TimeDay(Time[_shift+i])==prevDay) i++;
i--;
FH=High[Highest(NULL,0,MODE_HIGH,i,_shift+1)];
FL=Low[Lowest(NULL,0,MODE_LOW,i,_shift+1)];
if (Formula==0) FP=NormalizeDouble((FH+FL+Close[_shift+1])/3.0,Digits); else FP=NormalizeDouble((FH+FL+2*Close[_shift+1])/4.0,Digits);
//----
return(FP);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
if (Formula!=0)Formula=1;
string label="Pivot_PP("+Formula+")";
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,160);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);
SetIndexLabel(0,label);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit,firstDay;
int counted_bars=IndicatorCounted();
if (counted_bars<0) return(0);
if (counted_bars==0)
{
limit=Bars-1;
i=1;
firstDay=TimeDay(Time[limit]);
while (TimeDay(Time[limit-i])==firstDay) i++;
limit=limit-i-PERIOD_D1/Period();
}
if (counted_bars>0) limit=Bars-counted_bars;
//----
if (Period()>PERIOD_H4) return;
for (shift=limit;shift>=0;shift--)
{
if (isNewDay(shift)) ExtMapBuffer1[shift]=GetFPofDay(shift); else ExtMapBuffer1[shift]=ExtMapBuffer1[shift+1];
//if (shift==0) SetNullBarValue(shift);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments