Volatility Based Momentum Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
The Volatility Based Momentum (VBM) indicator is a variation on the rate-of-change ( ROC ) indicator. Instead of expressing momentum in a percentage gain or loss, VBM normalizes momentum using the historical volatility of the underlying security...The calculation for a volatility based momentum (VBM) indicator is very similar to ROC , but divides by the security’s historical volatility instead. The average true range indicator (ATR) is used to compute historical volatility.

For example, on a daily chart , VBM(22,65) calculates how many MoV price has increased or decreased over the last 22 trading days (approximately one calendar month). The second parameter is the number of periods to use with the ATR indicator to normalize the momentum in terms of volatility.

For more details, there is an article further describing VBM and its applicability versus ROC.

U03412B.png


thinkScript Code

Code:
declare lower;

input rocPeriod = 22;
input atrPeriod = 65;

def rateOfChange = close[0] - close[rocPeriod];
def normalizationATR = atr(atrPeriod)[0];
def volatilityBasedMomentum = rateOfChange / normalizationATR;

plot VBM = volatilityBasedMomentum;
plot ZeroLine = 0;
ZeroLine.AssignValueColor(GetColor(0));
 

tomsk

Well-known member
VIP
I looked at this request, after adding the snippet that @BenTen posted earlier, the resulting display does look a bit squished. I was thinking that perhaps it might be a better idea to transform this into an upper study so that the arrows can be clearly marked on the chart. However perhaps this might not be a perfect study to use for buy/sell as we see the convergence of the so-called "buy"/"sell" arrows that make the signal not clear and confusing. However if the requester really wishes to see those arrows, here is version 1.1 based on @BenTen original study

Code:
# Volatility Based Momentum
# tomsk
# 1.12.2020

# V1.0 - 12.03.2019 - BenTen - Initial release of Volatility Based Momentum study (Lower Study)
# V1.1 - 01.12.2020 - tomsk  - Converted to upper study so that intended signals can be displayed

input rocPeriod = 22;
input atrPeriod = 65;

def rateOfChange = close[0] - close[rocPeriod];
def normalizationATR = atr(atrPeriod)[0];
def volatilityBasedMomentum = rateOfChange / normalizationATR;
def VBM = volatilityBasedMomentum;

plot bull = if VBM crosses above 0 then low * 0.996  else Double.NaN;
plot bear = if VBM crosses below 0 then high * 1.004 else Double.NaN;

bull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bull.SetDefaultColor(Color.YELLOW);
bull.SetLineWeight(3);

bear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bear.SetDefaultColor(Color.CYAN);
bear.SetLineWeight(3);
# End Volatility Based Momentum
 

diazlaz

Well-known member
2019 Donor
VIP
thanks @tomsk - Quick testing on lower time frames, a value of 15, 39 seems to be a good optimization for lower time frame intraday scalps (e.g. 1 to 3 min TF).
 

Yoel Pablo

New member
Hi Tomsk,

Can you please help me with code?
Can you help me convert the lower study to upper study so that the arrows can be clearly marked on the chart with sound alert? I tried to convert the lower study code to upper study but was unable to. Enclosed is the lower code

Code:
#----Momentum
Declare lower;

input length = 12;
input price = close;
input showBreakoutSignals = no;

Assert(length > 0, "'length' must be positive: " + length);

plot Momentum = price - price[length];
plot ZeroLine = 0;
plot UpSignal = if Momentum crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Momentum crosses below ZeroLine then ZeroLine else Double.NaN;


UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

Momentum.SetDefaultColor(GetColor(1));
ZeroLine.SetDefaultColor(GetColor(0));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);


# Alerts
Alert( UpSignal, " ", Alert.BAR, Sound.RING);
Alert(DownSignal, " ", Alert.BAR, Sound.RING);
.... and the other one is the code I tried to convert to upper study.

Code:
#---Momentum_Upper

input length = 12;
input price = close;

Assert(length > 0, "'length' must be positive: " + length);

def Momentum = price - price[length];
def ZeroLine = 0;

plot UpSignal = if Momentum crosses above ZeroLine then ZeroLine else Double.NaN;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

plot DownSignal = if Momentum crosses below ZeroLine then ZeroLine else Double.NaN;
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

# Alerts
Alert( UpSignal, " ", Alert.BAR, Sound.Ring);
Alert(DownSignal, " ", Alert.BAR, Sound.Ring);
I truly appreciate your time and effort. Thank you!

Kindly,
YP
 
Last edited by a moderator:

horserider

Well-known member
VIP
Check logic here.
plot UpSignal = if Momentum crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Momentum crosses below ZeroLine then ZeroLine else Double.NaN;

and boolean arrows
 

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.
Top