Thursday, October 23, 2008

ADX Histogram - ThinkorSwim ThinkScript

For those of you who like using the ADX technical indicator, I saw a newsletter that had a "histogram" version of the ADX line and I thought it looked easier to digest, so I went ahead and added some modifications to the one that comes with ThinkorSwim. Since all I did here was add on some additional code, I don't take credit for the bulk of what is there, merely my histogram conversion.

declare lower;

input length = 14;

def hidiff = high - high[1];
def lodiff = low[1] - low;

def dmim = if (hidiff < 0 and lodiff < 0) or hidiff >= lodiff then 0 else lodiff;
def dmip = if (hidiff < 0 and lodiff < 0) or lodiff >= hidiff then 0 else hidiff;

rec wdmim = compoundValue("historical data" = Average(dmim, length), "visible data" = (dmim + wdmim[1] * (length - 1)) / length);
rec wdmip = compoundValue("historical data" = Average(dmip, length), "visible data" = (dmip + wdmip[1] * (length - 1)) / length);
rec volty = compoundValue("historical data" = Average(TrueRange(high, close, low), length), "visible data" = (TrueRange(high, close, low) + volty[1] * (length - 1)) / length);

def dip = 100 * wdmip / volty;
def dim = 100 * wdmim / volty;

def dx = if (dip + dim > 0) then 100 * AbsValue(dip - dim) / (dip + dim) else 0;
rec va = (if IsNaN(va[1]) then 0 else va[1]) + dx;
rec val = compoundValue(length = length, "historical data" = va / (TotalSum(1) + 1), "visible data" = (val[1] * (length - 1) + dx) / length);

plot ADX = val;
ADX.AssignValueColor(if ADX > ADX[1] then
Color.UPTICK
else
if ADX < ADX[1] then
Color.DOWNTICK
else
GetColor(1)
);

ADX.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);






1 comments:

Bob Campbell said...

Hi Chris,
I've enjoyed so many of your studies. Just wanted to let you know I've been learning from your code, and appreciate the studies you have written.

I know people who do crossword puzzles, and that's what writing code is like for me. It's a pleasant way to keep my mind sharp.

I kinda get that that's where you are at too.

One of my favorite routine was the indicator that represented RSI, DMI and the Stochastic in a band,

Keep up the good work my friend.