OnBalance Volume For ThinkOrSwim

Mike

Member
VIP
Hi. Can someone help me code or point me in the right direction to create a label for On Balance Volume Closing Above or Below a Moving Average? If closing above color Dark_Green if closing below color Dark_Red. Thanks!
 
On Balance Volume Modified (OBVM) is a variation of On Balance Volume (OBV) that adds a signal line and smooths out the OBV with an exponential moving average.

OBV is a momentum indicator that tracks changes in trading volume to predict price movements and market player strategies.

OBVM can help determine when major market moves might occur, and can be most useful as an entry filter when an instrument is testing a major support or resistance level.

Here are some scripts that provide different options. These studies should further your quest.
Bxl3Eku.png


Upper Chart Label:
Ruby:
## ########################################################
#ToS OnBalanceVolumeModified
## ########################################################

input signalLength = 10;
input averageType = "exponential" ;

def obvm = OnBalanceVolumeModified().obVM;
def ema = OnBalanceVolumeModified("signal length" = signalLength, "average type" = averageType).Signal; ;

def crossUP = if  obvm crosses above ema  then ema else double.NaN ;
def crossDN = if  obvm crosses below ema  then obvm else double.NaN ;

## ########################################################
# Charting & Formatting

DefineGlobalColor("bull", Color.green) ;
DefineGlobalColor("bear", Color.red) ;
DefineGlobalColor("crossup", Color.cyan) ;
DefineGlobalColor("crossdn", Color.magenta) ;

AddLabel(yes,
if  obvm crosses above ema then "obv cross up!" else
if  obvm crosses below ema then "obv cross down!" else
if obvm > ema then "obv trending above" else " |  obv trending below",

if  obvm crosses above ema then GlobalColor("crossup") else
if  obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));

input paintCandles = yes ;
AssignPriceColor(
if !paintCandles then color.current else
if  obvm crosses above ema then GlobalColor("crossup") else
if  obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));

Lower Chart :
Ruby:
## ########################################################
#ToS OnBalanceVolumeModified
## ########################################################
declare lower;
declare real_size;
DefineGlobalColor("bull", Color.green) ;
DefineGlobalColor("bear", Color.red) ;
DefineGlobalColor("crossup", Color.cyan) ;
DefineGlobalColor("crossdn", Color.magenta) ;

input signalLength = 10;
input averageType = "exponential" ;

plot obvm = OnBalanceVolumeModified().obVM;
plot ema = OnBalanceVolumeModified("signal length" = signalLength, "average type" = averageType).Signal; ;

addcloud(obvm, ema, GlobalColor("bull"), GlobalColor("bear"));

plot crossUP = if  obvm crosses above ema  then ema else double.NaN ;
crossUP.SetPaintingStrategy(PaintingStrategy.ARROW_up);
crossUP.SetDefaultColor(GlobalColor("crossup")) ;
crossUP.SetLineWeight(3);

plot crossDN = if  obvm crosses below ema  then obvm else double.NaN ;
crossDN.SetPaintingStrategy(PaintingStrategy.ARROW_down);
crossDN.SetDefaultColor(GlobalColor("crossdn")) ;
crossDN.SetLineWeight(3);

input showLabel = yes ;
AddLabel(showLabel,
if  obvm crosses above ema then "obv cross up!" else
if  obvm crosses below ema then "obv cross down!" else
if obvm > ema then "obv trending above" else " |  obv trending below",

if  obvm crosses above ema then GlobalColor("crossup") else
if  obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));

input paintCandles = yes ;
AssignPriceColor(
if !paintCandles then color.current else
if  obvm crosses above ema then GlobalColor("crossup") else
if  obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));
 
Last edited by a moderator:
I've reviewed the code (#3) above and have the following comments/questions:

1) I'd like to code an upper OBV chart label. How can I modify the code to identify the moving average type, the moving average length, and color the label dark_green if the OBV closes above the moving average else color the label dark_red if the OBV closes below the moving average. Thanks...
 
Last edited by a moderator:
I've reviewed the code (#3) above and have the following comments/questions:

1) I'd like to code an upper OBV chart label. How can I modify the code to identify the moving average type, the moving average length, and color the label dark_green if the OBV closes above the moving average else color the label dark_red if the OBV closes below the moving average. Thanks...

Modified OBV labels to identify the moving average type, the moving average length
See bottom of post for instructions to adjust the colors used in these scripts.

2XbGCbh.png

Ruby:
## ########################################################
# OnBalanceVolumeModified
# mike request
## ########################################################

input signalLength = 10;
input averageType = "exponential" ;

def obvm = OnBalanceVolumeModified().obVM;
def ema = OnBalanceVolumeModified("signal length" = signalLength, "average type" = averageType).Signal; ;

def crossUP = if  obvm crosses above ema  then ema else double.NaN ;
def crossDN = if  obvm crosses below ema  then obvm else double.NaN ;

## ########################################################
# Charting & Formatting

DefineGlobalColor("bull", Color.dark_green) ;
DefineGlobalColor("bear", Color.dark_red) ;
DefineGlobalColor("crossup", Color.cyan) ;
DefineGlobalColor("crossdn", Color.magenta) ;

AddLabel(yes,
"OBVm average used: "  +averageType +" | average length: " +signalLength+
if  obvm crosses above ema then " |  obv cross up!" else
if  obvm crosses below ema then " |  obv cross down!" else
if obvm > ema then " |  obv trending above" else " |  obv trending below",

if  obvm crosses above ema then GlobalColor("crossup") else
if  obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));

input paintCandles = no ;
AssignPriceColor(
if !paintCandles then color.current else
if  obvm crosses above ema then GlobalColor("crossup") else
if  obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));

yHglyac.png


Adjusting Global Colors:
1. click on studies beaker
2. click on gear to the right of the study placed on the chart
3. click on Globals
4. click on the color to be changed
5. change color and save

MAKE SURE to click on "Save as default" to save your settings to be used on future charts.
 

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
381 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