Posted on

Porting the Visualizing Displacement indicator from TradingView PineScript to Thinkorswim ThinkScript

porting an indicator from tradingview to thinkorswim

Today I had a customer request a port of the “Visualizing Displacement” indicator from Tradingview Pine Script over to Thinkorswim, so I made a video of the translation/porting process here to teach people ThinkScript and provide a free indicator.

The original indicator is found here:

https://www.tradingview.com/script/n6djFgQH-Visualizing-Displacement-TFO/

The original PineScript code is as follows:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradeforopp

//@version=5
indicator("Visualizing Displacement [TFO]", "Displacement [TFO]", true)

require_fvg = input.bool(true, "Require FVG")
disp_type = input.string("Open to Close", "Displacement Type", options = ['Open to Close', 'High to Low'])
std_len = input.int(100, minval = 1, title = "Displacement Length", tooltip = "How far back the script will look to determine the candle range standard deviation")
std_x = input.int(4, minval = 0, title = "Displacement Strength")
disp_color = input.color(color.yellow, "Bar Color")

candle_range = disp_type == "Open to Close" ? math.abs(open - close) : high - low
std = ta.stdev(candle_range, std_len) * std_x
fvg = close[1] > open[1] ? high[2] < low[0] : low[2] > high[0]

displacement = require_fvg ? candle_range[1] > std[1] and fvg : candle_range > std

barcolor(displacement ? disp_color : na, offset = require_fvg ? -1 : na)

The modified ThinkScript code, line by line, is as follows (import here: http://tos.mx/uI1jVGJ ):

#require_fvg = input.bool(true, "Require FVG")
input requireFvg = yes;

#disp_type = input.string("Open to Close", "Displacement Type", options = ['Open to Close', 'High to Low'])
input displayType = {default OpenToClose, HighToLow};

#std_len = input.int(100, minval = 1, title = "Displacement Length", tooltip = "How far back the script will look to determine the candle range standard deviation")
input stdDevLength = 100;

#std_x = input.int(4, minval = 0, title = "Displacement Strength")
input displacementStrength = 4;

#candle_range = disp_type == "Open to Close" ? math.abs(open - close) : high - low
def candleRange = if displayType == displayType.OpenToClose then bodyHeight() else high - low; # absValue(open - close)

#std = ta.stdev(candle_range, std_len) * std_x
def std = standardDeviation(candleRange, stdDevLength) * displacementStrength;

#fvg = close[1] > open[1] ? high[2] < low : low[2] > high
def fvg = if close[1] > open[1] then high[2] < low else low[2] > high;

#displacement = require_fvg ? candle_range[1] > std[1] and fvg : candle_range > std
def displacement = if requireFvg then candleRange[1] > std[1] and fvg else candleRange > std;

# disp_color = input.color(color.yellow, "Bar Color")
defineGlobalColor("Bar Color", color.yellow);

# barcolor(displacement ? disp_color : na, offset = require_fvg ? -1 : na)
def offset = if requireFvg then -1 else 0;

assignPriceColor(if displacement[offset] then globalColor("Bar Color") else color.current);

The final code without comments is below:

input requireFvg = yes;
input displayType = {default OpenToClose, HighToLow};
input stdDevLength = 100;
input displacementStrength = 4;

def candleRange = if displayType == displayType.OpenToClose then bodyHeight() else high - low; # absValue(open - close)
def std = standardDeviation(candleRange, stdDevLength) * displacementStrength;
def fvg = if close[1] > open[1] then high[2] < low else low[2] > high;
def displacement = if requireFvg then candleRange[1] > std[1] and fvg else candleRange > std;
def offset = if requireFvg then -1 else 0;

defineGlobalColor("Bar Color", color.yellow);
assignPriceColor(if displacement[offset] then globalColor("Bar Color") else color.current);
Posted on

Free: Volatility Normalized MACD-V

Awhile back I had a trader email requesting I code this indicator for Thinkorswim. At the time I wasn’t able to get to it, and I’ve subsequently lost the email, so I thought I would put this out there in the universe in case he happens to run across it here, and in case anyone else can use it.

Easycators Volatility Normalized MACD-V implementation: http://tos.mx/1VziaCe

And here’s the research paper with the details:

https://bit.ly/3El2L9V

“The output of the indicator is
the amount of momentum a security has,
that is in excess of its average volatility,
expressed as a percentage.
We are measuring directional strength,
“purified” from volatility fluctuations”

Alex Spiroglou
Traditional MACD vs. Volatility Normalized MACD-V for Thinkorswim
Posted on

Relative Volume Gradient Paintbars – New Updates for ThinkOrSwim

Relative Volume Gradient Paintbars for Thinkorswim [VIDEO]

Relative Volume Gradient Paintbars Study for Thinkorswim

Today I’m releasing an overhaul of the Relative Volume indicator for Thinkorswim that I’ve been working on for awhile. This is one of my favorite thinkscript studies and I’ve been experimenting with it in my own trading for awhile, so I wanted to go ahead and get the update released on the site and see if it can add some value for my fellow traders.

Like all of our upgrades, they’re completely free to prior purchasers, just go to the My Account > Orders > View Order Details area of the site and the new links should be posted there for you to install.

New Features

  1. Relative Volume Gradient Paintbars to highlight the highest relative volume bars!
    1. Custom colors
    2. 4 custom coloration thresholds
    3. Different color scheme for up bars vs. down bars
  2. MA-based relative volume for tick charts, also with gradient paintbars!
  3. Combined tick volume / trade volume in the same indicator, just switch the mode in settings. Simply add 2 instances if you want both relative tick count & share count on the same chart!
  4. Combined long term studies into 1 study with custom period reset (12 for monthly charts, 52 for weekly charts, 252 for daily charts).
  5. Added a TIME BASED relative volume QUOTE COLUMN so you can see when a stock in your watchlist has surging volume on whatever INTRADAY timeframe you want (5 minute, hourly, etc).
  6. Added a MA BASED relative volume QUOTE COLUMN so you can see when a stock in your watchlist has surging volume on ANY timeframe you want (hourly, daily, etc).

Benefits

  • High volume bars now immediately pop out visually on your chart without having to look down at the histogram.
  • You can even hide the histogram altogether and just use the paintbars function to gauge volume and save screen space.
  • This release really simplifies down the number of scripts and makes each more powerful and customizable.
  • MA-based relative volume indicator can be used on tick charts, intraday minute charts, or daily and higher charts.
  • Using the MA-based relative volume on tick charts lets you see an additional dimension of volume on the same graph (tick count bars combined with share count highlighting really adds additional depth of information).

Get the Relative Volume study here!

I’m finding the volume gradient to be a real value add, and especially on the tick charts:

relative volume gradient paintbars indicator for thinkorswim
Example chart of KO with the new relative volume gradient paintbars indicator for Thinkorswim

Get the Relative Volume study here!