Din_fibo_high_v2
Download scriptThis tool is designed to provide visual guidance on a trading chart by identifying specific price boundaries based on historical highs and lows. It functions by analyzing price action over defined segments of time to establish "high" and "low" markers, which helps traders understand the prevailing range of a market's movement.
Core Logic and Behavior
1. Time-Based Segmentation The script operates by identifying specific "delimiters" or break points on the chart. Depending on the timeframe you are using (e.g., 5-minute, 1-hour, or daily charts), the tool recognizes specific significant moments—such as the start of a new hour, day, or week. It uses these anchors to slice the market history into manageable sections.
2. Range Identification Once it identifies a section of time, the script looks back to find the highest price point (High) and the lowest price point (Low) reached during that specific period. From these two extremes, it calculates a "Typical Value," which is a balanced average of the highs, lows, and closing prices.
3. Dynamic Boundary Calculation Using the Typical Value as a center point, the script projects two boundaries:
- Upper Boundary (MaH): Calculated by projecting upward from the center based on the distance between the high and low extremes.
- Lower Boundary (MaL): Calculated by projecting downward from the center using the same logic.
A specific "Ratio" setting allows you to control how far these boundaries extend, essentially defining the "width" of the trading zone relative to the price volatility observed in that period.
4. Visual Presentation The tool offers two different ways to display this data on your chart:
- Section Mode: It draws the boundaries as distinct sections, making it easier to see how the market range changes from one time block to the next.
- Continuous Mode: If enabled, it connects these boundaries into a continuous line, providing a smoother visual flow of the price "envelope."
5. Real-Time Updates The script is designed to be reactive. As new price data arrives, it continuously recalculates the highest and lowest points within its active window. It also includes specific logic to handle the very last bar on the chart (the current live candle) to ensure that the boundaries remain accurate and up-to-date as the market moves in real-time.
Summary for the User
In simple terms, this script acts like a "smart ruler." It looks at how much the price moved during a specific time frame, finds the middle of that move, and then draws a zone above and below it. This helps you see where the "normal" trading range is located, making it easier to identify when the price is reaching extreme levels or staying within a consolidated area.
//+------------------------------------------------------------------------------------+
//| 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://forexsystems.ru/phpBB/index.php"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Yellow
//---- input parameters
extern int Ch_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;
while(counterPeriod<Ch_Period)
{
while(tvBuffer[i]==0.0 && i<Bars) 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;
SetMovingHnL(i, _shift);
//----
return;
}
//+------------------------------------------------------------------+
//| Óñòàíîâèì MaH è MaL âíóòðè äèàïàçîíà |
//+------------------------------------------------------------------+
void SetMovingHnL(int _DelimeterBar,int CurBar)
{
double delta;
//----
delta=(tvBuffer[_DelimeterBar]-tvBuffer[CurBar])/(_DelimeterBar-CurBar);
//----
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;
}
i=_shift;
counterPeriod=0;
while(counterPeriod<Ch_Period)
{
while(tvBuffer[i]==0.0 && i<Bars) 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;
//SetMovingHnL(j, _shift);
//----
return;
}
//-------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(3);
if (SetAllBars)
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexLabel(0,"MaH");
SetIndexEmptyValue(0,0.0);
//----
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexLabel(1,"MaL");
SetIndexEmptyValue(1,0.0);
}
else
{
SetIndexStyle(0,DRAW_SECTION);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexLabel(0,"MaH");
SetIndexEmptyValue(0,0.0);
//----
SetIndexStyle(1,DRAW_SECTION);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexLabel(1,"MaL");
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<Ch_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