This tool is designed to provide traders with a visual representation of market "bias"—essentially measuring the current momentum or trend direction relative to a moving average. By observing this indicator, users can better understand whether the price is currently pushing ahead of its historical average or falling behind it.
Core Logic and Functionality
The script operates by calculating the relationship between the current market price and a specific smoothed average (the Exponential Moving Average). Here is a breakdown of how that logic works:
- Trend Identification: The tool uses a user-defined period to smooth out market "noise." By calculating an average price over this timeframe, the script establishes a baseline for what the "normal" price behavior should look like.
- Relative Deviation Calculation: Instead of just showing the price or the average alone, the logic calculates the percentage difference between the two. It takes the current closing price, compares it to the moving average, and determines how far the price has deviated from that baseline.
- Visual Representation: The resulting data is displayed in a separate window below your main trading chart. Depending on your preference, this data can be viewed as either a continuous line or a histogram (a series of vertical bars).
- When the values are above zero, it indicates that the price is currently performing stronger than its recent average.
- When the values dip below zero, it suggests the price is weakening relative to its average.
Key Features for the User
- Customizable Sensitivity: You can adjust the "Maperiod" to change how many previous candles the script takes into account. A smaller period makes the indicator more responsive to quick price changes, while a larger period provides a smoother, broader view of the trend.
- Visual Toggle: The script allows you to switch between a histogram and a line view, letting you choose the visual style that best fits your trading environment.
- Clean Interpretation: By focusing on the deviation rather than raw price numbers, this tool helps strip away distractions, allowing you to focus solely on whether the market's current momentum is leaning bullish or bearish.
//+------------------------------------------------------------------+
//| bias.mq4 |
//| Copyright ?2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 SlateGray
#property indicator_width1 2
//---- input parameters
extern int MAPeriod=9;
extern bool drawHisto = true; //histi/line switch
//---- buffers
double ind_buffer[];
double BiasBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);
SetIndexBuffer(0, BiasBuffer);
SetIndexBuffer(1, ind_buffer);
//---- indicators
int draw;
if (drawHisto)draw = DRAW_HISTOGRAM; else draw = DRAW_LINE;
SetIndexStyle(0,draw);
SetIndexBuffer(0,BiasBuffer);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("BIAS ("+MAPeriod+")");
SetIndexLabel(0,"BIAS");
//----
SetIndexDrawBegin(0,MAPeriod);
return(0);
//----
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int i;
//----
if(Bars<=MAPeriod) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=MAPeriod;i++) BiasBuffer[Bars-i]=0.0;
//----
i=Bars-MAPeriod-1;
if(counted_bars>=MAPeriod) i=Bars-counted_bars-1;
while(i>=0)
{ind_buffer[i]=iMA(NULL,0,MAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
BiasBuffer[i]=(Close[i]-ind_buffer[i])/Close[i];
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments