Klinger Volume Oscillator for ThinkorSwim

opunui25

New member
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:
I updated the code below, but as a lower study it still won't print the arrows as shown in the last picture I sent. In past scripts I was able to choose (in the settings for the lower study) Values: "Numerical" - Draw as: "(first choice...squiggley line)" - Style: "straight line" - Width: "1". In this case I can only choose "draw as" and use the arrows. Is there any way to replicate the PMO from above? Attached is what it currently gave me.
AWxg6GZ.png
[/IMG]

# 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);

plot upArrow1 = if TriggerLine crosses above Zeroline then Zeroline else Double.NaN;
upArrow1.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
upArrow1.SetDefaultColor(Color.green);

plot dnArrow1 = if TriggerLine crosses below Zeroline then Zeroline else Double.NaN;;
dnArrow1.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
dnArrow1.SetDefaultColor(Color.red);


#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 by a moderator:
I updated the code below, but as a lower study it still won't print the arrows as shown in the last picture I sent. In past scripts I was able to choose (in the settings for the lower study) Values: "Numerical" - Draw as: "(first choice...squiggley line)" - Style: "straight line" - Width: "1". In this case I can only choose "draw as" and use the arrows. Is there any way to replicate the PMO from above? Attached is what it currently gave me.[/IMG]
Sorry, I have no idea what you are asking.
The code that you posted above produces a chart that looks like this:
C4UNrC6.png

You shouldn't be playing with settings or squiggly lines or what not.
  1. create a new study (yours is definitely broken)
  2. cut & paste your code.
  3. add it to your chart
  4. set the ticker to $CPB
  5. set the aggregation to 10min
If it doesn't produce an identical chart as mine. You either didn't follow the instructions that I just gave you or
your app is having bigger problems than missing some arrows
 
Last edited:
There was definitely something wrong with the study. I deleted and re-copied/pasted and it works great now. Sorry about that..appreciate the help, really. I'll make sure to do that again next time.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
355 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top