Volume Oscillator for ThinkorSwim

opunui25

New member
VIP
Summary
This modification of the Klinger Volume Oscillator (KVO) is designed to simplify signal analysis. It adds a built in histogram (similar to ToS's built-in MACD indicator), and support for colored price candles that can be toggled on or off in the options.
In a nutshell, the KVO uses high, low, close and volume to create a volume force. This volume force (VF) is then turned into an oscillator by taking a fast EMA (exponential moving average) of VF and subtracting a slow EMA of VF. A signal line (KOS), which is an EMA of the Klinger Oscillator (KO), is plotted to trigger trading signals.

Credit
Credit for the initial algorithm goes to Stephen J. Klinger.
Credit for the base script goes to Mauro Carrizales @Mauro-C https://github.com/Mauro-C

Notes
I've made some small adjustments and changes to reflect my scalping style. Please feel free to adjust the MA based on your needs. On a 5min chart, a MA of 21 seems to work rather nicely while on a 1min chart I would suggest 89. In all, sticking to Fibonacci values is the way to go.
Look for two things when using the oscillator. First is when the KOS crosses the trigger line. This is a good indication of trend reversal. Second is when the KOS crosses the Zeroline. That indicates strength is increasing in that direction. The histogram will also provide you a good visual in that regard.

Code:
# Volume_Oscillator
# Modified by (Opunui25) useThinkScript.com Member
# Based on KVO-Complete by Mauro Carrizales https://github.com/Mauro-C
# Credit for the initial algorithm goes to Stephen J. Klinger.
# Nov 13 2020
# Displays on Upper
# Plots the KVO (Klinger Volume Oscillator) using high, low, close and volume to create a volume force. This volume force (VF) is then turned into an oscillator by taking a fast EMA (exponential moving average) of VF and subtracting a slow EMA of VF. A Klinger Oscillator Signal line (KOS), which is an EMA of the Klinger Oscillator (KO), is plotted to trigger trading signals. Can be used on any timeframe.

declare lower;

#Inputs
input MALength = 20;
input PaintBars = no;

#Variables
def DM = high - low;
def Trend = if hlc3 > hlc3[1] then 1 else -1;
def CM = DM + if Trend == Trend[1] then CM[1] else DM[1];
def VForce = if CM != 0 then Trend * 100 * volume * AbsValue(2 * DM / CM - 1) else VForce[1];

#Plots
plot KOS = ExpAverage(VForce, 34) - ExpAverage(VForce, 55);
plot TriggerLine = Average(KOS, MALength);
plot ZeroLine = 0;
plot KVOH = KOS - Average(KOS, MALength);

#Painting
KVOH.DefineColor("Positive", Color.UPTICK);
KVOH.DefineColor("Negative", Color.DOWNTICK);
KVOH.AssignValueColor(if KVOH >= 0 then KVOH.color("Positive") else KVOH.color("Negative"));
KVOH.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
KVOH.SetLineWeight(3);

KOS.SetDefaultColor(GetColor(6));

TriggerLine.SetDefaultColor(GetColor(1));

ZeroLine.SetDefaultColor(GetColor(5));

#This option is controled by the PaintBars input and will allow you to change the color of the candles to reflect the current VF direction
AssignPriceColor(if KOS >= TriggerLine and PaintBars == yes then KVOH.color("Positive") else if KOS <= TriggerLine and PaintBars == yes then KVOH.color("Negative") else Color.CURRENT);
 
Last edited:

Similar threads

Top