^Pivot_ResSup2

Download script
Author: Modest, Rosh conversed only
^Pivot_ResSup2

This script is designed to automatically identify and display key price levels on your trading chart, specifically focusing on "Pivot Points" which represent significant support and resistance zones. By using these historical benchmarks, traders can better visualize where the market might encounter difficulty moving higher or lower.

Core Logic and Functionality

The script operates by analyzing the price action of the previous completed trading day to project specific levels onto the current day's chart. Here is a breakdown of how it processes that information:

1. Identifying the Trading Day Boundary The logic first scans the chart to identify when a new day begins. It specifically looks for the midnight reset (00:00). This allows the script to distinguish between "old" data from yesterday and "active" data for today.

2. Calculating Historical Highs and Lows Once it identifies the previous day, the script calculates the highest price reached (High) and the lowest price reached (Low) during that entire 24-hour period. These two numbers serve as the foundation for all subsequent calculations.

3. Pivot Point Generation Using the previous day's High, Low, and Closing prices, the script applies a mathematical formula to determine the "Pivot" (the central balance point). The user can choose between two different calculation methods:

  • Standard: A balanced average of the high, low, and close.
  • Modified: A weighted version that gives more importance to the previous day's closing price.

4. Establishing Support and Resistance Zones From that central Pivot point, the script projects two specific horizontal levels:

  • Resistance: A level calculated above the pivot, marking a potential ceiling where selling pressure might increase.
  • Support: A level calculated below the pivot, marking a potential floor where buying interest might cluster.

5. Persistence and Continuity A key feature of this script is its "memory." Instead of these levels disappearing or changing erratically throughout the day, the script is designed to carry over the levels established at the start of the day. As new candles form, the script ensures that the support and resistance lines remain consistent and visible based on the previous day's data until the next day begins.

Visual Representation

On the trading platform, these levels are displayed as distinct markers (arrows). This provides a clean, visual guide that allows you to see exactly where the "mathematical" boundaries for the current session sit, helping you identify potential areas of interest without manual calculation.

Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
^Pivot_ResSup2
//+------------------------------------------------------------------+
//|                                                ^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 2
#property indicator_color1 LightBlue
#property indicator_color2 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 ExtMapBuffer1[];
double ResBuffer[];
double SupBuffer[];

//+------------------------------------------------------------------+
//| Ïðîâåðêà íîâîãî äíÿ                                              |
//+------------------------------------------------------------------+
bool isNewDay(int _shift)
  {
//---- 
   result=false;
   if (  (TimeHour(Time[_shift])==0)  && (TimeMinute(Time[_shift])==0)   ) result=true;

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

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



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   if (Formula!=0)Formula=1;
   string label1="Pivot_Res2("+Formula+")";
   string label2="Pivot_Sup2("+Formula+")";
//---- indicators
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,160); 
   SetIndexBuffer(0,ResBuffer);
   SetIndexEmptyValue(0,0.0);
   SetIndexLabel(0,label2);

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

   SetIndexBuffer(0,ExtMapBuffer1);
//----
   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)) GetRS2ofDay(shift); else CopyLevels2Day(shift);
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments