Fractals are used to identify market structure — a moment t where:
Down fractal:
Low(t) <= Lowest(t-a, t+b)
for the minimum in domain [t-a, t+b]
Up fractal:
High(t) >= Highest(t-a, t+b)
for the maximum in domain [t-a, t+b]
Example:
If lookback = 20 and a = b = 3
Assume that at time t = i = 10 (bar index, where 0 is current, 1 is previous, n is nth bar, etc.):
Lowest(10-3, 10+3) → Lowest(7 to 13) = Low(10)
Then t = 10 is a down fractal.
Reference:
Here is the code of the existing indicator (X-bars Fractals from Serhii Ivanenko) that would be great to convert for ProRealTime users:
https://www.mql5.com/en/code/1381
Thank you !
JSParticipant
Senior
Hi,
Try this one…
Once NLB=5 //Number Left Bars
Once NRB=5 //Numer Right Bars
TB=NLB+NRB //TotalBars
fp=NRB+1 //fp=fractal point
If High[fp]=Highest[TB+1](High) then
DrawArrowUp(BarIndex-fp,High[fp]) Coloured("Blue")
EndIf
If Low[fp]=Lowest[TB+1](Low) then
DrawArrowDown(BarIndex-fp,Low[fp]) Coloured("Green")
endIf
Return
Thanks but it does not work…
JSParticipant
Senior
Have you tried it, because it works fine for me…
What doesn’t work…?
When I tried it yesterday during regular trading hours, it didn’t work. Now that I’ve tried it when the market is closed, it mostly works. This happens sometimes to me with other indicators as well. I wonder why…
But there are many false positives. Take a look at the screenshots here where NLB and NRB = 2; there are many examples of the displayed fractal not being the local min or max of the candle range (t-2, t+2, so in total 5 candles). Do you know why this happens?
JSParticipant
Senior
Hi,
Try this one… (small addition error)
Once NLB=2 //Number Left Bars
Once NRB=2 //Numer Right Bars
TB=NLB+NRB //TotalBars
fp=NRB //fp=fractal point
If High[fp]=Highest[TB+1](High) then
DrawArrowUp(BarIndex-fp,High[fp]) Coloured("Blue")
EndIf
If Low[fp]=Lowest[TB+1](Low) then
DrawArrowDown(BarIndex-fp,Low[fp]) Coloured("Green")
endIf
Return