Price Data Components
3
Views
0
Downloads
0
Favorites
AutoFibAutoTrend_OnParabolic
ÿþ//+------------------------------------------------------------------+
//| AutoFibAutoTrend_OnParabolic.mq5 |
//| Copyright © 2016, zzuegg |
//| when-money-makes-money.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, zzuegg"
#property link "when-money-makes-money.com"
//---- =><5@ 25@A88 8=48:0B>@0
#property version "1.00"
//+------------------------------------------------+
//| 0@0<5B@K >B@8A>2:8 8=48:0B>@0 |
//+------------------------------------------------+
//---- >B@8A>2:0 8=48:0B>@0 2 3;02=>< >:=5
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
//+------------------------------------------------+
//| 1JO2;5=85 :>=AB0=B |
//+------------------------------------------------+
#define RESET 0 // >=AB0=B0 4;O 2>72@0B0 B5@<8=0;C :><0=4K =0 ?5@5AG5B 8=48:0B>@0
//+------------------------------------------------+
//| E>4=K5 ?0@0<5B@K 8=48:0B>@0 |
//+------------------------------------------------+
//---- E>4=K5 ?0@0<5B@K 837030
input ENUM_TIMEFRAMES Timeframe=PERIOD_H6; // "09<D@59< 837030 4;O @0AG5B0 8=48:0B>@0
input double Step=0.02; // SAR H03
input double Maximum=0.2; // SAR <0:A8<C<
input bool ExtremumsShift=true; // D;03 A42830 25@H8=K
//---- =0AB@>9:8 287C0;L=>3> >B>1@065=8O 8=48:0B>@0
input string Sirname="AutoFibAutoTrend_OnParabolic"; // 0720=85 4;O <5B>: 8=48:0B>@0
input bool ShowFib=true;
input color FibColor=clrMagenta;
input uint FibSize=1;
//----
input bool ShowFibFan=true;
input color FibFanColor=clrMediumSpringGreen;
input uint FibFanSize=1;
//----
input bool ShowTrend=true;
input color TrendColor=clrDodgerBlue;
input uint TrendSize=5;
//+-----------------------------------+
//---- >1JO2;5=85 F5;>G8A;5==KE ?5@5<5==KE 4;O E5=4;>2 8=48:0B>@>2
int Ind_Handle;
//---- >1JO2;5=85 F5;>G8A;5==KE ?5@5<5==KE =0G0;0 >BAG5B0 40==KE
int min_rates_total;
string fib1="";
string trend="";
string fibf1="";
//+------------------------------------------------------------------+
//| >;CG5=85 B09<D@59<0 2 2845 AB@>:8 |
//+------------------------------------------------------------------+
string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
{return(StringSubstr(EnumToString(timeframe),7,-1));}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- =8F80;870F8O ?5@5<5==KE =0G0;0 >BAG5B0 40==KE
min_rates_total=100;
//---- 8=8F80;870F8O ?5@5<5==KE
fib1=Sirname+" fib1 "+GetStringTimeframe(Timeframe);
trend=Sirname+" trend1 "+GetStringTimeframe(Timeframe);
fibf1=Sirname+" fibf1 "+GetStringTimeframe(Timeframe);
//---- ?>;CG5=85 E5=4;0 8=48:0B>@0 ZigZagOnParabolic
Ind_Handle=iCustom(Symbol(),Timeframe,"ZigZagOnParabolic",Step,Maximum,ExtremumsShift);
if(Ind_Handle==INVALID_HANDLE)
{
Print(" 5 C40;>AL ?>;CG8BL E5=4; 8=48:0B>@0 ZigZagOnParabolic");
return(INIT_FAILED);
}
//---- 8<O 4;O >:>= 40==KE 8 ;M910 4;O AC1J>:>=
string shortname;
StringConcatenate(shortname,"AutoFibAutoTrend_OnParabolic(Step=",Step,"Maximum = ",Maximum,"ExtremumsShift = ",ExtremumsShift,")");
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);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//----
ObjectDelete(0,fib1);
ObjectDelete(0,trend);
ObjectDelete(0,fibf1);
//----
ChartRedraw(0);
}
//+------------------------------------------------------------------+
//| Custom indicator 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 @0AG5B0
if(BarsCalculated(Ind_Handle)<min_rates_total) return(RESET);
if(BarsCalculated(Ind_Handle)<Bars(Symbol(),Timeframe)) return(prev_calculated);
//---- >1JO2;5=85 ;>:0;L=KE ?5@5<5==KE
double UpSign[],DnSign[];
static datetime TIME[];
//---- :>?8@C5< 2=>2L ?>O282H85AO 40==K5 2 <0AA82K
if(CopyBuffer(Ind_Handle,0,0,rates_total,DnSign)<=0) return(RESET);
if(CopyBuffer(Ind_Handle,1,0,rates_total,UpSign)<=0) return(RESET);
if(CopyTime(Symbol(),Timeframe,0,rates_total,TIME)<=0) return(RESET);
//---- 8=45:A0F8O M;5<5=B>2 2 <0AA820E, :0: 2 B09<A5@8OE
ArraySetAsSeries(DnSign,true);
ArraySetAsSeries(UpSign,true);
ArraySetAsSeries(TIME,true);
static datetime curr=NULL;
if(curr!=TIME[0])
{
curr=TIME[0];
double swing_value[4]={0,0,0,0};
datetime swing_date[4]={0,0,0,0};
int found=NULL;
double tmp=NULL;
int bar=NULL;
while(found<4 && bar<rates_total)
{
if(UpSign[bar])
{
swing_value[found]=UpSign[bar];
swing_date[found]=TIME[bar];
found++;
}
if(DnSign[bar])
{
swing_value[found]=DnSign[bar];
swing_date[found]=TIME[bar];
found++;
}
bar++;
}
if(ShowTrend) SetChannel(0,trend,0,swing_date[3],swing_value[3],swing_date[1],swing_value[1],swing_date[2],swing_value[2],TrendColor,0,TrendSize,true,trend);
if(ShowFib) SetFibo(0,fib1,0,swing_date[2],swing_value[2],swing_date[1],swing_value[1],FibColor,0,FibSize,true,fib1);
if(ShowFibFan) SetFiboFan(0,fibf1,0,swing_date[2],swing_value[2],swing_date[1],swing_value[1],FibFanColor,0,FibFanSize,true,fibf1);
}
//----
ChartRedraw(0);
return(rates_total);
}
//+------------------------------------------------------------------+
//| !>740=85 $81> |
//+------------------------------------------------------------------+
void CreateFibo
(
long chart_id, // 845=B8D8:0B>@ 3@0D8:0
string name, // 8<O >1J5:B0
int nwin, // 8=45:A >:=0
datetime time1, // 2@5<O 1 F5=>2>3> C@>2=O
double price1, // 1 F5=>2>9 C@>25=L
datetime time2, // 2@5<O 2 F5=>2>3> C@>2=O
double price2, // 2 F5=>2>9 C@>25=L
color Color, // F25B ;8=88
int style, // AB8;L ;8=88
int width, // B>;I8=0 ;8=88
int ray, // =0?@02;5=85 ;CG0: -1 - 2;52>, +1 - 2?@02>, >AB0;L=K5 7=0G5=8O - =5B ;CG0
string text // B5:AB
)
//----
{
//----
ObjectCreate(chart_id,name,OBJ_FIBO,nwin,time1,price1,time2,price2);
ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);
ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style);
ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width);
if(ray>0)ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,true);
if(ray<0)ObjectSetInteger(chart_id,name,OBJPROP_RAY_LEFT,true);
if(ray==0)
{
ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,false);
ObjectSetInteger(chart_id,name,OBJPROP_RAY_LEFT,false);
}
ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);
for(int numb=0; numb<10; numb++)
{
ObjectSetInteger(chart_id,name,OBJPROP_LEVELCOLOR,numb,Color);
ObjectSetInteger(chart_id,name,OBJPROP_LEVELSTYLE,numb,style);
ObjectSetInteger(chart_id,name,OBJPROP_LEVELWIDTH,numb,width);
}
//----
}
//+------------------------------------------------------------------+
//| 5@5CAB0=>2:0 $81> |
//+------------------------------------------------------------------+
void SetFibo
(
long chart_id, // 845=B8D8:0B>@ 3@0D8:0
string name, // 8<O >1J5:B0
int nwin, // 8=45:A >:=0
datetime time1, // 2@5<O 1 F5=>2>3> C@>2=O
double price1, // 1 F5=>2>9 C@>25=L
datetime time2, // 2@5<O 2 F5=>2>3> C@>2=O
double price2, // 2 F5=>2>9 C@>25=L
color Color, // F25B ;8=88
int style, // AB8;L ;8=88
int width, // B>;I8=0 ;8=88
int ray, // =0?@02;5=85 ;CG0: -1 - 2;52>, 0 - =5B ;CG0, +1 - 2?@02>
string text // B5:AB
)
//----
{
//----
if(ObjectFind(chart_id,name)==-1) CreateFibo(chart_id,name,nwin,time1,price1,time2,price2,Color,style,width,ray,text);
else
{
ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
ObjectMove(chart_id,name,0,time1,price1);
ObjectMove(chart_id,name,1,time2,price2);
}
//----
}
//+------------------------------------------------------------------+
//| !>740=85 $81> |
//+------------------------------------------------------------------+
void CreateFiboFan
(
long chart_id, // 845=B8D8:0B>@ 3@0D8:0
string name, // 8<O >1J5:B0
int nwin, // 8=45:A >:=0
datetime time1, // 2@5<O 1 F5=>2>3> C@>2=O
double price1, // 1 F5=>2>9 C@>25=L
datetime time2, // 2@5<O 2 F5=>2>3> C@>2=O
double price2, // 2 F5=>2>9 C@>25=L
color Color, // F25B ;8=88
int style, // AB8;L ;8=88
int width, // B>;I8=0 ;8=88
int ray, // =0?@02;5=85 ;CG0: -1 - 2;52>, +1 - 2?@02>, >AB0;L=K5 7=0G5=8O - =5B ;CG0
string text // B5:AB
)
//----
{
//----
ObjectCreate(chart_id,name,OBJ_FIBOFAN,nwin,time1,price1,time2,price2);
ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);
ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style);
ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width);
if(ray>0)ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,true);
if(ray<0)ObjectSetInteger(chart_id,name,OBJPROP_RAY_LEFT,true);
if(ray==0)
{
ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,false);
ObjectSetInteger(chart_id,name,OBJPROP_RAY_LEFT,false);
}
ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);
for(int numb=0; numb<10; numb++)
{
ObjectSetInteger(chart_id,name,OBJPROP_LEVELCOLOR,numb,Color);
ObjectSetInteger(chart_id,name,OBJPROP_LEVELSTYLE,numb,style);
ObjectSetInteger(chart_id,name,OBJPROP_LEVELWIDTH,numb,width);
}
//----
}
//+------------------------------------------------------------------+
//| 5@5CAB0=>2:0 $81> |
//+------------------------------------------------------------------+
void SetFiboFan
(
long chart_id, // 845=B8D8:0B>@ 3@0D8:0
string name, // 8<O >1J5:B0
int nwin, // 8=45:A >:=0
datetime time1, // 2@5<O 1 F5=>2>3> C@>2=O
double price1, // 1 F5=>2>9 C@>25=L
datetime time2, // 2@5<O 2 F5=>2>3> C@>2=O
double price2, // 2 F5=>2>9 C@>25=L
color Color, // F25B ;8=88
int style, // AB8;L ;8=88
int width, // B>;I8=0 ;8=88
int ray, // =0?@02;5=85 ;CG0: -1 - 2;52>, 0 - =5B ;CG0, +1 - 2?@02>
string text // B5:AB
)
//----
{
//----
if(ObjectFind(chart_id,name)==-1) CreateFiboFan(chart_id,name,nwin,time1,price1,time2,price2,Color,style,width,ray,text);
else
{
ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
ObjectMove(chart_id,name,0,time1,price1);
ObjectMove(chart_id,name,1,time2,price2);
}
//----
}
//+------------------------------------------------------------------+
//| !>740=85 :0=0;0 |
//+------------------------------------------------------------------+
void CreateChannel
(
long chart_id, // 845=B8D8:0B>@ 3@0D8:0
string name, // 8<O >1J5:B0
int nwin, // 8=45:A >:=0
datetime time1, // 2@5<O 1 F5=>2>3> C@>2=O
double price1, // 1 F5=>2>9 C@>25=L
datetime time2, // 2@5<O 2 F5=>2>3> C@>2=O
double price2, // 2 F5=>2>9 C@>25=L
datetime time3, // 2@5<O 3 F5=>2>3> C@>2=O
double price3, // 3 F5=>2>9 C@>25=L
color Color, // F25B ;8=88
int style, // AB8;L ;8=88
int width, // B>;I8=0 ;8=88
int ray, // =0?@02;5=85 ;CG0: -1 - 2;52>, +1 - 2?@02>, >AB0;L=K5 7=0G5=8O - =5B ;CG0
string text // B5:AB
)
//----
{
//----
ObjectCreate(chart_id,name,OBJ_CHANNEL,nwin,time1,price1,time2,price2,time3,price3);
ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);
ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style);
ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width);
if(ray>0)ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,true);
if(ray<0)ObjectSetInteger(chart_id,name,OBJPROP_RAY_LEFT,true);
if(ray==0)
{
ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,false);
ObjectSetInteger(chart_id,name,OBJPROP_RAY_LEFT,false);
}
ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);
for(int numb=0; numb<10; numb++)
{
ObjectSetInteger(chart_id,name,OBJPROP_LEVELCOLOR,numb,Color);
ObjectSetInteger(chart_id,name,OBJPROP_LEVELSTYLE,numb,style);
ObjectSetInteger(chart_id,name,OBJPROP_LEVELWIDTH,numb,width);
}
//----
}
//+------------------------------------------------------------------+
//| 5@5CAB0=>2:0 :0=0;0 |
//+------------------------------------------------------------------+
void SetChannel
(
long chart_id, // 845=B8D8:0B>@ 3@0D8:0
string name, // 8<O >1J5:B0
int nwin, // 8=45:A >:=0
datetime time1, // 2@5<O 1 F5=>2>3> C@>2=O
double price1, // 1 F5=>2>9 C@>25=L
datetime time2, // 2@5<O 2 F5=>2>3> C@>2=O
double price2, // 2 F5=>2>9 C@>25=L
datetime time3, // 2@5<O 3 F5=>2>3> C@>2=O
double price3, // 3 F5=>2>9 C@>25=L
color Color, // F25B ;8=88
int style, // AB8;L ;8=88
int width, // B>;I8=0 ;8=88
int ray, // =0?@02;5=85 ;CG0: -1 - 2;52>, 0 - =5B ;CG0, +1 - 2?@02>
string text // B5:AB
)
//----
{
//----
if(ObjectFind(chart_id,name)==-1) CreateChannel(chart_id,name,nwin,time1,price1,time2,price2,time3,price3,Color,style,width,ray,text);
else
{
ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
ObjectMove(chart_id,name,0,time1,price1);
ObjectMove(chart_id,name,1,time2,price2);
ObjectMove(chart_id,name,2,time3,price3);
}
//----
}
//+------------------------------------------------------------------+
Comments