Here i have made a kind of MACD indicator from the halftrend indicator from the Great NICOLAS, after the improvement from him , I want to shared with everybody.
The histogram is made from the difference of 2 HalfTrend indicator (one long and one short period), then a signal line, built with an average of 6 periods of the histogram values is added.
Trades signals are the same than a normal MACD: long position when the histogram is crossing the zero line, short order when the histogram cross the zero level. The signal line can act the same, any crosses made with the histogram could result as an new order on market:
//PRC_HalfTrend MACD | indicator
//10.03.2017
//by LUCASSEN adapted code from
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//Amplitude1 = 2
//Amplitude2 = 6
//Amplitude3 = 30
// -- HL #1
lowpricei1 = Lowest[Amplitude1](low)
highpricei1 = Highest[Amplitude1](high)
lowma1 = average[Amplitude1](low)
highma1 = average[Amplitude1](high)
if barindex>Amplitude1 then
if(nexttrend1=1) then
maxlowprice1=Max(lowpricei1,maxlowprice1)
if(highma1<maxlowprice1 and Close<Low[1]) then
trend1=1.0
nexttrend1=0
minhighprice1=highpricei1
endif
endif
if(nexttrend1=0) then
minhighprice1=Min(highpricei1,minhighprice1)
if(lowma1>minhighprice1 and Close>High[1]) then
trend1=0.0
nexttrend1=1
maxlowprice1=lowpricei1
endif
endif
if(trend1=0.0) then
if(trend1[1]<>0.0) then
up1=down1[1]
else
up1=Max(maxlowprice1,up1[1])
endif
down1=0.0
else
if(trend1[1]<>1.0) then
down1=up1[1]
else
down1=Min(minhighprice1,down1[1])
endif
up1=0.0
endif
endif
// -- HL #2
lowpricei2 = Lowest[Amplitude2](low)
highpricei2 = Highest[Amplitude2](high)
lowma2 = average[Amplitude2](low)
highma2= average[Amplitude2](high)
if barindex>Amplitude2 then
if(nexttrend2=1) then
maxlowprice2=Max(lowpricei2,maxlowprice2)
if(highma2<maxlowprice2 and Close<Low[1]) then
trend2=1.0
nexttrend2=0
minhighprice2=highpricei2
endif
endif
if(nexttrend2=0) then
minhighprice2=Min(highpricei2,minhighprice2)
if(lowma2>minhighprice2 and Close>High[1]) then
trend2=0.0
nexttrend2=1
maxlowprice2=lowpricei2
endif
endif
if(trend2=0.0) then
if(trend2[1]<>0.0) then
up2=down2[1]
else
up2=Max(maxlowprice2,up2[1])
endif
down2=0.0
else
if(trend2[1]<>1.0) then
down2=up2[1]
else
down2=Min(minhighprice2,down2[1])
endif
up2=0.0
endif
endif
if up2>0 then
halftrend2 = up2
else
halftrend2 = down2
endif
// -- HL #3
lowpricei3 = Lowest[Amplitude3](low)
highpricei3 = Highest[Amplitude3](high)
lowma3 = average[Amplitude3](low)
highma3= average[Amplitude3](high)
if barindex>Amplitude3 then
if(nexttrend3=1) then
maxlowprice3=Max(lowpricei3,maxlowprice3)
if(highma3<maxlowprice3 and Close<Low[1]) then
trend3=1.0
nexttrend3=0
minhighprice3=highpricei3
endif
endif
if(nexttrend3=0) then
minhighprice3=Min(highpricei3,minhighprice3)
if(lowma3>minhighprice3 and Close>High[1]) then
trend3=0.0
nexttrend3=1
maxlowprice3=lowpricei3
endif
endif
if(trend3=0.0) then
if(trend3[1]<>0.0) then
up3=down3[1]
else
up3=Max(maxlowprice3,up3[1])
endif
down3=0.0
else
if(trend3[1]<>1.0) then
down3=up3[1]
else
down3=Min(minhighprice3,down3[1])
endif
up3=0.0
endif
endif
if up3>0 then
halftrend3 = up3
else
halftrend3 = down3
endif
return (halftrend2 - halftrend3),average[6] (halftrend2 - halftrend3)