This is a simple indicator I've created to help determine whether a trend is up or down. It plots the difference between the upper and lower channels of two Donchian Channels. The lengths of the two Donchian Channels are adjustable. The difference between the lower channels is plotted as a positive number, as a green histogram while the difference between the upper channels is plotted as a negative number, as a red histogram. More green and little to no red means uptrend, while more red and little to no green means downtrend. As I like to do with most of my indicators, I've included exponential smoothing which can be toggled on or off. The smoothing factor is also adjustable. Code below:
Update: As requested by another member, I've updated the code here for this indicator to include an option that allows you to see the DC Trend of a different security than the security loaded on the price chart. By default, it is toggled on and shows the DC Trend of the SPY security. If you want to see the DC Trend of the charted security, simply toggle "show different security" to "no".
A screenshot of the indicator below a chart of the SPY:
Update: As requested by another member, I've updated the code here for this indicator to include an option that allows you to see the DC Trend of a different security than the security loaded on the price chart. By default, it is toggled on and shows the DC Trend of the SPY security. If you want to see the DC Trend of the charted security, simply toggle "show different security" to "no".
Code:
declare lower;
input DCFastLength = 9;
input DCSlowLength = 27;
input ExponentialSmoothing = yes;
input SmoothingFactor = 3;
input ShowDifferentSecuirty = yes;
input Security = "SPY";
def dcfasthigh = if ShowDifferentSecuirty == yes then highest(high(Security), DCFastLength) else highest(high, DCFastLength);
def dcfastlow = if ShowDifferentSecuirty == yes then lowest(low(Security), DCFastLength) else lowest(low, DCFastLength);
def dcslowhigh = if ShowDifferentSecuirty == yes then highest(high(Security), DCSlowLength) else highest(high, DCSlowLength);
def dcslowlow = if ShowDifferentSecuirty == yes then lowest(low(Security), DCSlowLength) else lowest(low, DCSlowLength);
def lowdiff = if ExponentialSmoothing == yes then ExpAverage(ExpAverage(ExpAverage(dcfastlow - dcslowlow, SmoothingFactor), SmoothingFactor), SmoothingFactor) else dcfastlow - dcslowlow;
def highdiff = if ExponentialSmoothing == yes then ExpAverage(ExpAverage(ExpAverage(dcfasthigh - dcslowhigh, SmoothingFactor), SmoothingFactor), SmoothingFactor) else dcfasthigh - dcslowhigh;
plot Zero = 0;
plot LowDifference = lowdiff;
plot HighDifference = highdiff;
LowDifference.setPaintingStrategy(paintingStrategy.HISTOGRAM);
LowDifference.setDefaultColor(color.GREEN);
HighDifference.setPaintingStrategy(paintingStrategy.HISTOGRAM);
HighDifference.setDefaultColor(color.RED);
A screenshot of the indicator below a chart of the SPY:
Last edited: