HPotter

Trend continuation factor, by M.H. Pee

Trend continuation factor, by M.H. Pee
The related article is copyrighted material from Stocks & Commodities.

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 13/11/2014
//    The related article is copyrighted material from Stocks & Commodities.
////////////////////////////////////////////////////////////
study(title="Trend continuation factor")
Length = input(35, minval=1)
hline(0, color=green, linestyle=line)
xChange = mom(close, 1)
xPlusChange = iff(xChange > 0, xChange, 0)
xMinusChange = iff(xChange < 0, (xChange * -1), 0)
xPlusCF = iff(xPlusChange == 0, 0, xPlusChange + nz(xPlusCF[1], 1))
xMinusCF = iff(xMinusChange == 0, 0, xMinusChange + nz(xMinusCF[1], 1))
xPlus = xPlusChange - xMinusCF
xMinus = xMinusChange - xPlusCF
xPlusTCF =  sum(xPlus, Length)
nMinusTCF = sum(xMinus, Length)
plot(xPlusTCF, color=blue, title="Plus TCF")
plot(nMinusTCF, color=red, title="Minus TCF")