// HalfTrend PRC indicator 10.03.2017
//Nicolas @ www.prorealcode.com Sharing ProRealTime knowledge
lowpricei = Lowest[Amplitude](low)
highpricei = Highest[Amplitude](high)
lowma = average[Amplitude](low)
highma = average[Amplitude](high)
if barindex>Amplitude then
if(nexttrend=1) then
maxlowprice=Max(lowpricei,maxlowprice)
if(highma<maxlowprice and Close<Low[1]) then
trend=1.0
nexttrend=0
minhighprice=highpricei
endif
endif
if(nexttrend=0) then
minhighprice=Min(highpricei,minhighprice)
if(lowma>minhighprice and Close>High[1]) then
trend=0.0
nexttrend=1
maxlowprice=lowpricei
endif
endif
if(trend=0.0) then
if(trend[1]<>0.0) then
up=down[1]
else
up=Max(maxlowprice,up[1])
endif
down=0.0
else
if(trend[1]<>1.0) then
down=up[1]
else
down=Min(minhighprice,down[1])
endif
up=0.0
endif
endif
if up>0 then
halftrend = up
color = 1
else
halftrend = down
color = -1
endif
cc = customclose
ma = average [p,m](halftrend)
return cc as " cc " , halftrend coloured by color as "Half Trend" , ma as " ma ht "
// Variables :
// Amplitude = 2
// p = 6
// m = 2 pondérée