# Bull & Bear Power Histogram for ThinkorSwim

#### BenTen

Staff member
Staff
VIP
Showing the current strength of the stock.

Code:
``````# Bull & Bear Power Histogram
# Assembled by BenTen at useThinkScript.com

declare lower;

input Length = 30;

def r1 =if(close[1]<open, max(open-close[1], high-low),high-low);
def r2 =if(close[1]>open, max(close[1]-open, high-low),high-low);

def bull =if(close==open, if(high-close==close-low, if(close[1]>open, max(high-open, close-low),r1),if(high-close>close-low, if(close[1]<open, max(high-close[1], close-low), high-open),r1)),if(close<open, if(close[1]<open, max(high-close[1], close-low), max(high-open, close-low)),r1));
def bear =if(close==open, if(high-close==close-low, if(close[1]<open, max(open-low, high-close),r2),if(high-close>close-low, r2, if(close[1]>open, max(close[1]-low, high-close), open-low))),if(close<open, r2, if(close[1]> open, max(close[1]-low, high-close),max(open-low, high-close))));

def distance = simpleMovingAvg(bull - bear, Length);

plot diff = distance;

Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);

Diff.DefineColor("red", Color.red);
Diff.DefineColor("green", Color.green);

Diff.AssignValueColor(if distance< 0 then Diff.color("red") else Diff.color("green"));

plot ZeroLine = 0;``````

@BenTen I notice this indicator shows bullish moves above the 50 MA and bearish moves below it. Is there anyway to setup this indicator to catch bullish or bearish moves around the 10 MA? Thanks!

@KRHIlls Where do you see the 50 MA being used?

@BenTen When i use the indicator, i notice the histogram doesn't turn green until candles go above the 50 MA. When it's below the 50 MA the indicator show bearish. I was just checking out the indicator with a 50 MA. If you try it you'll see what i'm talking about. The indicator is very powerful above the 50 MA.

@BenTen When the candle is above the 50 MA and the indicator is showing green the market is strong uptrend. And below the 50 MA and the indicator showing red it's a strong downtrend. I'm using the 5 minute chart

@KRHIlls This script does not utilize the 50 simple moving average.

@BenTen I understand this script doesn't utilize the 50 SMA. I didn't see it in the code. If you just give it a try you'll see what i'm talking about. I've been trying to figure out how is this possible and the 50 SMA isn't utilized. But above the 50 the indicator show bullish and below the 50 it shows bearish. There's another indicator on this forum by the name Webby's RSI, it does the same thing. Please just look at them. If not i'll keep trying to figure them out. I don't know anything about coding but i'll keep trying. Thanks!

@KRHIlls

The following scan provides almost 400 stocks on the 5min chart that have the indicator showing Bullish with price below the 50SMA

I actually did quite well in several of these stocks on Friday.

Showing the current strength of the stock.

Code:
``````# Bull & Bear Power Histogram
# Assembled by BenTen at useThinkScript.com

declare lower;

input Length = 30;

def r1 =if(close[1]<open, max(open-close[1], high-low),high-low);
def r2 =if(close[1]>open, max(close[1]-open, high-low),high-low);

def bull =if(close==open, if(high-close==close-low, if(close[1]>open, max(high-open, close-low),r1),if(high-close>close-low, if(close[1]<open, max(high-close[1], close-low), high-open),r1)),if(close<open, if(close[1]<open, max(high-close[1], close-low), max(high-open, close-low)),r1));
def bear =if(close==open, if(high-close==close-low, if(close[1]<open, max(open-low, high-close),r2),if(high-close>close-low, r2, if(close[1]>open, max(close[1]-low, high-close), open-low))),if(close<open, r2, if(close[1]> open, max(close[1]-low, high-close),max(open-low, high-close))));

def distance = simpleMovingAvg(bull - bear, Length);

plot diff = distance;

Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);

Diff.DefineColor("red", Color.red);
Diff.DefineColor("green", Color.green);

Diff.AssignValueColor(if distance< 0 then Diff.color("red") else Diff.color("green"));

plot ZeroLine = 0;``````
Ben - Could we use any length other than 30? Is 30 the MA?

Ben - Could we use any length other than 30? Is 30 the MA?
The script that you quoted looks at the moving average of ratio of bull to bear price action.
Yes, the moving average looks at a length of 30 bars which is a standard default for most day and short-medium swing traders.

87k+ Posts
297 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?