Market Sports – Rewriting the Basics

As step one in minimizing the differences between the individual brokers, we need to start handling the information more loosely.

The following image shows 2 different broker’s bid charts. These are 4H candles for crying out loud!

Apparently one broker can print a positive doji with long wicks while the other one decides to go with a full bodied down candle for the same 4-hour slice. In this archaic mess the only handle seems to be the distance traveled under a similar length of time, but not necessarily starting or ending on the same candle.

To minimize the effects of this sloppiness, step one is to start allowing for more candles to be called Fractals. We would bring down the 2 left neighbors requirement to 1, and invent the Modified Fractals.

//+------------------------------------------------------------------+
//|                                            Modified Fractals.mq4 |
//|           Original:  Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2018, Edit by Macdulio"
#property link      "https://forexfore.blog/"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Orange
//---- input parameters

//---- buffers
double ExtUpFractalsBuffer[];
double ExtDownFractalsBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping  
    SetIndexBuffer(0,ExtUpFractalsBuffer);
    SetIndexBuffer(1,ExtDownFractalsBuffer);  
//---- drawing settings
    SetIndexStyle(0,DRAW_ARROW,EMPTY,17);
    SetIndexArrow(0,119);
    SetIndexStyle(1,DRAW_ARROW,EMPTY,17);
    SetIndexArrow(1,119);
//----
    SetIndexEmptyValue(0,0.0);
    SetIndexEmptyValue(1,0.0);
//---- name for DataWindow
    SetIndexLabel(0,"Fractal Up");
    SetIndexLabel(1,"Fractal Down");
//---- initialization done  
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i,nCountedBars;
   bool   bFound;
   double dCurrent;
   nCountedBars=IndicatorCounted();
//---- last counted bar will be recounted    
   if(nCountedBars<=2)
      i=Bars-nCountedBars-3;
   if(nCountedBars>2)
     {
      nCountedBars--;
      i=Bars-nCountedBars-1;
     }
//----Up and Down Fractals
   while(i>=2)
     {
      //----Fractals up
      bFound=false;
      dCurrent=High[i];
      if(dCurrent>High[i+1]  && dCurrent>High[i-1] && dCurrent>High[i-2])
       //&& dCurrent>High[i+2]
        {
         bFound=true;
         ExtUpFractalsBuffer[i]=dCurrent;
        }
      //----6 bars Fractal
      if(!bFound && (Bars-i-1)>=3)
        {
         if(dCurrent==High[i+1] && dCurrent>High[i+2]  
         //&& dCurrent>High[i+3]
            && dCurrent>High[i-1] && dCurrent>High[i-2])
           {
            bFound=true;
            ExtUpFractalsBuffer[i]=dCurrent;
           }
        }        
      //----7 bars Fractal
      if(!bFound && (Bars-i-1)>=4)
        {  
         if(dCurrent>=High[i+1]  && dCurrent>High[i+3] && dCurrent>High[i+4] &&  dCurrent==High[i+2]
            && dCurrent>High[i-1] && dCurrent>High[i-2])
           {
            bFound=true;
            ExtUpFractalsBuffer[i]=dCurrent;
           }
        }  
      //----8 bars Fractal                          
      if(!bFound && (Bars-i-1)>=5)
        {  
         if(dCurrent>=High[i+1] && dCurrent==High[i+2] && dCurrent==High[i+3] && dCurrent>High[i+4]  &&
         
        //&& dCurrent>High[i+5]
            dCurrent>High[i-1] && dCurrent>High[i-2])
           {
            bFound=true;
            ExtUpFractalsBuffer[i]=dCurrent;
           }
        }
      //----9 bars Fractal                                        
      if(!bFound && (Bars-i-1)>=6)
        {  
         if(dCurrent>=High[i+1] && dCurrent==High[i+2] && dCurrent>=High[i+3] && dCurrent==High[i+4] && dCurrent>High[i+5]  && dCurrent>High[i-1] && dCurrent>High[i-2])
           //&&             dCurrent>High[i+6]
           {
            bFound=true;
            ExtUpFractalsBuffer[i]=dCurrent;
           }
        }                                    
      //----Fractals down
      bFound=false;
      dCurrent=Low[i];
      if(dCurrent<Low[i+1]  && dCurrent<Low[i-1] && dCurrent<Low[i-2])
        //&& dCurrent<Low[i+2]
        {
         bFound=true;
         ExtDownFractalsBuffer[i]=dCurrent;
        }
      //----6 bars Fractal
      if(!bFound && (Bars-i-1)>=3)
        {
         if(dCurrent==Low[i+1] && dCurrent<Low[i+2]  &&
            dCurrent<Low[i-1] && dCurrent<Low[i-2])
           //&& dCurrent<Low[i+3]
           {
            bFound=true;
            ExtDownFractalsBuffer[i]=dCurrent;
           }                      
        }        
      //----7 bars Fractal
      if(!bFound && (Bars-i-1)>=4)
        {  
         if(dCurrent<=Low[i+1] && dCurrent==Low[i+2] && dCurrent<Low[i+3]  &&
            dCurrent<Low[i-1] && dCurrent<Low[i-2])
          //&& dCurrent<Low[i+4]  
           {
            bFound=true;
            ExtDownFractalsBuffer[i]=dCurrent;
           }                      
        }  
      //----8 bars Fractal                          
      if(!bFound && (Bars-i-1)>=5)
        {  
         if(dCurrent<=Low[i+1] && dCurrent==Low[i+2] && dCurrent==Low[i+3] && dCurrent<Low[i+4]  &&
            dCurrent<Low[i-1] && dCurrent<Low[i-2])
           //&& dCurrent<Low[i+5] 
           {
            bFound=true;
            ExtDownFractalsBuffer[i]=dCurrent;
           }                      
        }
      //----9 bars Fractal                                        
      if(!bFound && (Bars-i-1)>=6)
        {  
         if(dCurrent<=Low[i+1] && dCurrent==Low[i+2] && dCurrent<=Low[i+3] && dCurrent==Low[i+4] && dCurrent<Low[i+5]  && dCurrent<Low[i-1] && dCurrent<Low[i-2])
           //&&             dCurrent<Low[i+6]
           {
            bFound=true;
            ExtDownFractalsBuffer[i]=dCurrent;
           }                      
        }                                    
      i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

The following image shows the original Fractals in purple and pink, and the ones that were not called fractals before are in blue and orange.

The second change would be to extend the search for the now Modified Fractals to the previous sample as well, when trying to find the “Synchronized, Modified Fractals”.

if(stoch[i+1]<23 && RSI2[i+1]<16  && RSI2[i+3]>5 && !(stoch[i]<5 && RSI2[i]<5)&& 
(ExtDownFractalsBuffer[i+1]!=EMPTY_VALUE  || ExtDownFractalsBuffer[i+2]!=EMPTY_VALUE)
//iFractals(Symbol(),0,MODE_LOWER,i+1)
)
    sdn[i+1]=iLow(symbol,30,i+1); 
if(stoch[i+1]<23 && RSI2[i+1]<16  && !(stoch[i]<5 && RSI2[i]<5)&& 
(ExtDownFractalsBuffer[i+1]!=EMPTY_VALUE  || ExtDownFractalsBuffer[i+2]!=EMPTY_VALUE)
//iFractals(Symbol(),0,MODE_LOWER,i+1)
)
    sdn[i+1]=iLow(symbol,30,i+1); 
if(stoch[i+1]<44 && stoch[i+1]>5 && RSI2[i+1]>5 && !(stoch[i]>15 && RSI2[i]>15) && 
(ExtDownFractalsBuffer[i+1]!=EMPTY_VALUE  || ExtDownFractalsBuffer[i+2]!=EMPTY_VALUE)
//iFractals(Symbol(),0,MODE_LOWER,i+1)
)        
   sdn[i+1]=iLow(symbol,30,i+1);
if(stoch[i+1]<5 && RSI2[i+1]<5 && !(stoch[i]>15 && RSI2[i]>15) && 
(ExtDownFractalsBuffer[i+1]!=EMPTY_VALUE  || ExtDownFractalsBuffer[i+2]!=EMPTY_VALUE)
//iFractals(Symbol(),0,MODE_LOWER,i+1)
)        
    sdn[i+1]=iLow(symbol,30,i+1);

if( ((stoch[i+1]>64 && stoch[i]<85 && RSI2[i+2]>85  ) ||  (stoch[i+1]>72 && stoch[i+1]<75 )  ||  (stoch[i]>44 && stoch[i+1]<35 && stoch[i-1]<44  && RSI2[i+1]>85 )) && RSI2[i+1]>70 && !(stoch[i-1]>95 && RSI2[i-1]>95) && 
(ExtUpFractalsBuffer[i+1]!=EMPTY_VALUE || ExtUpFractalsBuffer[i+2]!=EMPTY_VALUE)
//(  iFractals(Symbol(),0,MODE_UPPER,i+1)  )  
&& !sup[i+2]   )        
    sup[i+1]=iHigh(symbol,30,i+1);
if(stoch[i+1]>64 && stoch[i+2]<64 && RSI2[i+1]>85 && !(stoch[i]>70 && RSI2[i]>95) && 
(ExtUpFractalsBuffer[i+2]!=EMPTY_VALUE || ExtUpFractalsBuffer[i+2]!=EMPTY_VALUE)
//( iFractals(Symbol(),0,MODE_UPPER,i+2) )  
&& !sup[i+2] )        
    sup[i+1]=iHigh(symbol,30,i+1);
if(stoch[i+1]>85 && RSI2[i+1]>85 && !(stoch[i]>85 && RSI2[i]>95) &&  
(ExtUpFractalsBuffer[i+1]!=EMPTY_VALUE || ExtUpFractalsBuffer[i+2]!=EMPTY_VALUE)

Although there are plenty of differences still, I would call this an improvement.