_255eDyn_Range2

Download script
Author: Modest, Rosh conversed only
_255eDyn_Range2

This tool is designed as a visual technical analysis assistant for the MetaTrader 4 platform. Its primary purpose is to identify and plot key "Pivot" price levels on your trading chart based on the previous day's price action. By automatically calculating these boundaries, it helps traders visualize potential areas of support and resistance.

Core Functionality

The script analyzes historical price data to determine three specific horizontal price markers:

  1. The Pivot Point (FP): This is the central calculated level for the day. The tool calculates this by looking at the highest price reached, the lowest price reached, and the closing price of the previous trading session.
  2. Resistance Levels (FR2): A dynamic upper boundary calculated based on the distance between the previous day's highs and lows. This represents a potential ceiling where price might face selling pressure.
  3. Support Levels (FS2): A dynamic lower boundary calculated similarly to the resistance level but projected downwards. This represents a potential floor where price might find buying interest.

How it Works Internally

  • Daily Detection: The script automatically monitors the timeline to detect when a new trading day begins. When a new day starts, it pulls the data from the completed preceding day to generate the markers for the current session.
  • Customizable Formulas: There is a built-in toggle (Formula) that allows the user to choose between two different mathematical methods for calculating the central Pivot Point, providing flexibility based on individual trading preferences.
  • Dynamic Adjustments: The script includes specific logic to handle "null" bars and ensures that levels are only drawn where they are relevant, preventing your chart from becoming cluttered with unnecessary data points.
  • Timeframe Compatibility: To maintain accuracy, the tool is optimized to run on lower timeframes (such as hourly or shorter), automatically adjusting its calculations to ensure the daily boundaries remain consistent and visible.

Visual Representation

On your trading platform, these levels appear as distinct colored sections. They provide a clear, "at-a-glance" map of where the market's pivot points are situated, allowing you to see potential price turning points without having to perform manual calculations every day.

Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
_255eDyn_Range2
/*-----------------------------+
|			       |
| 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 2
#property indicator_color1 LightBlue
#property indicator_color2 Magenta
//---- input parameters
extern int       Formula=0;
int i=1, j=1, shift=0;
double FP=0.0;
double FH=0.0, FL=0.0;
bool result;
//---- buffers
double ExtMapBuffer1[];
double FR2Buffer[];
double FS2Buffer[];
//+------------------------------------------------------------------+
//| Ïðîâåðêà íîâîãî äíÿ                                              |
//+------------------------------------------------------------------+
bool isNewDay(int _shift)
  {
//---- 
   result=false;
   if (  (TimeHour(Time[_shift])==0)  && (TimeMinute(Time[_shift])==0)   ) result=true;
   //Print("Äàòà=",TimeToStr(Time[_shift]),"  isNewDay=",result);
//----
   return(result);
  }
//+------------------------------------------------------------------+
//| Óñòàíîâèòü óðîâíè FP, FR2 è FS2 ïðîøåäøåãî äíÿ                   |
//+------------------------------------------------------------------+
void SetLevels2(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;
   FR2Buffer[_shift]=NormalizeDouble(FP+(FH-FL),Digits);
   FS2Buffer[_shift]=NormalizeDouble(FP-(FH-FL),Digits);
  }

//+------------------------------------------------------------------+
//| Óñòàíîâèòü óðîâíè FP, FR2 è FS2 â íîëü                           |
//+------------------------------------------------------------------+
void SetLevels2Empty(int _shift)
  {
   ExtMapBuffer1[_shift]=0.0;
   FR2Buffer[_shift]=0.0;
   FS2Buffer[_shift]=0.0;
  }
//+------------------------------------------------------------------+
//| Óñòàíîâêà óðîâíåé â íóëåâîì áàðå                                 |
//+------------------------------------------------------------------+
void SetNullBarLevels(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;
         FR2Buffer[_shift]=0.0;
         FS2Buffer[_shift]=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;
      FR2Buffer[_shift]=NormalizeDouble(FP+(FH-FL),Digits);
      FS2Buffer[_shift]=NormalizeDouble(FP-(FH-FL),Digits);
      }
//----
   return;
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(2);
   if (Formula!=0)Formula=1;
   string label1="FR2("+Formula+")";
   string label2="FS2("+Formula+")";
//---- indicators
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexBuffer(0,FR2Buffer);
   SetIndexEmptyValue(0,0.0);
   SetIndexLabel(0,label1);

   SetIndexStyle(1,DRAW_SECTION);
   SetIndexBuffer(1,FS2Buffer);
   SetIndexEmptyValue(1,0.0);
   SetIndexLabel(1,label2);

   SetIndexBuffer(2,ExtMapBuffer1);
   SetIndexEmptyValue(2,0.0);

//----
   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(-1);
   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)) SetLevels2(shift); else  SetLevels2Empty(shift);
      if (shift==0) SetNullBarLevels(shift);
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments