ytg_fibo_zz

Author: Yuriy Tokman
Indicators Used
Indicator of the average true range
0 Views
0 Downloads
0 Favorites
ytg_fibo_zz
//+------------------------------------------------------------------+
//|                                                  ytg_fibo_zz.mq4 |
//|                                                     Yuriy Tokman |
//|                                         http://www.mql-design.ru |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link      "http://www.mql-design.ru"

#property indicator_chart_window

extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;
extern int TimeFrame = 60;
extern color color_s = Gold;
extern color color_l = Yellow;
extern int DELTA_K = 30;

string name ;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   name = "ytg_"+WindowExpertName()+"_"+GetNameTF(TimeFrame)+"_"+ExtDepth;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   GetDellName();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   double atr = iATR(Symbol(),1,55,0);GetYTG();GetAvtor();
   
   double level_100;datetime time_100;double level_0;datetime time_0;
   GetLVL(level_100,time_100,level_0,time_0);
   
   GetTLINE(name,time_100,level_100,time_0,level_0,color_s,2,0,false);   
   GetTLINE(name+"_level_100",time_100,level_100,time_0,level_100,color_l,1);
   GetTXT(name+"_level_100t",Time[0], level_100+atr,color_l, DoubleToStr(level_100,Digits)+" (100%)"+GetNameTF(TimeFrame));          
   GetTLINE(name+"_level_0",time_100,level_0,time_0,level_0,color_l,1);
   GetTXT(name+"_level_0t",Time[0], level_0+atr,color_l, DoubleToStr(level_0,Digits)+" (0%)"+GetNameTF(TimeFrame));          
   double delta = MathAbs(level_100-level_0);
   double level_50, level_618, level_382,level_236,level_146, level_810;
   string pref = "(up)";
   if(level_0>level_100)//up trend
    {
     level_50 = level_0 - delta*0.5;
     level_618 = level_0 - delta*0.618;
     level_382 = level_0 - delta*0.382;
     level_236 = level_0 - delta*0.236;
     level_146 = level_0 - delta*0.146;
     level_810 = level_0 - delta*0.81;                         
    }   
   if(level_0<level_100)//down trend
    { 
     pref = "(dn)";
     level_50 = level_0 + delta*0.5;
     level_618 = level_0 + delta*0.618;
     level_382 = level_0 + delta*0.382;
     level_236 = level_0 + delta*0.236;
     level_146 = level_0 + delta*0.146;
     level_810 = level_0 + delta*0.81;                         
    }
   Comment("delta= ",DoubleToStr(delta/Point,0)," pips");
   
   GetTLINE(name+"_level_50",time_100,level_50,time_0,level_50,color_l,1);
   GetTXT(name+"_level_50t",Time[0], level_50+atr,color_l, DoubleToStr(level_50,Digits)+" (50%)"+GetNameTF(TimeFrame)+pref+ExtDepth);       
   GetTLINE(name+"_level_618",time_100,level_618,time_0,level_618,color_l,1);
   GetTXT(name+"_level_618t",Time[0], level_618+atr,color_l, DoubleToStr(level_618,Digits)+" (61.8%)"+GetNameTF(TimeFrame)+pref+ExtDepth);          
   GetTLINE(name+"_level_382",time_100,level_382,time_0,level_382,color_l,1);
   GetTXT(name+"_level_382t",Time[0], level_382+atr,color_l, DoubleToStr(level_382,Digits)+" (38.2%)"+GetNameTF(TimeFrame)+pref+ExtDepth);   
   GetTLINE(name+"_level_236",time_100,level_236,time_0,level_236,color_l,1);
   GetTXT(name+"_level_236t",Time[0], level_236+atr,color_l, DoubleToStr(level_236,Digits)+" (23.6%)"+GetNameTF(TimeFrame)+pref+ExtDepth);   
   GetTLINE(name+"_level_146",time_100,level_146,time_0,level_146,color_l,1);
   GetTXT(name+"_level_146t",Time[0], level_146+atr,color_l, DoubleToStr(level_146,Digits)+" (14.6%)"+GetNameTF(TimeFrame)+pref+ExtDepth);                     
   GetTLINE(name+"_level_810",time_100,level_810,time_0,level_810,color_l,1);
   GetTXT(name+"_level_810t",Time[0], level_810+atr,color_l, DoubleToStr(level_810,Digits)+" (81%)"+GetNameTF(TimeFrame)+pref+ExtDepth);                     

//----
   return(0);
  }
//+------------------------------------------------------------------+
 double GetZZ(int bar)
  {
   double vzz = iCustom(Symbol(),TimeFrame,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,bar);
   return(vzz); 
  }
//----+
 void GetLVL(double&level_100,datetime&time_100,double&level_0,datetime&time_0)
  {
   double zig;int bar =0;
   double prc_1 = -1, prc_2 = -1;
   datetime time_1, time_2;
      
   while(prc_2 < 0)
   {
    zig = GetZZ(bar);
    if(zig>0 && prc_1<0){prc_1 = zig; time_1 = iTime(Symbol(),TimeFrame,bar);bar++;continue;}
    if(zig>0 && prc_1>0 && prc_2<0){prc_2 = zig; time_2 = iTime(Symbol(),TimeFrame,bar);}          
    bar++;
   }
   
   if(time_1>time_2)
    {
     level_100 = prc_2;
     time_100 = time_2;
     level_0 = prc_1;
     time_0 = time_1;
    }
   if(time_1<time_2)
    {
     level_100 = prc_1;
     time_100 = time_1;
     level_0 = prc_2;
     time_0 = time_2;
    }      
  }
//----+
//ôóíêöèÿ ñòðîèò òðåíäîâóþ ëèíèþ
 void GetTLINE(string name_label,datetime t1,double p1,datetime t2,double p2,color c = Red,int style = 0, int widh = 0, bool ray = true)
  {
   if (ObjectFind(name_label)!=-1) ObjectDelete(name_label);
   ObjectCreate(name_label,OBJ_TREND,0,t1,p1,t2,p2);
   ObjectSet(name_label,OBJPROP_COLOR,c);
   ObjectSet(name_label,OBJPROP_STYLE,style);   
   ObjectSet(name_label,OBJPROP_WIDTH,widh);
   ObjectSet(name_label,OBJPROP_RAY,ray);               
  }
//----+
string GetNameTF(int TimeFrame=0) {
  if (TimeFrame==0) TimeFrame=Period();
  switch (TimeFrame) {
    case PERIOD_M1:  return("M1");
    case PERIOD_M5:  return("M5");
    case PERIOD_M15: return("M15");
    case PERIOD_M30: return("M30");
    case PERIOD_H1:  return("H1");
    case PERIOD_H4:  return("H4");
    case PERIOD_D1:  return("Daily");
    case PERIOD_W1:  return("Weekly");
    case PERIOD_MN1: return("Monthly");
    default:         return("UnknownPeriod");
  }
}
//----+
 void GetDellName (string name_n = "ytg_")
  {
   string vName;
   for(int i=ObjectsTotal()-1; i>=0;i--)
    {
     vName = ObjectName(i);
     if (StringFind(vName,name_n) !=-1) ObjectDelete(vName);
    }  
  }
//ôóíêöèÿ ñòðîèò òåêñòîâóþ ìåòêó
 void GetTXT(string name_label,datetime t1, double p1,color c = Red, string txt = "zero",double angle = 0)
  {
   datetime dlt = DELTA_K * 60*Period();
   if (ObjectFind(name_label)!=-1) ObjectDelete(name_label);
   ObjectCreate(name_label,OBJ_TEXT,0,t1+dlt,p1,0,0);
   ObjectSet(name_label,OBJPROP_ANGLE,angle);   
   ObjectSetText(name_label, txt, 10, "Times New Roman", c);            
  }
 void Label(string name_label,          
            string text_label,          
            int corner = 2,        
            int x = 3,                  
            int y = 15,               
            int font_size = 10,       
            string font_name = "Arial",  
            color text_color = LimeGreen 
           )
  {
   if (ObjectFind(name_label)!=-1) ObjectDelete(name_label);
       ObjectCreate(name_label,OBJ_LABEL,0,0,0,0,0);         
       ObjectSet(name_label,OBJPROP_CORNER,corner);
       ObjectSet(name_label,OBJPROP_XDISTANCE,x);
       ObjectSet(name_label,OBJPROP_YDISTANCE,y);
       ObjectSetText(name_label,text_label,font_size,font_name,text_color);
  }
//----+
 void GetYTG()
  {
   static int count = 0;
   count++;if(count>2)count = 0;   
   color color_Y = Red;
   color color_T = Lime;   
   color color_G = Blue;
   if(count==1){color_Y = Crimson;color_T = LimeGreen;color_G = DodgerBlue;}
   if(count==2){color_Y = OrangeRed;color_T = ForestGreen;color_G = RoyalBlue;}
                     
   Label("ytg_Y","Y" ,3,40,20,25,"Arial Black",color_Y);
   Label("ytg_T","T" ,3,25,5,25,"Arial Black",color_T);   
   Label("ytg_G","G" ,3,13,32,25,"Arial Black",color_G);
    
  }
void GetAvtor()
 {
  static int tick = 0;
  tick++;if(tick>=42)tick=0;
 
  string char1[256]; int i;
  string f_n = "Arial";
  for (i = 0; i < 256; i++) char1[i] = CharToStr(i);   
  Label("label",char1[70],2,5,15,10,f_n,GetColor(41,tick));
  Label("label1",char1[97],2,12,15,10,f_n,GetColor(0,tick));
  Label("label2",char1[99],2,19,15,10,f_n,GetColor(1,tick));  
  Label("label3",char1[116],2,26,15,10,f_n,GetColor(2,tick));  
  Label("label4",char1[111],2,30,15,10,f_n,GetColor(3,tick));  
  Label("label5",char1[114],2,37,15,10,f_n,GetColor(4,tick));
  Label("label6",char1[121],2,42,15,10,f_n,GetColor(5,tick));  
  Label("label8",char1[111],2,53,15,10,f_n,GetColor(6,tick));    
  Label("label9",char1[102],2,60,15,10,f_n,GetColor(7,tick));    
  Label("label11",char1[116],2,70,15,10,f_n,GetColor(8,tick));
  Label("label12",char1[104],2,75,15,10,f_n,GetColor(9,tick));    
  Label("label13",char1[101],2,81,15,10,f_n,GetColor(10,tick));      
  Label("label15",char1[97],2,94,15,10,f_n,GetColor(11,tick));  
  Label("label16",char1[100],2,101,15,10,f_n,GetColor(12,tick));
  Label("label17",char1[118],2,108,15,10,f_n,GetColor(13,tick)); 
  Label("label18",char1[105],2,115,15,10,f_n,GetColor(14,tick));  
  Label("label19",char1[115],2,118,15,10,f_n,GetColor(15,tick));   
  Label("label20",char1[101],2,125,15,10,f_n,GetColor(16,tick));
  Label("label21",char1[114],2,133,15,10,f_n,GetColor(17,tick));
  Label("label22",char1[115],2,138,15,10,f_n,GetColor(18,tick));  
  Label("label23",char1[58],2,147,15,10,f_n,GetColor(19,tick));    
  Label("label24",char1[121],2,153,15,10,f_n,GetColor(20,tick));  
  Label("label25",char1[117],2,160,15,10,f_n,GetColor(21,tick));  
  Label("label26",char1[114],2,167,15,10,f_n,GetColor(22,tick));  
  Label("label28",char1[105],2,172,15,10,f_n,GetColor(23,tick));  
  Label("label29",char1[121],2,176,15,10,f_n,GetColor(24,tick));    
  Label("label311",char1[116],2,184,15,10,f_n,GetColor(25,tick));
  Label("label312",char1[111],2,188,15,10,f_n,GetColor(26,tick));    
  Label("label313",char1[107],2,195,15,10,f_n,GetColor(27,tick));      
  Label("label315",char1[109],2,203,15,10,f_n,GetColor(28,tick));  
  Label("label316",char1[97],2,214,15,10,f_n,GetColor(29,tick));
  Label("label317",char1[110],2,221,15,10,f_n,GetColor(30,tick)); 
  Label("label318",char1[64],2,230,15,10,f_n,GetColor(31,tick));    
  Label("label319",char1[103],2,244,15,10,f_n,GetColor(32,tick));
  Label("label3411",char1[109],2,251,15,10,f_n,GetColor(33,tick));
  Label("label3412",char1[97],2,261,15,10,f_n,GetColor(34,tick));      
  Label("label3413",char1[105],2,268,15,10,f_n,GetColor(35,tick));    
  Label("label3415",char1[108],2,271,15,10,f_n,GetColor(36,tick));  
  Label("label33",char1[46],2,274,15,10,f_n,GetColor(37,tick));
  Label("label34",char1[99],2,278,15,10,f_n,GetColor(38,tick)); 
  Label("label35",char1[111],2,286,15,10,f_n,GetColor(39,tick));  
  Label("label36",char1[109],2,294,15,10,f_n,GetColor(40,tick)); //42           
 }
 color GetColor(int n, int t)
  {
   color colir = LimeGreen;
   if(n==t || n+1==t || n+2==t)colir = Yellow;
   if(n+10==t || n+11==t || n+12==t)colir = Aqua;
   if(n+20==t || n+21==t || n+22==t)colir = Gold;      
   return(colir);
  } 

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---