trading - How to solve Fractals over N-bars period in MQL4, similar to IQOptions Fractals indicator? -


i learning mql4 myself. registered iqoptions binary options trading.

i planning write indicators myself trading system. fractals lot, not mql4-supported fractal logic, keen on iqoptions specific one.

in mql4, find fractal use ifractal() doesn't take parameters other offset.

i convinced myself finds fractal on 3 bars. doing lot of homework, have realized iqoptions indicator doing more fractal. please find attached screenshot.

i wrote many programs added recent 1 below. need figure out has been there. image attached iqoption screenshot, fractals on 20 bar period.

enter image description here

//+------------------------------------------------------------------+ //|                                                        bulls.mq4 | //|                   copyright 2005-2014, metaquotes software corp. | //|                                              http://www.mql4.com | //+------------------------------------------------------------------+ #property copyright   "2005-2014, metaquotes software corp." #property link        "http://www.mql4.com" #property description "fractals tanya" #property strict  //--- indicator settings #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 red #property indicator_color2 green #property indicator_width1 1 #property indicator_width2 1 #property indicator_style1 style_solid #property indicator_style2 style_solid //--- input parameter input int b_f=20; //extern int allb=240;   //--- buffers double extfractalsupbuffer[]; double extfractalsdownbuffer[];  //+------------------------------------------------------------------+ //| custom indicator initialization function                         | //+------------------------------------------------------------------+ void oninit(void)   {  //--- 1 additional buffer used counting.    indicatorbuffers(2);    indicatordigits(digits); //--- indicator line    setindexbuffer( 0, extfractalsupbuffer );    setindexstyle( 0, draw_arrow );    setindexarrow( 0, 234 );     setindexlabel( 0, null );    setindexemptyvalue( 0, 0.0 );     setindexbuffer( 1, extfractalsdownbuffer );    setindexstyle( 1, draw_arrow );    setindexarrow( 1, 233 );     setindexlabel( 1, null );    setindexemptyvalue( 1, 0.0 );     setindexdrawbegin(0,b_f);    setindexdrawbegin(1,b_f);     indicatorshortname( "fractalstanya" );    indicatordigits( digits );   } //+------------------------------------------------------------------+ //| bulls power                                                      | //+------------------------------------------------------------------+ int oncalculate(const int rates_total,                 const int prev_calculated,                 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[])   {    int limit=rates_total-prev_calculated; //---    if(rates_total<=b_f || b_f<=0)       return(0); //---    if(prev_calculated>0)       limit++;    int i=0,j=0,k=0;    double upfratal=0.0;    double downfratal=0.0;    int x=0; int y=0;     for(int t=0; t<limit+b_f; t++)      {      double uptempfractal=ifractals(null,period(),mode_upper,t);      double downtempfractal=ifractals(null,period(),mode_lower,t);      if(uptempfractal!=0&&uptempfractal>upfratal)      {       upfratal=uptempfractal;       j=t;      }      if(downtempfractal!=0.0&&downfratal==0.0)      {          downfratal=downtempfractal;      }      if(downtempfractal!=0.0&&downtempfractal<=downfratal)      {          downfratal=downtempfractal;          k=t;      }          i++;          if(i==b_f)          {         if(upfratal!=0.0)             {             if(x==0||(j-x)>=b_f)             {               x=j;               extfractalsupbuffer[j]=upfratal;             }             }             if(downfratal!=0.0)             {             if(y==0||(k-y)>=b_f)             {                y=k;                extfractalsdownbuffer[k]=downfratal;             }              }             i=0;             upfratal=0.0;             downfratal=0.0;          }      }       /*for(int t=0; t<limit; t++)      {       double upfratal=ifractals(null,period(),mode_upper,t);       double downfratal=ifractals(null,period(),mode_lower,t);       if(upfratal!=0.0)extfractalsupbuffer[t]=upfratal;       else if(downfratal!=0.0)extfractalsdownbuffer[t]=downfratal;      }*/    return(rates_total);   } 

i assume want achieve find fractals in last x bars. had same issue , in case wanted find recent fractals, both , down, function created. used calculate trailing stop. changing function can find highest , lowest fractals.

i hope helps

// --------------------------------------------------------------------- bool   fractalsup        = false; bool   fractalsdown      = false; double fractalsupprice   = 0; double fractalsdownprice = 0;  // -----------------------------------------------number of bars scan int    fractalslimit     = 15;  void findfractals(){ // ------------------------------------------(re)-initialization of variables    fractalsup        = false;    fractalsdown      = false;    fractalsupprice   = 0;    fractalsdownprice = 0; /* --------------------------------------a for(){...} loop scan                                                       last fractalslimit                                                       candles, starting                                                       oldest , finishing                                                       recent 1 */    ( int = fractalslimit; >= 0; i-- ){       // ----------------------------------------------------------------------------          double fu = ifractals( null, 0, mode_upper, );          double fl = ifractals( null, 0, mode_lower, );                                              /* if there posack of fractal on candle                                                    value greater 0                                                    , equal highest or lowest price */       // ---------------------------------------------------------------------------          if (  fu >  0 ){                    // if there upper fractal                fractalsupprice   = fu;       //    store value ,                fractalsup        = true;     //    set true fractalsup variable                fractalsdown      = false;    //    set false on posack_up          }       // ----------------------------------------------------------------------------          if (  fl >  0 ){                    // if there lower fractal                fractalsdownprice = fl;       //    store value ,                fractalsup        = false;    //    set false on posack_lo                fractalsdown      = true;     //    set true fractalsdown variable          }       // ----------------------------------------------------------------------------          if (  fu >  0                       // if candle has both upper             && fl >  0                       //    , lower fractal                ){                fractalsupprice   = fu;       //    values stored                 fractalsdownprice = fl;                fractalsup        = false;    //    not, on nack,                fractalsdown      = false;    //    consider last fractal          }    } } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -