I have problem with iFractal

 

Dear Experts

I'm new in programing and i need the maximum Upper Williams Fractals between 6 last Upper Fractals @ daily timeframe. So i tried to code these lines below:

double Fractals_Daily_UPPER_LINE[]  ;
double Fractals_Daily_LOWER_LINE[]  ;
   ArraySetAsSeries(Fractals_Daily_UPPER_LINE,true)   ;
   ArraySetAsSeries(Fractals_Daily_LOWER_LINE,true)   ;
   int Fractals_Daily_handle = iFractals(_Symbol,PERIOD_D1) ;
   CopyBuffer(Fractals_Daily_handle,0,1,6,Fractals_Daily_UPPER_LINE) ;
   CopyBuffer(Fractals_Daily_handle,1,1,6,Fractals_Daily_LOWER_LINE) ;
   
   int Maximum_Upper_Daily_fractal_Index = ArrayMaximum(Fractals_Daily_UPPER_LINE,0)   ;
   double Maximum_Upper_Daily_fractal       = NormalizeDouble( Fractals_Daily_UPPER_LINE[Maximum_Upper_Daily_fractal_Index] ,2 )   ;

   int Minimum_Upper_Daily_fractal_Index = ArrayMinimum(Fractals_Daily_UPPER_LINE,0)   ; 
   double Minimum_Upper_Daily_fractal       = NormalizeDouble( Fractals_Daily_LOWER_LINE[Minimum_Upper_Daily_fractal_Index] ,2 )   ;

But results is not correct. It seems that the arrays is not properly filled by the upper and lower fractals.

Can you please help me to find my mistake ?

Thanks

Fractals - Bill Williams' Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
All markets are characterized by the fact that on the most part the prices do not change too much, and only short periods of time (15–30 percent)...
 
Mehdi Vafakhah: But results is not correct. It seems that the arrays is not properly filled by the upper and lower fractals.

Can you please help me to find my mistake ?

Where there is no fractal, you will read zero or EMPTY_VALUE (MT5 vs MT4). You are only reading the last six bars, not the last six fractals.

Either write a function that results in an array of the last six fractals and then use ArrayMaximum. Or just read the last six:

Not tested, not compiled, just typed.
   double Maximum_Upper_Daily_fractal = DBL_MIN;    int upCnt=0;
   for(int iBar=2; upCnt != 6; ++i){
       double A[]; CopyBuffer(Fractals_Daily_handle,0,iBar,1,A) ;
       if(A[0] != 0 && A[0] != EMPTY_VALUE){
           Maximum_Upper_Daily_fractal = MathMax(Maximum_Upper_Daily_fractal, A[0]);
          ++upCnt;
      }
  }
Not tested, not compiled, just typed.
 
William Roeder #:

Where there is no fractal, you will read zero or EMPTY_VALUE (MT5 vs MT4). You are only reading the last six bars, not the last six fractals.

Either write a function that results in an array of the last six fractals and then use ArrayMaximum. Or just read the last six:

Not tested, not compiled, just typed. Not tested, not compiled, just typed.

Dear  William Roeder

Thank you for your guidance.

Thanks to your help I realized the general problem of my codes Now.

After entering your suggested code section, The array appears to be properly filled by the fractals and it's so good


But there is still a problem as below:

1-)    2023.03.27 22:40:15.629 debug version of '001.ex5', please recompile it.

2-)    And after compiling the tester does not work!

3-)   By removing the new codes everything works correctly as before!


Seems i have a new challenge Now.

William Roeder
William Roeder
  • www.mql5.com
Trader's profile
 
Mehdi Vafakhah #:

Dear  William Roeder

Thank you for your guidance.

Thanks to your help I realized the general problem of my codes Now.

After entering your suggested code section, The array appears to be properly filled by the fractals and it's so good


But there is still a problem as below:

1-)    2023.03.27 22:40:15.629 debug version of '001.ex5', please recompile it.

2-)    And after compiling the tester does not work!

3-)   By removing the new codes everything works correctly as before!


Seems i have a new challenge Now.

Fixed array creation problem for fractals. I used the time function for this. The results are given below:

//variables:
 datetime Daily_candles_time[6]       ;  
 datetime Daily_Fractals_Date[6]      ;
 double Daily_Upper_Fractal[6]        ;
 double Fractal_Daily_HighPrices[6]   ; 
 int fractals_Daily_Array_FillingNo   ;
 double Maximum_Daily_Fractals        ;

