Below you will find various custom written ThinkScript code snippets that can be used in charting and stock scanners on the ThinkorSwim platform.

Millions (Dollar Volume)

declare lower;
input offset = .000001;
plot million = Round(((volume * close) * offset),2);

million.AssignValueColor(
if million > million[1] then CreateColor(0, 204, 102) # Green
else if million < million[1] then CreateColor(255, 95, 95) # Red
else CreateColor(70, 162, 255));

million.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

AddLabel(yes, million,CreateColor(25, 202, 247));

Average Intraday Volatility

declare lower;

input length = 10;
input price = close;
input avg = AverageType.EXPONENTIAL;

def range = high[0] – low[0];
plot avr = RoundUp(MovingAverage(avg, range, length), 2);

avr.SetDefaultColor(Color.MAGENTA);
avr.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

avr.AssignValueColor(if avr > avr[1] then CreateColor(0,204,102) else if avr[1] > avr then CreateColor(255,95,95) else (Color.WHITE));

AddLabel(yes, “AvgRange: ” + avr, CreateColor(25, 202, 247));

Stock/Index Overlay (Check Left Axis via Gear Icon)

input stock = “NDX”;
plot symbol = Close(stock);
symbol.SetDefaultColor(Color.MAGENTA);

Correlation Labels

input length = 10;
input NDX = “NDX”;
input SPX = “SPX”;
input DJX = “DJX”;
input BZ = “/BZ”;
input GC = “/GC”;
def nas = RoundUp(Correlation(close, close(NDX), length) * (100), 0);
def sp = RoundUp(Correlation(close, close(SPX), length) * (100), 0);
def dow = RoundUp(Correlation(close, close(DJX), length) * (100), 0);
def crude = RoundUp(Correlation(close, close(BZ), length) * (100), 0);
def gold = RoundUp(Correlation(close, close(GC), length) * (100), 0);

Addlabel(yes,”NDX: ” + nas + ” | S&P: ” + sp + ” | DOW: “+ dow + ” | BZ: ” + crude + ” | GC: ” + gold, color.light_gray );

Average Percent Volatility /w Moving Average

declare lower;
input length = 10;
input price = close;
input avg = AverageType.EXPONENTIAL;
def range = high[0] – low[0];

def avr_ema = RoundUp(MovingAverage(avg, range, length), 2);
plot vlt = Round((avr_ema/price)*(100),1);

def mean = (Sum(vlt, 10))/(10);
plot mean_line = mean;

AddLabel(yes, “AvgVlt: ” + vlt, Color.WHITE);

vlt.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
vlt.AssignValueColor(if vlt > mean then CreateColor(0,204,102) else if mean > vlt then CreateColor(255,95,95) else CreateColor(70,162,255));

Average OverNight Volatility

declare lower;

input avg = AverageType.EXPONENTIAL;
input period = 10;

def range = open[0] – close[1];

plot AvgONRange = RoundUp(MovingAverage(avg, range, period), 2);

AddLabel(yes, “AvgONRange: ” + AvgONRange, CreateColor(25, 202, 247));

AvgONRange.SetDefaultColor(Color.MAGENTA);
AvgONRange.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

AvgONRange.AssignValueColor(if AvgONRange > AvgONRange[1] then CreateColor(0,204,102) else if AvgONRange < AvgONRange[1] then CreateColor(255,95,95) else (Color.GRAY));

plot Zero = 0;
Zero.SetDefaultColor(Color.GREEN);

Stock Correlation

declare lower;
input length = 10;
input stock = “NDX”;
plot correlation = RoundUp(correlation(close, close(stock), length)*(100),0);

plot zero = 0;
zero.SetDefaultColor(Color.MAGENTA);;
correlation.SetDefaultColor(Color.GREEN);;
Addlabel(yes, correlation, Color.GREEN);

Visual Earnings Labels | Estimated vs Actual

def price = close;
def estimate = GetEstimatedEarnings();
def actual = GetActualearnings();
def get_price = if estimate and actual then price else get_price[1];
def gain = (actual – estimate);
AddChartBubble(estimate,close, “Est: ” + estimate + “\nAct: ” + actual + “\nGain: ” + gain, if actual <= estimate then CreateColor(247, 25, 91) else CreateColor(25, 202, 247));