The BearBulls indicator is designed to provide traders with a visual representation of market momentum by measuring the distance between current price action and a smoothed average of recent historical prices. It effectively highlights the "strength" behind both upward (bullish) and downward (bearish) price movements.
Core Logic Overview
The script functions by identifying a baseline trend and then calculating how far the actual market highs and lows deviate from that baseline. Here is the step-by-step breakdown of how it processes information:
-
Establishing the Baseline: The indicator first calculates a moving average based on the closing prices over a specific timeframe (defined by the user). This average acts as a "fair value" or equilibrium line, smoothing out the minor fluctuations of the market to show the general direction.
-
Measuring Market Tension: Once the baseline is established, the script looks at two specific data points for every candle:
- The High Price: The highest point reached during a period.
- The Low Price: The lowest point reached during a period.
-
Calculating Bear vs. Bull Strength: The indicator then performs two separate calculations to determine the intensity of the market's movement:
- Bearish Strength: It subtracts the moving average from the low price. This shows how much "room" there is for downward pressure or how deep the price has dipped relative to the average.
- Bullish Strength: It subtracts the moving average from the high price. This measures the upward reach of the price relative to the average.
Visual Representation
The results are displayed in a separate window below your main chart as a histogram:
- Red Histograms: Represent bearish activity or downward pressure.
- Lime Histograms: Represent bullish activity or upward momentum.
By observing these bars, traders can visually assess whether the market is pushing aggressively in one direction or if it is struggling to move away from its average price level. The thicker lines and distinct colors allow for a quick at-a-glance assessment of which side of the market—the "Bears" or the "Bulls"—is currently dominating the price action.
//+------------------------------------------------------------------+
//| BearBulls.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_level1 0.0002
#property indicator_level2 -0.0002
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Lime
#property indicator_width1 4
#property indicator_width2 2
//---- input parameters
extern int BearsBullsPeriod=13;
//---- buffers
double BearsBuffer[];
double BullsBuffer[];
double TempBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- 1 additional buffer used for counting.
IndicatorBuffers(3);
IndicatorDigits(Digits);
//---- indicator line
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(0,BearsBuffer);
SetIndexBuffer(1,BullsBuffer);
SetIndexBuffer(2,TempBuffer);
//---- name for DataWindow and indicator subwindow label
short_name="BearBulls("+BearsBullsPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
SetIndexLabel(1,"BearBulls2("+BearsBullsPeriod+")");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Bears Power |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
//----
if(Bars<=BearsBullsPeriod) return(0);
//----
int limit=Bars-counted_bars;
if(counted_bars>0) limit++;
for(i=0; i<limit; i++)
TempBuffer[i]=iMA(NULL,0,BearsBullsPeriod,0,MODE_EMA,PRICE_CLOSE,i);
//----
i=Bars-counted_bars-1;
while(i>=0)
{
BearsBuffer[i]=Low[i]-TempBuffer[i];
BullsBuffer[i]=High[i]-TempBuffer[i];
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments