^Pivot_ResSup

Download script
Author: Modest, Rosh conversed only
^Pivot_ResSup

This script is designed as a visual trading tool for the MetaTrader platform. Its primary purpose is to automatically identify and plot key price levels—specifically Resistance and Support zones—based on historical daily price action. These levels help traders visualize where the market might encounter significant friction or potential reversal points.

Core Logic Overview

The script operates by analyzing the previous day's trading activity to establish "Pivot" points for the current day. It follows a structured sequence of logic:

1. Day Transition Detection The tool constantly monitors the time on the chart. Every time it detects the start of a new trading day, it triggers a calculation to determine the price boundaries established during the previous 24-hour cycle.

2. Price Boundary Identification To find these levels, the script looks back at the previous day's data to identify two critical values:

  • The highest price reached (High).
  • The lowest price reached (Low).
  • The closing price of that period.

3. Calculation of Pivot Points Once it has the high, low, and close prices, the script applies a mathematical formula to determine the central "Pivot" point. The user can choose between two different formulas via the settings:

  • Standard Formula: A weighted average of the high, low, and previous close.
  • Alternative Formula: A variation that gives more weight to the previous day's closing price.

4. Support and Resistance Projection After establishing the central Pivot point, the script calculates two specific horizontal levels:

  • Resistance: The level above the pivot where the price might struggle to break higher.
  • Support: The level below the pivot where the price might find a "floor" and bounce back up.

5. Continuous Visualization The script is designed to be dynamic. While it calculates new levels at the start of each day, it also carries those levels forward across the current day's candles. This ensures that the support and resistance lines remain visible and consistent throughout the trading session until the next day's data replaces them.

Summary for Traders

In practical terms, this tool saves you from manually calculating "Pivot Points." It automatically scans the previous day's history and draws clear markers on your chart to show you where the most relevant price boundaries are likely to occur today, allowing for quicker identification of potential trade entries and exits.

Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
^Pivot_ResSup
//+------------------------------------------------------------------+
//|                                                ^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 Blue
#property indicator_color2 Red
//---- 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 GetRS1ofDay(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+(FP-FL),Digits);
   SupBuffer[_shift]=NormalizeDouble(FP-(FH-FP),Digits);
//----
  }

//+------------------------------------------------------------------+
//| Êîïèðîâàòü FP,Res1 è Sup1 ïðîøåäøåãî äíÿ                         |
//+------------------------------------------------------------------+
void CopyLevels1Day(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_Res("+Formula+")";
   string label2="Pivot_Sup("+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)) GetRS1ofDay(shift); else CopyLevels1Day(shift);
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments