1
Views
0
Downloads
0
Favorites
Din_fibo_Nex_Chn
ÿþ//+----------------------------------------------------------------------------------+
//| Din_fibo_Nex_Chn.mq5 |
//| Copyright © 2006, unknown author, get from kaizer, conversed by Rosh |
//|link to kaizer: http://forum.alpari-idc.ru/profile.php?mode=viewprofile&u=4196161 |
//+----------------------------------------------------------------------------------+
#property copyright "Copyright © 2006, unknown author, get from kaizer, conversed by Rosh"
#property link "http://forum.alpari-idc.ru/profile.php?mode=viewprofile&u=4196161"
#property description "=48:0B>@ ;8=88 ?5@5<5I5=8O B@59;8=AB>?0"
//---- =><5@ 25@A88 8=48:0B>@0
#property version "1.00"
//---- >B@8A>2:0 8=48:0B>@0 2 3;02=>< >:=5
#property indicator_chart_window
//---- :>;8G5AB2> 8=48:0B>@=KE 1CD5@>2 5
#property indicator_buffers 5
//---- 8A?>;L7>20=> 2A53> B@8 3@0D8G5A:8E ?>AB@>5=8O
#property indicator_plots 3
//+----------------------------------------------+
//| >1JO2;5=85 :>=AB0=B |
//+----------------------------------------------+
#define RESET 0 // >=AB0=B0 4;O 2>72@0B0 B5@<8=0;C :><0=4K =0 ?5@5AGQB 8=48:0B>@0
//+----------------------------------------------+
//| 0@0<5B@K >B@8A>2:8 8=48:0B>@0 >1;0:0 |
//+----------------------------------------------+
//---- >B@8A>2:0 8=48:0B>@0 1 2 2845 F25B=>3> >1;0:0
#property indicator_type1 DRAW_FILLING
//---- 2 :0G5AB25 F25Bjd 8=48:0B>@0 8A?>;L7>20=K
#property indicator_color1 clrLavender
//---- >B>1@065=85 1KG59 <5B:8 8=48:0B>@0
#property indicator_label1 "Din_fibo_Nex_Chn Cloud"
//+----------------------------------------------+
//| 0@0<5B@K >B@8A>2:8 8=48:0B>@0 1 |
//+----------------------------------------------+
//---- >B@8A>2:0 8=48:0B>@0 2 2 2845 ;8=88
#property indicator_type2 DRAW_LINE
//---- 2 :0G5AB25 F25B0 8=48:0B>@0 8A?>;L7>20=
#property indicator_color2 clrTeal
//---- B>;I8=0 ;8=88 8=48:0B>@0 2 @02=0 2
#property indicator_width2 2
//---- >B>1@065=85 <5B:8 8=48:0B>@0
#property indicator_label2 "Din_fibo_Nex MaH"
//+----------------------------------------------+
//| 0@0<5B@K >B@8A>2:8 8=48:0B>@0 2 |
//+----------------------------------------------+
//---- >B@8A>2:0 8=48:0B>@0 3 2 2845 ;8=88
#property indicator_type3 DRAW_LINE
//---- 2 :0G5AB25 F25B0 8=48:0B>@0 8A?>;L7>20=
#property indicator_color3 clrMaroon
//---- B>;I8=0 ;8=88 8=48:0B>@0 3 @02=0 2
#property indicator_width3 2
//---- >B>1@065=85 <5B:8 8=48:0B>@0
#property indicator_label3 "Din_fibo_Nex MaL"
//+----------------------------------------------+
//| %+ " + " |
//+----------------------------------------------+
input uint Fibo_Channel_Period=3;
input double Ratio=0.786;
//+----------------------------------------------+
//---- >1JO2;5=85 48=0<8G5A:8E <0AA82>2, :>B>@K5 1C4CB 2
// 40;L=59H5< 8A?>;L7>20=K 2 :0G5AB25 8=48:0B>@=KE 1CD5@>2
double ExtLineBuffer1[],ExtLineBuffer2[],ExtLineBuffer3[],ExtLineBuffer4[],tvBuffer[];
//---- 1JO2;5=85 F5;KE ?5@5<5==KE =0G0;0 >BAGQB0 40==KE
int min_rates_total;
//+------------------------------------------------------------------+
//| @>25@8< - @0745;8B5;L 480?07>=0 8;8 =5B |
//+------------------------------------------------------------------+
bool isDelimeter(int TimeFrame,int Rates_total,const datetime &Time[],int shift)
{
//----
bool result=false;
MqlDateTime tm;
TimeToStruct(Time[shift],tm);
//----
switch(TimeFrame)
{
case PERIOD_M1:result=(tm.min==0); break;
case PERIOD_M2:result=(tm.min==0); break;
case PERIOD_M3:result=(tm.min==0); break;
case PERIOD_M4:result=(tm.min==0); break;
case PERIOD_M5:result=(tm.min==0); break;
case PERIOD_M6:result=(tm.min==0); break;
case PERIOD_M10:result=(tm.min==0); break;
case PERIOD_M12:result=(tm.min==0); break;
case PERIOD_M15:result=(tm.min==0); break;
case PERIOD_M20:result=(tm.min==0); break;
case PERIOD_M30:result=(tm.min==0) && (MathMod(tm.hour,4.0)==0); break;
case PERIOD_H1:result=(tm.min==0) && (MathMod(tm.hour,4.0)==0); break;
case PERIOD_H2:result=(tm.min==0) && (MathMod(tm.hour,4.0)==0); break;
case PERIOD_H3:result=(tm.min==0) && (tm.hour==0); break;
case PERIOD_H4:result=(tm.min==0) && (tm.hour==0); break;
case PERIOD_H6:result=(tm.min==0) && (tm.hour==0); break;
case PERIOD_H8:result=(tm.min==0) && (tm.hour==0); break;
case PERIOD_H12:result=(tm.min==0) && (tm.hour==0); break;
case PERIOD_D1:result=(tm.day_of_week==MONDAY) && (tm.hour==0); break;
case PERIOD_W1:
{
MqlDateTime tm1;
TimeToStruct(Time[MathMin(Rates_total-1,shift+1)],tm1);
result=(tm.day==1) || (tm.day==2 && tm1.day!=1) || (tm.day==3 && tm1.day!=2); break;
}
default: Print("54>?CAB8<K9 B09<D@59<!!!");
}
//----
return(result);
}
//+------------------------------------------------------------------+
//| #AB0=>28< MaH 8 MaL =0 3@0=8F5 480?07>=0 |
//+------------------------------------------------------------------+
void SetHnL(int Rates_total,const double &Low[],const double &High[],const double &Close[],int shift)
{
//----
int i=shift+1;
int counterPeriod=0;
int first=0;
while(counterPeriod<int(Fibo_Channel_Period))
{
while(i<Rates_total && !tvBuffer[i]) i++;
if(!first) first=i;
counterPeriod++;
i++;
}
i--;
//----
int hh=ArrayMaximum(High,shift+1,i-shift);
int ll=ArrayMinimum(Low,shift+1,i-shift);
//----
double tv=NormalizeDouble((High[hh]+Low[ll]+Close[shift+1])/3.0,_Digits);
double diff=NormalizeDouble((High[hh]-Low[ll])/2.0*Ratio,_Digits);
double MaH=tv+diff;
double MaL=tv-diff;
tvBuffer[shift]=tv;
ExtLineBuffer1[shift]=ExtLineBuffer3[shift]=MaH;
ExtLineBuffer2[shift]=ExtLineBuffer4[shift]=MaL;
SetMovingHnL(first,shift);
//----
return;
}
//+------------------------------------------------------------------+
//| #AB0=>28< MaH 8 MaL 2=CB@8 480?07>=0 |
//+------------------------------------------------------------------+
void SetMovingHnL(int DelimeterBar,int CurBar)
{
int m_cnt;
double deltaH,deltaL;
//----
deltaH=(ExtLineBuffer1[DelimeterBar]-ExtLineBuffer1[CurBar])/(DelimeterBar-CurBar);
deltaL=(ExtLineBuffer2[DelimeterBar]-ExtLineBuffer2[CurBar])/(DelimeterBar-CurBar);
//----
for(m_cnt=DelimeterBar-1; m_cnt>CurBar; m_cnt--)
{
ExtLineBuffer1[m_cnt]=ExtLineBuffer3[m_cnt]=ExtLineBuffer1[m_cnt+1]-deltaH;
ExtLineBuffer2[m_cnt]=ExtLineBuffer4[m_cnt]=ExtLineBuffer2[m_cnt+1]-deltaL;
}
//----
for(m_cnt=DelimeterBar-1; m_cnt>CurBar; m_cnt--)
{
ExtLineBuffer1[m_cnt]=ExtLineBuffer3[m_cnt]=NormalizeDouble(ExtLineBuffer1[m_cnt],_Digits);
ExtLineBuffer2[m_cnt]=ExtLineBuffer4[m_cnt]=NormalizeDouble(ExtLineBuffer2[m_cnt],_Digits);
}
//----
return;
}
//+------------------------------------------------------------------+
//| #AB0=>28< MaH 8 MaL =0 ?@02>< :@0N |
//+------------------------------------------------------------------+
void SetValuesNullBar(int Rates_total,const double &Low[],const double &High[],const double &Close[],int shift)
{
//----
int i=shift;
while(!tvBuffer[i]) i++;
for(int j=i-1; j>shift; j--)
{
ExtLineBuffer1[j]=ExtLineBuffer3[j]=0.0;
ExtLineBuffer2[j]=ExtLineBuffer4[j]=0.0;
}
//----
int first=0;
i=shift;
int counterPeriod=0;
while(counterPeriod<int(Fibo_Channel_Period))
{
while( i<Rates_total && !tvBuffer[i]) i++;
if(!first) first=i;
counterPeriod++;
i++;
}
i--;
//----
int hh=ArrayMaximum(High,shift,i-shift);
int ll=ArrayMinimum(Low,shift,i-shift);
//----
double tv=NormalizeDouble((High[hh]+Low[ll]+Close[shift])/3.0,_Digits);
double diff=NormalizeDouble((High[hh]-Low[ll])/2.0*Ratio,_Digits);
double MaH=tv+diff;
double MaL=tv-diff;
ExtLineBuffer1[shift]=ExtLineBuffer3[shift]=MaH;
ExtLineBuffer2[shift]=ExtLineBuffer4[shift]=MaL;
SetMovingHnL(first,shift);
}
//+------------------------------------------------------------------+
//| SL_ATR indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- ?@>25@:0 B09<D@59<0 =0 20;84=>ABL
if(Period()==PERIOD_MN1)
{
Print("54>?CAB8<K9 B09<D@59<!!!");
return(INIT_FAILED);
}
//---- =8F80;870F8O ?5@5<5==KE =0G0;0 >BAGQB0 40==KE
min_rates_total=int(20*Fibo_Channel_Period)+1;
//---- ?@52@0I5=85 48=0<8G5A:8E <0AA82>2 2 8=48:0B>@=K5 1CD5@K
SetIndexBuffer(0,ExtLineBuffer1,INDICATOR_DATA);
SetIndexBuffer(1,ExtLineBuffer2,INDICATOR_DATA);
SetIndexBuffer(2,ExtLineBuffer3,INDICATOR_DATA);
SetIndexBuffer(3,ExtLineBuffer4,INDICATOR_DATA);
SetIndexBuffer(4,tvBuffer,INDICATOR_CALCULATIONS);
//---- CAB0=>2:0 ?>78F88, A :>B>@>9 =0G8=05BAO >B@8A>2:0 8=48:0B>@>2
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);
//---- 70?@5B =0 >B@8A>2:C 8=48:0B>@>< ?CABKE 7=0G5=89
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@0E :0: 2 B09<A5@8OE
ArraySetAsSeries(ExtLineBuffer1,true);
ArraySetAsSeries(ExtLineBuffer2,true);
ArraySetAsSeries(ExtLineBuffer3,true);
ArraySetAsSeries(ExtLineBuffer4,true);
ArraySetAsSeries(tvBuffer,true);
//---- 8=8F80;870F88 ?5@5<5==>9 4;O :>@>B:>3> 8<5=8 8=48:0B>@0
string shortname;
StringConcatenate(shortname,"Din_fibo_Nex(",Fibo_Channel_Period,",",DoubleToString(Ratio,4),")");
//--- A>740=85 8<5=8 4;O >B>1@065=8O 2 >B45;L=>< ?>4>:=5 8 2> 2A?;K20NI59 ?>4A:07:5
IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//--- >?@545;5=85 B>G=>AB8 >B>1@065=8O 7=0G5=89 8=48:0B>@0
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- 7025@H5=85 8=8F80;870F88
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| SL_ATR iteration function |
//+------------------------------------------------------------------+
int OnCalculate(
const int rates_total, // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5
const int prev_calculated,// :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]
)
{
//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AGQB0
if(rates_total<min_rates_total) return(RESET);
//---- >1JO2;5=8O ;>:0;L=KE ?5@5<5==KE
int limit,bar;
//---- 8=45:A0F8O M;5<5=B>2 2 <0AA820E :0: 2 B09<A5@8OE
ArraySetAsSeries(time,true);
ArraySetAsSeries(close,true);
ArraySetAsSeries(high,true);
ArraySetAsSeries(low,true);
//---- @0AGQB AB0@B>2>3> =><5@0 limit 4;O F8:;0 ?5@5AGQB0 10@>2
if(prev_calculated>rates_total || prev_calculated<=0)// ?@>25@:0 =0 ?5@2K9 AB0@B @0AGQB0 8=48:0B>@0
{
//---- =09B8 ?5@2K9 8 2B>@>9 @0745;8B5;L 8 CAB0=>28BL limit
bar=rates_total-1;
while(!isDelimeter(Period(),rates_total,time,bar)) bar--;
int first=bar;
bar--;
int counterPeriod=0;
while(counterPeriod<int(Fibo_Channel_Period))
{
while(!isDelimeter(Period(),rates_total,time,bar)) bar--;
bar--;
counterPeriod++;
}
bar++;
int hh=ArrayMaximum(high,bar+1,first-bar);
int ll=ArrayMinimum(low,bar+1,first-bar);
double tv=NormalizeDouble((high[hh]+low[ll]+close[bar+1])/3.0,_Digits);
double MaH=tv+NormalizeDouble((high[hh]-low[ll])/2.0*Ratio,_Digits);
double MaL=tv-NormalizeDouble((high[hh]-low[ll])/2.0*Ratio,_Digits);
tvBuffer[bar]=tv;
ExtLineBuffer1[bar]=ExtLineBuffer3[bar]=MaH;
ExtLineBuffer2[bar]=ExtLineBuffer4[bar]=MaL;
limit=bar-1; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2
}
else limit=rates_total-prev_calculated; // AB0@B>2K9 =><5@ 4;O @0AGQB0 =>2KE 10@>2
//---- >A=>2=>9 F8:; @0AGQB0 8=48:0B>@0
for(bar=limit; bar>=0 && !IsStopped(); bar--)
{
tvBuffer[bar]=0.0;
if(isDelimeter(Period(),rates_total,time,bar)) SetHnL(rates_total,low,high,close,bar);
if(!bar) SetValuesNullBar(rates_total,low,high,close,bar);
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+
Comments