PrevDayAndFloatingPivot_v1
Download scriptThis technical tool is designed to provide traders with clear visual reference points on their charts by calculating two distinct types of "Pivot" levels: one based on historical data from the previous trading day and another that evolves in real-time throughout the current day.
Core Functionality
The script analyzes market price action to establish two primary lines:
1. Previous Day Pivot (Static Reference) The tool identifies the most recent completed trading day, specifically skipping Sundays to ensure the data reflects a valid active trading session. It calculates a fixed price point based on four key ingredients from that previous period: the high price, the low price, the closing price, and the opening price of the current day. By averaging these specific values, it produces a "Previous Day Pivot." This serves as a stable horizontal reference point, helping traders understand the established baseline from the prior session.
2. Floating Current Pivot (Dynamic Reference) Unlike the previous day's pivot, this value is designed to move and update as the market progresses. The script continuously monitors the highest price reached and the lowest price dropped during the current trading day. It then combines these "live" extremes with the current market closing price to create a floating average. Because it incorporates the high and low of the day so far, this line adjusts dynamically, reflecting the immediate range and momentum of the current session.
How It Works for the Trader
By placing both of these lines on a chart simultaneously, the tool allows you to see the relationship between yesterday's established boundaries and today's active price movement.
- The Previous Day Pivot tells you where the market was centered in the past.
- The Floating Current Pivot shows you where the market is centering right now.
This dual-perspective approach helps in identifying potential support and resistance zones, allowing for a clearer understanding of whether the current price action is trending above or below historical norms.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| PrevDayAndFloatingPivot.mq4 |
//| Copyright © 2006, mbkennel@gmail.com |
//| http://www.metatrader.org |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, mbkennel@gmail.com"
#property link "http://www.metatrader.org"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Magenta
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexLabel(0,"Previous Day Pivot");
SetIndexLabel(1,"Floating current pivot");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
int TodaysBarShift(int shift) {
// return the bar shift for today.
// i.e. not today.
datetime timenow= iTime(NULL,Period(),shift); // shift of current bar on lower TF chart.
int idaybarshift = iBarShift(NULL,PERIOD_D1,timenow,false);
datetime timedaybegin = iTime(NULL,PERIOD_D1,idaybarshift);
if ((timedaybegin) > timenow) idaybarshift++;
return(idaybarshift);
}
int PreviousNonSundayBarShift(int shift) {
int tbs = TodaysBarShift(shift);
int ybs = tbs+1;
datetime yesterdaybegin = iTime(NULL,PERIOD_D1,ybs);
if (TimeDayOfWeek(yesterdaybegin) == 0) ybs++; // we found a Sunday bar so screw it.
return(ybs);
}
void TodaysHighestLowest(double& H, double& L, int shift) {
// return the higest and lowest so far today.
datetime now = iTime(NULL,Period(),shift); // time value of bar.
int tbs = TodaysBarShift(shift);
datetime daybegin = iTime(NULL,PERIOD_D1,tbs);
H = High[shift];
L = Low[shift];
int j = shift+1;
while ( iTime(NULL,Period(),j) >= daybegin) {
double Ht = High[j];
double Lt = Low[j];
H = MathMax(H,Ht);
L = MathMin(L,Lt);
j++;
if ((j-shift) > 24) {
Print ("Shit!");
break;
}
}
return;
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
int limit = Bars-counted_bars;
for (int i=limit; i >= 0; i--) {
// Get the prev days pivot. Today's pivot.
int ybs = PreviousNonSundayBarShift(i);
int tdbar = TodaysBarShift(i);
// Prev day's pivot:
double p = (iHigh(NULL,PERIOD_D1,ybs)+iLow(NULL,PERIOD_D1,ybs)+
iClose(NULL,PERIOD_D1,ybs) + iOpen(NULL,PERIOD_D1,tdbar))*0.25;
double TH,TL;
TodaysHighestLowest(TH,TL,i);
double flp = (TH+TL+Close[i])*0.33333;
ExtMapBuffer1[i] = p;
ExtMapBuffer2[i] = flp;
//
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments