_255eDyn_Pivot

Download script
Author: Modest, Rosh conversed only
_255eDyn_Pivot

This tool is designed to identify and display specific "Pivot Points" on a trading chart. Pivot points are key price levels used by traders to gauge potential support and resistance, helping to determine where the market might change direction or stabilize during a trading session.

Core Logic and Functionality

The script automatically analyzes historical price data to calculate these pivot levels based on the previous day's performance. Here is a breakdown of how the logic operates:

1. Historical Data Analysis To determine today's pivot point, the script looks backward at the completed candles of the previous trading day. It specifically identifies three critical pieces of information from that period:

  • The highest price reached (High).
  • The lowest price reached (Low).
  • The closing price at the end of that day.

2. Calculation Methods The script provides two different mathematical approaches to calculate the pivot level, allowing for different styles of analysis:

  • Standard Calculation: This blends the high, low, and previous close equally. It is a traditional method used to find the "balance" point of the previous day's range.
  • Weighted Calculation: This places a heavier emphasis on the closing price of the previous day. By giving the closing price more "weight" in the math, the indicator reflects a strategy where the final sentiment of the previous day is considered more significant than the extremes (the highs and lows).

3. Smart Chart Rendering The script includes specific logic to ensure the visual data remains clean and useful:

  • New Day Detection: It automatically recognizes when a new trading day begins to trigger the calculation for the current period.
  • Visual Cleanup: To prevent the chart from becoming cluttered with unnecessary lines, the script is programmed to "clear" or nullify values on bars where the data is not applicable. This ensures that only the relevant pivot levels are visible, making it easier for a trader to focus on the current price action.
  • Timeframe Compatibility: The logic is optimized to run on shorter timeframes (specifically those smaller than 4 hours), ensuring that the daily pivot level remains relevant and accurate as price movestick-by-stick throughout the day.

Summary for the User

In essence, this script acts as an automated scout. It looks at everything that happened yesterday, performs a specific mathematical calculation to find the "fair value" or "pivot" of today, and draws that level on your chart. This allows you to see at a glance where the market's center of gravity sits for the current day.

Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
_255eDyn_Pivot
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                   ^Dyn_Pivot.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"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DarkGreen
//---- 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[];

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

//----
   return(result);
  }
//+------------------------------------------------------------------+
//| Ïîëó÷èòü óðîâåíü FP ïðîøåäøåãî äíÿ                               |
//+------------------------------------------------------------------+
double GetFPofDay(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);
//----
   return(FP);
  }
//+------------------------------------------------------------------+
//| Ðàáîòà â íóëåâîì áàðå                                            |
//+------------------------------------------------------------------+
void SetNullBarValue(int _shift)
  {
  int cnt;
  int currDay=TimeDay(Time[_shift]);
//---- 
   i=1;
   while (TimeDay(Time[_shift+i])==currDay) i++;
   if (i>=2)
      {
      i=i-2;
      for (cnt=i;cnt>0;cnt--) ExtMapBuffer1[shift+cnt]=0.0;
      FH=High[Highest(NULL,0,MODE_HIGH,i+1,_shift)];
      FL=Low[Lowest(NULL,0,MODE_LOW,i+1,_shift)];
      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;
      }
//----
   return;
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   if (Formula!=0)Formula=1;
   string label="FP("+Formula+")";
//---- indicators
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexLabel(0,label);

//----
   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)) ExtMapBuffer1[shift]=GetFPofDay(shift); else  ExtMapBuffer1[shift]=0.0;
      if (shift==0) SetNullBarValue(shift);
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments