^Pivot_AllLevels

Download script
Author: Modest, Rosh conversed only
^Pivot_AllLevels

This tool is designed to automatically identify and plot key price levels on your trading chart based on the previous day's market activity. It acts as a visual guide, helping traders see where significant support (price floors) and resistance (price ceilings) might exist for the current trading session.

How the Logic Works

1. Daily Data Analysis The script constantly monitors the price movement of the preceding day. Specifically, it looks back to find three critical data points from that past 24-hour period:

  • The highest price reached (High)
  • The lowest price reached (Low)
  • The final closing price (Close)

2. Calculation of Key Levels Using these three data points, the script calculates a series of mathematical "Pivot" levels. Depending on your settings, it uses a specific formula to determine the Pivot Point, which acts as the central balance of the previous day's movement. From that central point, it projects several other levels:

  • Support Levels: These represent areas where buying interest is expected to be stronger, potentially preventing the price from falling further.
  • Resistance Levels: These represent areas where selling pressure is expected to be higher, potentially preventing the price from rising further.

3. Automatic Updates and Continuity The logic is programmed to be "smart" about time:

  • New Day Detection: Every time a new trading day begins, the script automatically resets. It captures the high, low, and close of the day that just ended to calculate the new levels for today.
  • Level Persistence: For the remainder of the current day, the script "carries over" these calculated levels. This ensures that the support and resistance lines remain steady and visible throughout the session rather than jumping around or disappearing.

4. Visual Display The results are plotted directly on your chart as specific markers. These markers provide a clean, organized view of the market's "geography," allowing you to see at a glance where the price might encounter friction or find stability based on yesterday’s historical behavior.

Price Data Components
Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
^Pivot_AllLevels
//+------------------------------------------------------------------+
//|                                                ^Pivot_ResSup.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 7
#property indicator_color6 Aqua 
#property indicator_color1 Turquoise
#property indicator_color2 Blue
#property indicator_color3 Black
#property indicator_color4 Red
#property indicator_color5 Coral
#property indicator_color7 Magenta
//---- 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 ResBuffer3[];
double ResBuffer2[];
double ResBuffer[];
double ExtMapBuffer1[];
double SupBuffer[];
double SupBuffer2[];
double SupBuffer3[];
//+------------------------------------------------------------------+
//| Ïðîâåðêà íîâîãî äíÿ                                              |
//+------------------------------------------------------------------+
bool isNewDay(int _shift)
  {
//---- 
   result=false;
   if (  (TimeHour(Time[_shift])==0)  && (TimeMinute(Time[_shift])==0)   ) result=true;

//----
   return(result);
  }
//+------------------------------------------------------------------+
//| Ïîëó÷èòü óðîâíè FP,Res1,Sup1,Res2 è Sup2 ïðîøåäøåãî äíÿ          |
//+------------------------------------------------------------------+
void GetRSofDay(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);
   ExtMapBuffer1[_shift]=FP;
   ResBuffer[_shift]=NormalizeDouble(FP+(FP-FL),Digits);
   SupBuffer[_shift]=NormalizeDouble(FP-(FH-FP),Digits);
   ResBuffer2[_shift]=NormalizeDouble(FP+(FH-FL),Digits);
   SupBuffer2[_shift]=NormalizeDouble(FP-(FH-FL),Digits);
   ResBuffer3[_shift]=NormalizeDouble(FH-(2*(FL-FP)),Digits);
   SupBuffer3[_shift]=NormalizeDouble(FL-(2*(FH-FP)),Digits);
//----
  }

//+------------------------------------------------------------------+
//| Êîïèðîâàòü FP,Res1,Sup1,Res2 è Sup2 ïðîøåäøåãî äíÿ               |
//+------------------------------------------------------------------+
void CopyLevelsDay(int _shift)
  {
   ExtMapBuffer1[_shift]=ExtMapBuffer1[_shift+1];
   ResBuffer[_shift]=ResBuffer[_shift+1];
   SupBuffer[_shift]=SupBuffer[_shift+1];
   ResBuffer2[_shift]=ResBuffer2[_shift+1];
   SupBuffer2[_shift]=SupBuffer2[_shift+1];
   ResBuffer3[_shift]=ResBuffer3[_shift+1];
   SupBuffer3[_shift]=SupBuffer3[_shift+1];
  }



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   if (Formula!=0)Formula=1;
   string label1="Pivot_Res2("+Formula+")";
   string label2="Pivot_Res("+Formula+")";
   string label3="Pivot_Point("+Formula+")";
   string label4="Pivot_Sup("+Formula+")";
   string label5="Pivot_Sup2("+Formula+")";
   string label6="Pivot_Res3("+Formula+")";
   string label7="Pivot_Sup3("+Formula+")";
//---- indicators
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5,160); 
   SetIndexBuffer(5,ResBuffer3);
   SetIndexEmptyValue(5,0.0);
   SetIndexLabel(5,label6);

   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,160); 
   SetIndexBuffer(0,ResBuffer2);
   SetIndexEmptyValue(0,0.0);
   SetIndexLabel(0,label1);

   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,160); 
   SetIndexBuffer(1,ResBuffer);
   SetIndexEmptyValue(1,0.0);
   SetIndexLabel(1,label2);

   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,160); 
   SetIndexBuffer(2,ExtMapBuffer1);
   SetIndexEmptyValue(2,0.0);
   SetIndexLabel(2,label3);

   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,160); 
   SetIndexBuffer(3,SupBuffer);
   SetIndexEmptyValue(3,0.0);
   SetIndexLabel(3,label4);

   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,160); 
   SetIndexBuffer(4,SupBuffer2);
   SetIndexEmptyValue(4,0.0);
   SetIndexLabel(4,label5);
   
   SetIndexStyle(6,DRAW_ARROW);
   SetIndexArrow(6,160); 
   SetIndexBuffer(6,SupBuffer3);
   SetIndexEmptyValue(6,0.0);
   SetIndexLabel(6,label7);


//----
   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)) GetRSofDay(shift); else CopyLevelsDay(shift);
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments