PrevDayAndFloatingPivot_O_001

Download script
Author: Copyright � 2006, mbkennel@gmail.com
PrevDayAndFloatingPivot_O_001

This tool is designed to provide traders with a visual and audible reference for key price levels on their charts, specifically focusing on "pivots." It helps identify significant support and resistance areas by comparing the market's previous performance with its current live movement.

Core Functionality

The script tracks two distinct types of price data simultaneously:

1. The Previous Day’s Pivot The indicator automatically identifies the closing price from the previous trading day (filtering out Sundays to ensure accuracy). This acts as a baseline, representing where the market established itself at the end of the prior session.

2. The Floating Current Pivot Unlike a static price level, this is a "floating" calculation that updates in real-time. It looks at the highest and lowest prices reached during the current day so far, combines them with the current live price, and calculates a weighted average. Because it uses the current high, low, and moving price, this line moves dynamically as the market fluctuates throughout the day.

Visual and Alert Features

  • Visual Mapping: The tool draws two distinct lines on your chart. One represents the fixed point from yesterday, and the other represents the moving average of today's price action. By observing the distance and relationship between these two lines, traders can gauge current momentum.
  • Directional Alerts: The script includes a smart alert system. It monitors the relationship between the "Floating Pivot" and the "Previous Day Pivot." If the relative position of these two levels flips—meaning the market sentiment shifts from being above the baseline to below it (or vice versa)—the system will trigger an alert notification.

Summary for Traders

This tool simplifies technical analysis by highlighting where the market is currently "weighted" compared to yesterday's closing state. It automates the math required to find these pivot points, allowing you to see shifts in market momentum instantly without having to manually calculate price averages or hunt for previous day data.

Price Data Components
Series array that contains open prices of each bar
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
9 Views
0 Downloads
0 Favorites
PrevDayAndFloatingPivot_O_001
//+------------------------------------------------------------------+
//|                                      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 HotPink
#property indicator_color2 LightSkyBlue
#property indicator_width1 3
extern bool PivAlert = true;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double alertBar;
//+------------------------------------------------------------------+
//| 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 = iOpen(NULL,PERIOD_D1,tdbar);
      
      double TH,TL;
      TodaysHighestLowest(TH,TL,i);
      
      double flp = (TH+TL+Close[i])*0.33333;   
      ExtMapBuffer1[i] = p;
      ExtMapBuffer2[i] = flp; 
      // 
   
   }
   if (PivAlert == true)
   {  
     static string earlier_direction = "";
     string current_direction = "";
                                    
     if ( ((ExtMapBuffer2[1] - ExtMapBuffer1[1]) > 0) && ((ExtMapBuffer2[0] - ExtMapBuffer1[0]) < 0) ) current_direction = "down";
     if ( ((ExtMapBuffer2[1] - ExtMapBuffer1[1]) < 0) && ((ExtMapBuffer2[0] - ExtMapBuffer1[0]) > 0) ) current_direction = "up";
                                   
     if(current_direction != earlier_direction && Bars>alertBar) 
     {
        Alert(Symbol(), " M", Period()," Pivot direction has changed ", current_direction);
        earlier_direction = current_direction;alertBar = Bars;       
     }   
   }  
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments