Fractals Support and Resistance Expert Advisor

 

hello everyone,

I face another problem with Fractals, I want to draw support and resistance lines on fractals lower and upper levels, however.. it draws only when candle opens up.. and then price changes. Any chance to figure out how to draw on high and low prices of a fractal candle?

Thanks


#property copyright ""
#property link      ""


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+

int getTime(int period){

   int calc = 3600;           
    
   if(period==1)          { calc = 60;}
   else if(period==5)     { calc = 300;}
   else if(period==15)    { calc = 900;}
   else if(period==30)    { calc = 1800;}
   else if(period==60)    { calc = 3600;}
   else if(period==240)   { calc = 14400;}
   else if(period==1440)  { calc = 86400;}
   else if(period==10080) { calc = 604800;}
   else if(period==43200) { calc = 604800*4;}
   
   return(calc);
}

int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

int ticket, result, calc, i;

int upper_count = 0;
int lower_count = 0;

double upper_array[100000];
double lower_array[100000];

bool forceclose = false, lockresistance = false, locksupport = false;

datetime totime, fromtime, totimebig, fromtimebig;

int start()
  {
//----

   if(iFractals(NULL, 0, MODE_UPPER, 2)!=0.0){
      
      upper_array[upper_count] = iFractals(NULL, 0, MODE_UPPER, 2);
      //Print(" upper_array[upper_count] -> " + upper_array[upper_count] +  " -> " +iFractals(NULL, 0, MODE_UPPER, 2));
      upper_count++;
   }
   
   if(iFractals(NULL, 0, MODE_LOWER, 2)!=0.0){
   
      lower_array[lower_count] = iFractals(NULL, 0, MODE_LOWER, 2);
      //Print(" lower_array[lower_count] -> " + lower_array[lower_count] +  " -> " +iFractals(NULL, 0, MODE_LOWER, 2));
      lower_count++;
   }
   
   if(iLow(Symbol(),Period(),0)<lower_array[lower_count-1] && locksupport == false){

      calc = getTime(Period());
      fromtime=iTime(Symbol(),Period(),0)-2*calc;
      totime=iTime(Symbol(),Period(),0)+2*calc;   
      
      
      ObjectCreate("support_line"+i,OBJ_TREND,0,totime,iLow(Symbol(),Period(),0),fromtime,iLow(Symbol(),Period(),0));
      ObjectSet("support_line"+i,OBJPROP_COLOR,Green);
      ObjectSet("support_line"+i,OBJPROP_WIDTH,2);
      ObjectSet("support_line"+i,OBJPROP_RAY,false);
      i++;
      locksupport    = true;
      lockresistance = false;
   }
   
   Print(iHigh(Symbol(),Period(),0) + " " +upper_array[upper_count-1]);
   if(iHigh(Symbol(),Period(),0)>upper_array[upper_count-1] && lockresistance == false){
   
      calc = getTime(Period());
      fromtime=iTime(Symbol(),Period(),0)-2*calc;
      totime=iTime(Symbol(),Period(),0)+2*calc;   
      
      
      ObjectCreate("resistance_line"+i,OBJ_TREND,0,totime,iHigh(Symbol(),Period(),0),fromtime,iHigh(Symbol(),Period(),0));
      ObjectSet("resistance_line"+i,OBJPROP_COLOR,Red);
      ObjectSet("resistance_line"+i,OBJPROP_WIDTH,2);
      ObjectSet("resistance_line"+i,OBJPROP_RAY,false);
      i++;      
      lockresistance = true;
      locksupport    = false;
   }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

Hello,

I would like at least to know whether this is possible to do in Meta Trader?

 
cedas:

Hello,

I would like at least to know whether this is possible to do in Meta Trader?

Yes it most certainly is possible.

Why don't you use one of the many Fractals indicators ?

 
RaptorUK:

Yes it most certainly is possible.

Why don't you use one of the many Fractals indicators ?

Hello RaptroUK,

Which one indicators you think it is better to use for Fractals ?

thanks

 
cedas:

Hello RaptroUK,

Which one indicators you think it is better to use for Fractals ?

thanks

Sorry, can't recommend any as I don't use them.

https://www.mql4.com/search#!keyword=fractal&module=mql4_module_codebase

 
cedas:

Hello RaptroUK,

Which one indicators you think it is better to use for Fractals ?

thanks


https://www.mql5.com/en/code/7118 is one of them

Reason: