Navigation:Home > Content >

Fractal-alert.mq4

Time: 2015-11-08 | Download file:Fractal-alert.mq4

//+------------------------------------------------------------------+
//|                                                      Fractal.mq4 |
//+------------------------------------------------------------------+
//|                                                    RFractals.mq4 |
//|                                                       Lizhniyk E |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
/*
  Modify Necron   
  www.fxgeneral.com
*/
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_width1 1
#property indicator_width2 1
#property indicator_color1 Lime
#property indicator_color2 Red
//---- input parameters
extern int    Size = 1; 
extern int    range_fractal=5;
extern double multiplier=1;
extern bool   show_level=true;
extern color  fr_up_color=Lime;
extern color  fr_dn_color=Red;
extern int    width=1;
extern int    style=0;
int    Bars_ATR=233;//период для ATR                                                          
int    Code_Arrow_UP=217;                                                                     
int    Code_Arrow_DN=218; 

//---- buffers
double Ext1[];
double Ext2[];
int center=0;
datetime temt=0;
extern bool Signal=true;
bool sell=true;
bool buy=true;
datetime tempT=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   if(range_fractal % 2 == 0) range_fractal++;
   if(range_fractal<3) range_fractal=3;
   center=range_fractal/2 + 1 ;
   //scenter=range_fractal/2;
   SetIndexStyle(0,DRAW_ARROW,EMPTY,Size);
   SetIndexArrow(0,Code_Arrow_UP);
   SetIndexBuffer(0,Ext1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,Size);
   SetIndexArrow(1,Code_Arrow_DN);
   SetIndexBuffer(1,Ext2);
   SetIndexEmptyValue(1,0.0);
   SetIndexLabel(0,"Fractal Up");
   SetIndexLabel(1,"Fractal Down");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
      ObjectDelete("fr_up");
      ObjectDelete("fr_dn");


//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
double cur=0;
double range;
bool found=false;
int start()
  {
   int    counted_bars=IndicatorCounted();
   range=iATR(NULL,0,Bars_ATR,0);
//----
   for(int i=Bars-counted_bars;i>=0;i--)
    {
    //*************fractal_up**************
    found=false;
    cur=High[i+center];
    if(cur>=High[i+1] && cur>=High[i+range_fractal]) found=true;
    else found=false; 
    if(found) 
     {
     for(int j=1;jHigh[i+center-j] && cur>=High[i+center+j]) found=true;
       else {found=false; break;}
       }  
      } 
    if(found) 
    {
      Ext1[i+center]=cur+range*multiplier/10; Ext1[i+center+1]=0;
      if(show_level)
       {
        ObjectCreate("fr_up",OBJ_TREND,0,0,0,0,0); 
        ObjectSet("fr_up",OBJPROP_TIME1,iTime(Symbol(),Period(),i+center));
		  ObjectSet("fr_up",OBJPROP_TIME2,iTime(Symbol(),Period(),0));
 		  ObjectSet("fr_up",OBJPROP_PRICE1,cur);
 		  ObjectSet("fr_up",OBJPROP_PRICE2,cur);
  		  ObjectSet("fr_up",OBJPROP_RAY,false);
  		  ObjectSet("fr_up",OBJPROP_WIDTH,width); 
		  ObjectSet("fr_up",OBJPROP_COLOR,fr_up_color); 
 		  ObjectSet("fr_up",OBJPROP_STYLE,style); 

       }
    }
    
    //*************fractal down************* 
    found=false;
    cur=Low[i+center]; 
    if(cur<=Low[i+1] && cur<=Low[i+range_fractal]) found=true;
    else found=false; 
    if(found) 
     {
     for(int k=1;kObjectGet("fr_dn",OBJPROP_PRICE1))
               {
                  sell=true;
               }
       }
    if(ObjectFind("fr_up")!=-1) 
       {
          if(Signal==true&&Bid>ObjectGet("fr_up",OBJPROP_PRICE1)&&buy==true)
            {
               Alert("Пробой верхнего фрактала");
               buy=false;
               tempT=Time[0];
            }
            if(tempT!=Time[0]&&Open[0]        

Recommend