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:
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.
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:
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.

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: Tested and compiled. Thank you Dear William Roeder . //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
);
}

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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:
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