# BIAS Indicator for ThinkorSwim

#### mashume

##### Expert
VIP

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

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

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

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

Eye Candy

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

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

mashume

Last edited by a moderator:

87k+ Posts
274 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?