This custom indicator is designed to provide visual feedback on market momentum and price positioning by calculating the distance between current market prices and a smoothed average of previous prices.
How it Works
The logic follows a three-step process to generate the data you see on your chart:
1. Establishing the Baseline First, the script calculates a moving average based on a specific period (which can be adjusted in the settings). Instead of looking at just the most recent price, it looks at a window of previous prices to determine a "fair value" or baseline for the market at any given moment.
2. Calculating the Deviation (The "Bears" Value) The script then measures the difference between the current low price and that moving average baseline. By subtracting the average from the low price, the indicator determines how far the price is "stretching" away from its mean. This result is displayed as a histogram, allowing you to see the magnitude of this deviation over time.
3. Smoothing the Signal To make the data easier to read and to filter out minor market "noise," the script performs one final calculation. It takes the results from the previous step and applies a second moving average to them. This creates a secondary signal line that smooths out the fluctuations, helping to highlight the broader trend of the price deviations rather than just individual price spikes.
Visual Representation
The indicator appears in a separate window below your main price chart. It uses two primary visual components:
- The Histogram: Represents the raw difference between the low price and the moving average.
- The Signal Line: Represents the smoothed trend of those differences, providing a clearer view of whether the deviation is increasing or decreasing over time.
//+------------------------------------------------------------------+
//| Bears.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_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
//---- input parameters
extern int BearsPeriod=13;
extern int SignalSMA=3;
//---- buffers
double BearsBuffer[];
double BearsSignal[];
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);
SetIndexBuffer(0,BearsBuffer);
SetIndexBuffer(1,BearsSignal);
SetIndexBuffer(2,TempBuffer);
//---- name for DataWindow and indicator subwindow label
short_name="RickW00716 Bears("+BearsPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Bears Power |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
//----
if(Bars<=BearsPeriod) return(0);
//----
int limit=Bars-counted_bars;
if(counted_bars>0) limit++;
for(i=0; i<limit; i++)
TempBuffer[i]=iMA(NULL,0,BearsPeriod,0,MODE_EMA,PRICE_CLOSE,i);
//----
i=Bars-counted_bars-1;
while(i>=0)
{
BearsBuffer[i]=Low[i]-TempBuffer[i];
i--;
}
//----
i=Bars-counted_bars-1;
while(i>=0)
{
BearsSignal[i]=iMAOnArray(BearsBuffer,Bars,SignalSMA,0,MODE_SMA,i);
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments