Author: unknown author, get from kaizer, conversed by Rosh
DFC High

This script is designed for the MetaTrader 4 platform to provide traders with a visual representation of price boundaries based on Fibonacci principles. Rather than showing a simple moving average, it calculates dynamic upper and lower bounds that react to specific market conditions and timeframes.

Core Logic and Functionality

1. Timeframe Awareness (Delimiters) The script is intelligent about how it views time. It includes a "Delimiter" system that identifies specific points in time based on the chart's timeframe. For example, depending on whether you are looking at 15-minute, hourly, or daily charts, the script recognizes key structural shifts (like the start of a new day or a specific hour). These markers act as anchors for its calculations.

2. Dynamic Price Range Calculation The tool calculates two primary boundaries:

  • Upper Bound: A ceiling based on high price movements.
  • Lower Bound: A floor based on low price movements.

To determine these, the script looks back over a specific number of periods (defined by the user) to find the highest highs and lowest lows. It then calculates a " trung tâm" (average) value using a weighted formula that considers the high, the low, and the previous closing price. The upper and lower boundaries are then projected outward from this average using a specific Fibonacci ratio (defaulting to 0.786).

3. Handling of Gaps and Movement The logic includes specific rules for different scenarios:

  • Standard Updates: When the script hits a "delimiter" (like a new session), it recalculates the boundaries based on the most recent significant price action.
  • Current Bar Updates: It performs a special calculation for the very last (live) candle to ensure the boundaries stay relevant as price moves in real-time.
  • Linear Interpolation: If the user chooses to show all historical data smoothly, the script can "fill in" the gaps between major delimiters with straight lines, ensuring the visual output is continuous rather than jumping from one point to another.

Visual Representation

The script produces two main visual elements on your chart:

  • Blue/Yellow Lines: These represent the upper and lower boundaries. Depending on your settings, these can appear as solid lines or sections that appear only during specific market periods.
  • Dynamic Scaling: Because the boundaries are based on a ratio of the price range (High to Low), the "channel" will expand when the market is volatile and contract when the market is consolidating.

Summary for the Trader

Think of this script as an automated way to draw "Fibonacci Channels." Instead of you manually identifying highs and lows and drawing lines, the script identifies the significant price swings automatically based on the time of day and the volatility of the recent candles, providing you with a clearer picture of the current market range.

Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
DFC High
//+------------------------------------------------------------------------------------+
//|                                                Din_fibo_high.mq4                   |
//|                                 unknown author, get from kaizer, conversed by Rosh |
//| link to kaizer: http://forum.alpari-idc.ru/profile.php?mode=viewprofile&u=4196161  |
//|                                              http://forexsystems.ru/phpBB/index.php|
//+------------------------------------------------------------------------------------+
#property copyright "unknown author, get from kaizer, conversed by Rosh"
#property link      "http://fx.winm.ru/book.htm"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Yellow
//---- input parameters
extern int       Fibo_Channel_Period=3;
extern double    Ratio=0.786;
extern bool      SetAllBars=false;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double tvBuffer[];
int hh,ll,first,counterPeriod;
double tv,MaH,MaL;
//+------------------------------------------------------------------+
//| Ïðîâåðèì - ðàçäåëèòåëü äèàïàçîíà èëè íåò                         |
//+------------------------------------------------------------------+
bool isDelimeter(int _Period, int _shift)
  {
  bool result=false;
//---- 
  switch (_Period)
   {
   case 5:result=(TimeMinute(Time[_shift])==0)&&(TimeHour(Time[_shift])==0); break;
   case 15:result=(TimeMinute(Time[_shift])==0)&&(TimeHour(Time[_shift])==0); break;
   case 30:result=(TimeMinute(Time[_shift])==0)&&(TimeHour(Time[_shift])==0); break;
   case 60:result=(TimeMinute(Time[_shift])==0)&&(TimeHour(Time[_shift])==0); break;
   case 240:result=(TimeDayOfWeek(Time[_shift])==1)&&(TimeHour(Time[_shift])==0); break;
   case 1440:result=(TimeDay(Time[_shift])==1)||((TimeDay(Time[_shift])==2 && TimeDay(Time[_shift+1])!=1))||((TimeDay(Time[_shift])==3 && TimeDay(Time[_shift+1])!=2)); break;
   case 10080:result=TimeDay(Time[_shift])<=7 && TimeMonth(Time[_shift])==1; break;
   default: Print("Íåäîïóñòèìûé ïåðèîä!!!"); 
   }
//----
   return(result);
  }
//+------------------------------------------------------------------+
//| Óñòàíîâèì MaH è MaL íà ãðàíèöå äèàïàçîíà                           |
//+------------------------------------------------------------------+
void SetHnL(int _shift)
  {
//---- 
   int i=_shift+1;
   counterPeriod=0;
   first=0;
   while (counterPeriod<Fibo_Channel_Period)
      {
      while (tvBuffer[i]==0.0 && i<Bars) i++;
      if (first==0) first=i;
      counterPeriod++;
      i++;
      }
   i--;   
   hh=Highest(NULL,0,MODE_HIGH,i-_shift,_shift+1);
   ll=Lowest(NULL,0,MODE_LOW,i-_shift,_shift+1);
   tv=NormalizeDouble((High[hh]+Low[ll]+Close[_shift+1])/3.0,Digits);
   MaH=tv+NormalizeDouble((High[hh]-Low[ll])/2.0*Ratio,Digits);
   MaL=tv-NormalizeDouble((High[hh]-Low[ll])/2.0*Ratio,Digits);
   tvBuffer[_shift]=tv;
   ExtMapBuffer1[_shift]=MaH;
   ExtMapBuffer2[_shift]=MaL;
   if (SetAllBars) SetMovingHnL(first, _shift);    
   
//----
   return;
  }
//+------------------------------------------------------------------+
//| Óñòàíîâèì MaH è MaL âíóòðè äèàïàçîíà                             |
//+------------------------------------------------------------------+
void SetMovingHnL(int _DelimeterBar,int CurBar)
  {
   int m_cnt;
   double deltaH,deltaL;
//---- 
   deltaH=(ExtMapBuffer1[_DelimeterBar]-ExtMapBuffer1[CurBar])/(_DelimeterBar-CurBar);
   deltaL=(ExtMapBuffer2[_DelimeterBar]-ExtMapBuffer2[CurBar])/(_DelimeterBar-CurBar);
   for (m_cnt=_DelimeterBar-1;m_cnt>CurBar;m_cnt--)
      {
      ExtMapBuffer1[m_cnt]=ExtMapBuffer1[m_cnt+1]-deltaH;
      ExtMapBuffer2[m_cnt]=ExtMapBuffer2[m_cnt+1]-deltaL;
      }
   for (m_cnt=_DelimeterBar-1;m_cnt>CurBar;m_cnt--)
      {
      ExtMapBuffer1[m_cnt]=NormalizeDouble(ExtMapBuffer1[m_cnt],Digits);
      ExtMapBuffer2[m_cnt]=NormalizeDouble(ExtMapBuffer2[m_cnt],Digits);
      }  
//----
   return;
  }
//+------------------------------------------------------------------+
//| Óñòàíîâèì MaH è MaL íà ïðàâîì êðàþ                               |
//+------------------------------------------------------------------+
void SetValuesNullBar(int _shift)
  {
//---- 
   int i=_shift;
   while (tvBuffer[i]==0.0) i++;
   for (int j=i-1;j>_shift;j--)
      {
      ExtMapBuffer1[j]=0.0;
      ExtMapBuffer2[j]=0.0;
      }
   first=0;
   i=_shift;
   counterPeriod=0;
   while (counterPeriod<Fibo_Channel_Period)
      {
      while (tvBuffer[i]==0.0 && i<Bars) i++;
      if (first==0) first=i;
      counterPeriod++;
      i++;
      }
   i--;   
   hh=Highest(NULL,0,MODE_HIGH,i-_shift,_shift);
   ll=Lowest(NULL,0,MODE_LOW,i-_shift,_shift);
   tv=NormalizeDouble((High[hh]+Low[ll]+Close[_shift])/3.0,Digits);
   MaH=tv+NormalizeDouble((High[hh]-Low[ll])/2.0*Ratio,Digits);
   MaL=tv-NormalizeDouble((High[hh]-Low[ll])/2.0*Ratio,Digits);
   ExtMapBuffer1[_shift]=MaH;
   ExtMapBuffer2[_shift]=MaL;
   if (SetAllBars) SetMovingHnL(first,_shift);    
//----
   return;
  }//-------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(3);
   if (SetAllBars)
      {
      SetIndexStyle(0,DRAW_LINE);
      SetIndexBuffer(0,ExtMapBuffer1);
      SetIndexLabel(0,"MaH("+Fibo_Channel_Period+")");
      SetIndexEmptyValue(0,0.0);

      SetIndexStyle(1,DRAW_LINE);
      SetIndexBuffer(1,ExtMapBuffer2);
      SetIndexLabel(1,"MaL("+Fibo_Channel_Period+")");
      SetIndexEmptyValue(1,0.0);
      }
   else
      {
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel(0,"MaH("+Fibo_Channel_Period+")");
   SetIndexEmptyValue(0,0.0);

   SetIndexStyle(1,DRAW_SECTION);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(1,"MaL("+Fibo_Channel_Period+")");
   SetIndexEmptyValue(1,0.0);
      }

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

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int cnt,limit;

//---- 
   if (Period()==10080) return;
   if (counted_bars<0) return(-1);
   if (counted_bars>0) limit=Bars-counted_bars;
   if (counted_bars==0)
      {
      // íàéòè ïåðâûé è âòîðîé ðàçäåëèòåëü è óñòàíîâèòü limit
      cnt=Bars-1;
      while (!isDelimeter(Period(),cnt)) cnt--;
      first=cnt;
      cnt--;
      counterPeriod=0;
      while (counterPeriod<Fibo_Channel_Period)
         {
         while (!isDelimeter(Period(),cnt)) cnt--;
         cnt--;
         counterPeriod++;
         }
      cnt++;
      hh=Highest(NULL,0,MODE_HIGH,first-cnt,cnt+1);
      ll=Lowest(NULL,0,MODE_LOW,first-cnt,cnt+1);
      tv=NormalizeDouble((High[hh]+Low[ll]+Close[cnt+1])/3.0,Digits);
      MaH=tv+NormalizeDouble((High[hh]-Low[ll])/2.0*Ratio,Digits);
      MaL=tv-NormalizeDouble((High[hh]-Low[ll])/2.0*Ratio,Digits);
      tvBuffer[cnt]=tv;
      ExtMapBuffer1[cnt]=MaH;
      ExtMapBuffer2[cnt]=MaL;
      limit=cnt-1;
      }   
//----
   for (int shift=limit;shift>=0;shift--)
      {
      if (isDelimeter(Period(),shift)) SetHnL(shift);// else SetMovingHnL(shift);
      if (shift==0) SetValuesNullBar(shift);
      }
      
   return(0);
  }
//+------------------------------------------------------------------+

Comments