Three Day Rolling Pivot_v1

Download script
Three Day Rolling Pivot_v1

This indicator is designed to provide traders with a visual representation of key price levels based on historical price action over a specific three-day rolling period. It simplifies complex market data into three primary horizontal reference lines: a central Pivot Point, a "Range Top," and a "Range Bottom."

How the Logic Works

1. Identifying the Data Window The tool focuses on a specific timeframe defined by the user (the "Pivot Range"). By looking at the history of the market, the script identifies the high, low, and closing prices within this designated window. It treats these three values as the foundation for all its calculations.

2. Calculating the Core Pivot Point The central line (the Pivot Point) is calculated using a standard mathematical average. It takes the highest price reached, the lowest price hit, and the final closing price of the period, and divides them by three. This represents the "fair value" or equilibrium point for that specific market cycle.

3. Establishing the Range Boundaries To give traders a sense of the market's volatility and potential boundaries, the script calculates two additional lines:

  • The Pivot Top: An upper boundary calculated by measuring the distance between the midpoint of the high/low range and the actual Pivot Point.
  • The Pivot Bottom: A lower boundary mirroring that same distance below the Pivot Point.

4. Dynamic Visual Updates As new price data arrives, the script automatically scans the chart to keep these levels current. It continuously updates the calculations so that the lines on your chart shift accurately as new "highs," "lows," and "closes" are established within your chosen time window.

Key Features for the User

  • Visual Clarity: The indicator draws three distinct lines on the chart: a dotted line for the main Pivot Point and dashed lines for the Top and Bottom boundaries.
  • Real-Time Feedback: It provides an on-screen summary showing the exact High, Low, and Close values currently being used to generate the levels.
  • Customizable Windows: Users can define the specific start and end times that determine which price data is captured for the calculation, allowing for flexibility based on different trading sessions.
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Three Day Rolling Pivot_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

/**
* ACD_3.mq4
* Three Day Rolling Pivot
**/

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Green 
#property indicator_color2 LimeGreen
#property indicator_color3 LimeGreen

//Input Params
extern string PivotRangeStart = "21:00";
extern string PivotRangeEnd = "21:00";
extern bool DisplayPivotPoint = true;

double Buffer1[];
double Buffer2[];
double Buffer3[];

double pivotRangeHigh;
double pivotRangeLow;
double pivotRangeClose;
double pivotTop=0;
double pivotBottom=0;
    
int init()
{
   SetIndexStyle(0,DRAW_LINE, STYLE_DOT, 1);
   SetIndexBuffer(0,Buffer1);
   SetIndexLabel(0,"Pivot Point");

   SetIndexStyle(1,DRAW_LINE, STYLE_DASH, 1);
   SetIndexBuffer(1,Buffer2);
   SetIndexLabel(1,"Pivot Range Top");

   SetIndexStyle(2,DRAW_LINE, STYLE_DASH, 1);
   SetIndexBuffer(2,Buffer3);
   SetIndexLabel(2,"Pivot Range Bottom");

   return(0);
}

int deinit()
{
   return(0);
}

int start()
{   
   string barTime="", lastBarTime="";    
   string barDay="", lastBarDay="";        
   int openBars[3], tempBars[3];
   int openBar, closeBar;
          
   for(int i=Bars; i>=0; i--)
   {  
      barTime = TimeToStr(Time[i], TIME_MINUTES);
      lastBarTime = TimeToStr(Time[i+1], TIME_MINUTES); 
      barDay = TimeToStr(Time[i],TIME_DATE);
      lastBarDay = TimeToStr(Time[i+1],TIME_DATE);
      
      if ((PivotRangeEnd == "00:00" && barTime>=PivotRangeEnd && barDay>lastBarDay) || (barTime>=PivotRangeEnd && lastBarTime<PivotRangeEnd))     
      {  
         closeBar = i + 1;
         openBar = openBars[2];
         
         ArrayCopy(tempBars, openBars, 1, 0, 2);
         ArrayCopy(openBars, tempBars);
         
         if (openBar>0)
         {
            calculatePivotRangeValues(openBar, closeBar);
         }
      }
      
      if ((PivotRangeStart == "00:00" && barTime>=PivotRangeStart && barDay>lastBarDay) || (barTime>=PivotRangeStart && lastBarTime<PivotRangeStart))
      {
          openBars[0] = i;
      }
      
      if (openBar>0)
      {
          drawIndicators(i);
      }     
   }
   return(0);
}

void calculatePivotRangeValues(int openBar, int closeBar)
{
   pivotRangeHigh = High[Highest(NULL, 0, MODE_HIGH, (openBar - closeBar + 1), closeBar)];
   pivotRangeLow = Low[Lowest(NULL, 0, MODE_LOW, (openBar - closeBar + 1), closeBar)];
   pivotRangeClose = Close[closeBar];
}

void drawIndicators(int curBar)
{
   double pivotPoint, pivotDiff;
   
   if (pivotRangeHigh<=0 || pivotRangeLow <=0 || pivotRangeClose <= 0)
   {
      return(0);
   }
   
   pivotPoint=(pivotRangeHigh + pivotRangeLow + pivotRangeClose)/3;
   pivotDiff = MathAbs(((pivotRangeHigh + pivotRangeLow)/2) - pivotPoint);
   pivotTop = pivotPoint + pivotDiff;
   pivotBottom = pivotPoint - pivotDiff;   

   if (DisplayPivotPoint) Buffer1[curBar]=pivotPoint;
   Buffer2[curBar]=pivotTop;
   Buffer3[curBar]=pivotBottom;
   Comment("H " + DoubleToStr(pivotRangeHigh, Digits) + " L " + DoubleToStr(pivotRangeLow, Digits) + " C " + DoubleToStr(pivotRangeClose,Digits));
}

Comments