• Get $40 off VIP by signing up for a free account! Sign Up

BIAS Indicator for ThinkorSwim

mashume

Expert
VIP
Lifetime
About the Indicator

The basic idea of this indicator is well summed up in several places around the internet:

https://support.moomoo.com/en-us/topic245

https://www.tradingview.com/script/HWl23Wk9/

https://medium.com/@FMZ_Quant/deviation-rate-bias-trading-strategy-18f3d2e2b5b

Calculation Variations
I have included a few additional variations, simply because I like them:
1. Standard Calculation by the method described above.
2. Alternate calculation which shows the deviation between the moving average of the close with the moving average of HL2. This was my original _mis_reading of the formula. It is here because it seemed interesting
3. VWAP as the moving average instead of HL2 for average price. Again, because VWAP.

CX Options
1. "a-b" This calculates the crossovers between the a and b lines. Difference between the fastest and medium speed lines can be useful to display as an histogram.
2. "a-zero" This calculates crossovers of the a line and the zero line.
3. "b-zero" This is similar to #2 but uses the medium speed line and the zero.

Moving Average Options
Take your pick of all of your favourites!

Display Options
1. Display cx - this will show arrows where the CX-option setting defines them to be.

Eye Candy
uceSO6b.png

1. Showing histogram for "a-b" difference option.

sBRtvQU.png

2. Showing zero crossovers.

Code:
##################
#
#   BIAS Deviance Rate Indicator
#    for ThinkOrSwim
#
#   Version 1 2021-03-18
#   This Version by @Mashume
#   released under GPL as applicable
#   to the useThinkScript community
#
####################


declare lower;

input a_length = 6;
input b_length = 12;
input c_length = 24;
input method = {default "Standard", "Modified", "VWAP"};
input show_cx = yes;
input cx_type = {default "a-b", "a-zero", "b-zero"};
input ma_type = AverageType.Simple;


script bias{
input length = 6;
input method = {default "Standard", "Modified", "VWAP"};
input ma_type = AverageType.Simple;

def average_close = MovingAverage(ma_type, close, length);
def average_price = MovingAverage(ma_type, hl2[1], length);
plot bias;
switch (method) {
    case Standard:
        bias = (close - average_price) / average_price * 100;
    case Modified:
        bias = (average_close / average_price) - 1;
    case VWAP:
        bias = (close - MovingAverage(ma_type, vwap[1], length)) / MovingAverage(ma_type, vwap[1], length) * 100;
    }
}

plot a = bias(a_length, method, ma_type);
plot b = bias(b_length, method, ma_type);
plot c = bias(c_length, method, ma_type);

a.setDefaultColor(getColor(3));
b.setDefaultColor(getColor(9));
c.setDefaultColor(getColor(5));

plot midline = 0;
midline.setDefaultColor(getColor(7));

plot cxd;
switch (cx_type) {
    case "a-b":
        cxd = if a crosses above b then 0 else double.nan;
    case "a-zero":
        cxd = if a crosses below 0 then 0 else double.nan;
    case "b-zero":
        cxd =  if b crosses below 0 then 0 else double.nan;
}
cxd.setPaintingStrategy(PaintingStrategy.ARROW_DOWN);
cxd.SetDefaultColor(GetColor(5));
cxd.SetHiding(!show_cx);

plot cxu;
switch (cx_type) {
    case "a-b":
        cxu = if a crosses below b then 0 else double.nan;
    case "a-zero":
        cxu = if a crosses above 0 then 0 else double.nan;
    case "b-zero":
        cxu =  if b crosses above 0 then 0 else double.nan;
}

cxu.setPaintingStrategy(paintingStrategy.ARROW_UP);
cxu.SetDefaultColor(GetColor(9));
cxu.SetHiding(!show_cx);

plot hist;
switch (cx_type) {
    case "a-b":
        hist = b - a;
    case "a-zero":
        hist = double.nan;
    case "b-zero":
        hist =  double.nan;
}
hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
hist.AssignValueColor(if hist < 0 then GetColor(4) else GetColor(3));

Shareable link: http://tos.mx/yqAVX6p


Happy Trading,
mashume
 
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
274 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