MFI & %B For ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
The Money Flow Index (MFI) and Bollinger Bands are technical indicators that can be combined to identify price swings and trends:

MFI
A volume-weighted oscillator that measures price momentum and strength using price and volume data.

Bollinger Bands
A statistical chart that consists of a middle band and two outer bands that are calculated based on standard deviations from the middle band. The upper band is often considered resistance, the lower band is often considered support, and the middle band can act as either support or resistance depending on price.

Combining MFI and Bollinger Bands
Traders can use MFI and Bollinger Bands to identify when an asset's price might reverse, which can happen when the price touches the upper or lower Bollinger Band.

For example, John Bollinger's trading strategy uses %B, a technical indicator derived from Bollinger Bands, and MFI to identify the start of a new trend.

This study's approach differs from J.Bollinger's strategy, in that, it is averaging Money Flow Index and Bollinger Bands' %B
Colored bars indicate buy or sell signals


3sqFz8k.png


Per member @netarchitech request
https://usethinkscript.com/threads/...-pinescript-to-thinkscript.19442/#post-145266

original Tradingview script: https://www.tradingview.com/script/v6f40cDT-MFI-B-seiglerj/
see below for the ThinkOrSwim Study

CSS:
#// @author seiglerj
#// product of MFI and %B for reliable signals based on price, volatility, and volume
#study(title = "MFI & %B [seiglerj]", shorttitle="MFI & %B", precision=2)
declare lower;

input source = hlc3;
input mfilength = 14; #, title="MFI length", minval=1)
input bblength = 20; #, title="BB length", minval=1)
input bbstdevs = 2; #, title="BB std dev", minval=0, type=float)
input lower = 20; #, title="Lower Bound", minval=0, maxval=50, type=integer)
input upper = 80; #, title="Upper Bound", minval=50, maxval=100, type=integer)
input DrawMFI = yes; #(true, title="Draw MFI", type=bool)
input DrawBBP = yes; #(true, title="Draw %B", type=bool)
input DrawProd = yes; #t(true, title="Draw Product", type=bool)
input HighlightBreaches = yes; #, title="Highlight Breaches?", type=bool)

def na = Double.NaN;
def last = IsNaN(close);
#// MFI
def mf = MoneyFlowIndex(Length =  mfilength);
def mfScaled = (mf - lower) / (upper - lower); # // inner band becomes 0-1 like B%

#// BB
def bbavg = Average(source, bblength);
def bbdev = bbstdevs * StDev(source, bblength);
def bbupper = bbavg + bbdev;
def bblower = bbavg - bbdev;
def bbp = (source - bblower) / (bbupper - bblower); # // usually 0-1, can exceed those bounds

#// combined
def both = (if mfScaled > 0.5 and bbp > 0.5 then Min(mfScaled, bbp) else
           (if mfScaled < 0.5 and bbp < 0.5 then Max(mfScaled, bbp) else (mfScaled + bbp) / 2));

#// Draw MFI
plot mfp = if DrawMFI then mfScaled else  na; #, title="MFI", color=color(yellow, 0), linewidth=1)
#// Draw %B
plot bbpp = if DrawBBP then bbp else na; #, title="%B", color=color(aqua, 0), linewidth=1)
#// Draw combined
plot bothPlot = if DrawProd then both else na; #, title="Average", color=color(black, 100), linewidth=1, editable=false)
mfp.SetDefaultColor(GetColor(4));
bbpp.SetDefaultColor(GetColor(1));
bothPlot.SetDefaultColor(GetColor(3));
#// Draw min chart bounds
def top = if last then na else 1; #, color=color(black,100), editable=false)
plot mid = if last then na else 0.5;
def bottom = if last then na else 0; #, color=color(black,100), editable=false)
mid.SetDefaultColor(Color.DARK_GRAY);
#// Breaches
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def b_color = if !HighlightBreaches then 0 else if both > 1 then -1 else if both < 0 then 1 else 0;

AddCloud(if (b_color>0 or b_color[1]>0) then pos else na, neg, Color.GREEN);
AddCloud(if (b_color<0 or b_color[1]<0) then pos else na, neg, Color.RED);

AddCloud(top, bottom, Color.DARK_GRAY);

# End of CODE
 
Last edited by a moderator:

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