void Fractals_daily()
{
  ArraySetAsSeries(Daily_candles_time,true)           ;
  CopyTime(_Symbol,PERIOD_D1,1,6,Daily_candles_time)  ;
   
   
   ArraySetAsSeries(Fractal_Daily_HighPrices,true)          ;
   CopyHigh(_Symbol,PERIOD_D1,1,6,Fractal_Daily_HighPrices) ;
    
  

   

    
    if(Fractal_Daily_HighPrices[3]>Fractal_Daily_HighPrices[1] && Fractal_Daily_HighPrices[3]>Fractal_Daily_HighPrices[2] &&
       Fractal_Daily_HighPrices[3]>Fractal_Daily_HighPrices[4] && Fractal_Daily_HighPrices[3]>Fractal_Daily_HighPrices[5] 
       )
       {
        
        if(fractals_Daily_Array_FillingNo== 0 && Daily_candles_time[3] != Daily_Fractals_Date[5])
          {
           Daily_Upper_Fractal[0] = Fractal_Daily_HighPrices[3]   ;
           fractals_Daily_Array_FillingNo=1                       ;
           Daily_Fractals_Date[0] = Daily_candles_time[3]         ;
          }
           else if(fractals_Daily_Array_FillingNo== 1 && Daily_candles_time[3] != Daily_Fractals_Date[0]  )
                  {
                   Daily_Upper_Fractal[1] = Fractal_Daily_HighPrices[3] ;
                   fractals_Daily_Array_FillingNo=2                     ;
                   Daily_Fractals_Date[1] = Daily_candles_time[3]       ;
                                     
                  }
           else if(fractals_Daily_Array_FillingNo== 2 && Daily_candles_time[3] != Daily_Fractals_Date[1] )
                  {
                   Daily_Upper_Fractal[2] = Fractal_Daily_HighPrices[3] ;
                   fractals_Daily_Array_FillingNo=3                     ;
                    Daily_Fractals_Date[2] = Daily_candles_time[3]      ;                 
                  }
           else if(fractals_Daily_Array_FillingNo== 3 && Daily_candles_time[3] != Daily_Fractals_Date[2]  )
                  {
                   Daily_Upper_Fractal[3] = Fractal_Daily_HighPrices[3] ;
                   fractals_Daily_Array_FillingNo=4                     ;
                    Daily_Fractals_Date[3] = Daily_candles_time[3]      ;                
                  }                  
           else if(fractals_Daily_Array_FillingNo== 4 && Daily_candles_time[3] != Daily_Fractals_Date[3])
                  {
                   Daily_Upper_Fractal[4] = Fractal_Daily_HighPrices[3] ;
                   fractals_Daily_Array_FillingNo=5                     ;
                    Daily_Fractals_Date[4] = Daily_candles_time[3]      ;               
                  }
           else if(fractals_Daily_Array_FillingNo== 5 && Daily_candles_time[3] != Daily_Fractals_Date[4] )
                  {
                   Daily_Upper_Fractal[5] = Fractal_Daily_HighPrices[3] ;
                    Daily_Fractals_Date[5] = Daily_candles_time[3]      ;
                    fractals_Daily_Array_FillingNo=0                    ;                  
                  }
                  else Print("some thing is wrong in Fractals") ;
  
   int Maximum_Daily_Fractals_index = ArrayMaximum(Daily_Upper_Fractal,0,WHOLE_ARRAY)     ;
   Maximum_Daily_Fractals    = Daily_Upper_Fractal[Maximum_Daily_Fractals_index]          ;
  
                  
                             
        }     
           

  Comment( Daily_candles_time[0], "\n" ,
           Daily_candles_time[1], "\n" ,
           Daily_candles_time[2], "\n" ,
           Daily_candles_time[3], "\n" ,
           Daily_candles_time[4], "\n" ,
           Daily_candles_time[5], "\n" ,
           "fractals as below"," ", "\n" ,
           Daily_Upper_Fractal[0], "\n" ,
           Daily_Upper_Fractal[1], "\n" ,
           Daily_Upper_Fractal[2], "\n" ,
           Daily_Upper_Fractal[3], "\n" ,
           Daily_Upper_Fractal[4], "\n" ,
           Daily_Upper_Fractal[5], "\n" ,
           "MAX Fractals Is:"," ", Maximum_Daily_Fractals  
          );


}

Tested and compiled. Thank you Dear William Roeder .

Dear experts newbies never could solve their Problems without you help.

Reason: