This ProBuilder script is designed to detect and visualize changes in market trends using fractals. It identifies higher highs and lower lows, marking the beginning of new trends with arrows and segments on a trading chart.
defparam calculateonlastbars=10000
cp = 3
once lastpoint = 0
if high[cp] >= highest[2*cp+1](high) then
PEAK = 1
else
PEAK = 0
endif
if low[cp] <= lowest[2*cp+1](low) then
TROUGH = -1
else
TROUGH = 0
endif
if PEAK = 1 then
TOPy = high[cp]
TOPx = barindex[cp]
endif
if TROUGH = -1 then
BOTy = low[cp]
BOTx = barindex[cp]
endif
if PEAK>0 and (lastpoint=-1 or lastpoint=0) then
DRAWSEGMENT(lastX,lastY,TOPx,TOPy)
COLOURED(200,0,0,255)
DRAWTEXT("■",TOPx,TOPy,Dialog,Bold,20)
coloured(200,0,0,255)
lastpoint = 1
lastX = TOPx
lastY = TOPy
endif
if TROUGH<0 and (lastpoint=1 or lastpoint=0) then
DRAWSEGMENT(lastX,lastY,BOTx,BOTy)
COLOURED(0,200,0,255)
DRAWTEXT("■",BOTx,BOTy,Dialog,Bold,20)
coloured(0,200,0,255)
lastpoint = -1
lastX = BOTx
lastY = BOTy
endif
//TREND ATTEMPT
atr=AverageTrueRange[14](close)
if TOPy > TOPy[1] and topy<>lasttop then
drawarrowup(barindex,low-atr/2)
coloured(0,200,0)
lasttop=topy
trendup = 1
else
trendup = 0
endif
RETURN TOPy as "TOPy", BOTY as "BOTy", trendup as "trendup"
This script performs several key operations to detect and visualize trend changes:
This approach helps traders visually identify significant trend changes, potentially aiding in decision-making processes.
Check out this related content for more information:
https://www.prorealcode.com/topic/use-lower-higher-low-high-as-trend-signal/#post-148483
Visit Link