How to spot fractures in Line charts

 

I wrote this code to spot fractures but the thing is that the threshold for each chart and time frame is different.

And with a fixed low threshold you may miss some fractures and with a high threshold you may get non fractures in the line chart

Isn't there any better solution for this?

here is sample code that puts an arrow on top of each candle where there is a fracture

for(int i = 0; i < 1000; i++){
      double dif = MathAbs(iClose(Symbol(),PERIOD_CURRENT,i)-iClose(Symbol(),PERIOD_CURRENT,i+1));
      if(dif <= 0.00100){
         ObjectCreate(ChartID(),"BreakShow "+IntegerToString(i),OBJ_ARROW_CHECK,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i));
      }
}


I'll attach a photo to show what I mean by fracture

The pink arrow showing a fracture missed by my code

Files:
Untitled.png  2 kb
 
Anyone??
 
Nima J # :
Anyone??

Are you writing an indicator or an Expert Advisor? Do you write in MQL5 or in the language for the old terminal?

 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   /*double ATR[],threshold=0;
   if(CopyBuffer(iATR(_Symbol,_Period,1000),0,0,1,ATR)>0)
      threshold=ATR[0]/10;*/
   
   double highest=iHigh(_Symbol,_Period,iHighest(_Symbol,_Period,MODE_HIGH,1000,0));
   double lowest=iLow(_Symbol,_Period,iLowest(_Symbol,_Period,MODE_LOW,1000,0));
   double percent=0.005,threshold=(highest-lowest)*percent;
   
   for(int i = 0; i < 1000; i++){
      double dif = MathAbs(iClose(Symbol(),PERIOD_CURRENT,i)-iClose(Symbol(),PERIOD_CURRENT,i+1));
      if(dif <= threshold){
         ObjectCreate(ChartID(),"BreakShow "+IntegerToString(i),OBJ_ARROW_CHECK,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i));
      }
    }
   
   while(!_StopFlag) {}
   ObjectsDeleteAll(ChartID(),0,OBJ_ARROW_CHECK);
  }
//+------------------------------------------------------------------+

Or Average True Range.

 
Vladimir Karputov #:

Are you writing an indicator or an Expert Advisor? Do you write in MQL5 or in the language for the old terminal?

I'm writing an Expert in MQL4. but if you have any suggestion in MQL5 It would be great too

 
Ernst Van Der Merwe #:

Or Average True Range.

Thanks a lot, this is actually a good idea