MACD+OsMA+BB
Download scriptThis custom trading indicator is designed to provide a comprehensive visual overview of market momentum and volatility by combining three distinct technical analysis tools: the MACD (Moving Average Convergence Divergence), OsMA (Oscillating Moving Average), and Bollinger Bands.
The primary logic of the script functions as follows:
Core Components
- MACD & Signal Integration: The indicator tracks the relationship between fast and slow moving averages to determine the overall direction of price momentum. It specifically highlights the "Signal" line to help identify potential turning points.
- OsMA Dynamics: The script incorporates the Oscillating Moving Average, which serves as a visual representation of the MACD's histogram. This allows traders to see the speed and strength of the current trend more clearly than by looking at simple averages alone.
- Bollinger Bands: By incorporating Bollinger Bands, the indicator adds a layer of volatility analysis. It calculates upper and lower boundaries based on standard deviations, helping users identify "overbought" or "oversold" conditions relative to the moving average center.
Visual Logic & Execution
The script processes market data to create several distinct visual elements:
- Trend Direction (Histogram): The indicator uses a conditional logic system to color-code the momentum. It compares current and previous price values to determine if the trend is moving upward or downward. If the momentum shifts, the script dynamically assigns values to "Up" and "Down" buffers, which are then displayed as histograms. This helps traders instantly see where a trend is gaining strength versus where it is losing steam.
- Momentum Tracking: The OsMA component is split into positive and negative components. By comparing the current value of the oscillating average against its previous value, the script determines whether to plot a "positive" or "negative" momentum bar, effectively creating a visual map of price velocity.
- Volatility Envelopes: The indicator calculates the upper, lower, and middle bands of the Bollinger system. These are plotted to provide a "container" for the price action, allowing the user to see how far the current market activity is stretching away from the mean.
Summary for the User
In essence, this script doesn't just tell you what the price is doing; it tells you how fast it is moving and how much volatility is surrounding that movement. By blending the MACD's trend-following capabilities with the OsMA's momentum visualization and the Bollinger Bands' volatility limits, the indicator provides a multi-layered perspective on market behavior in a single window.
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
//| MACD+OsMA+BB_MOD.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
#property copyright ""
#property link ""
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Lime
#property indicator_color5 Red
#property indicator_color6 Peru
#property indicator_color7 Peru
#property indicator_color8 Yellow
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
extern int BollingerPeriod=21;
extern int BollingerDeviation=2;
extern int BollingerShift=0;
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
double redBuffer[];
double blueBuffer[];
double blueBorder[];
double ind_buffer4[];
double ind_buffer5[];
double bandsUpper[];
double bandsLower[];
double bandsMiddle[];
int i;
double osma1,
osma2,
fast,
slow1,
slow2;
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
int init()
{
IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(6,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(7,DRAW_LINE,STYLE_DOT,1);
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
SetIndexDrawBegin(0,SignalSMA);
SetIndexDrawBegin(1,SignalSMA);
SetIndexDrawBegin(2,SignalSMA);
SetIndexDrawBegin(3,SignalSMA);
SetIndexDrawBegin(4,SignalSMA);
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
SetIndexBuffer(0,redBuffer);
SetIndexBuffer(1,blueBuffer);
SetIndexBuffer(2,blueBorder);
SetIndexBuffer(3,ind_buffer4);
SetIndexBuffer(4,ind_buffer5);
SetIndexBuffer(5,bandsUpper);
SetIndexBuffer(6,bandsLower);
SetIndexBuffer(7,bandsMiddle);
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
SetIndexLabel(2,"OsMA");
SetIndexLabel(3,"OsMAup");
SetIndexLabel(4,"OsMAdown");
SetIndexLabel(5,"bandsUpper");
SetIndexLabel(6,"bandsLower");
SetIndexLabel(7,"bandsMiddle");
return(0);
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
int start()
{
int limit,
counted_bars=IndicatorCounted();
if(counted_bars>0)
counted_bars--;
limit=Bars-counted_bars-1;
for(i=0;i<limit;i++)
redBuffer[i]=iCustom(NULL,0,"macdHelp",FastEMA,SlowEMA,SignalSMA,BollingerPeriod,BollingerDeviation,BollingerShift,3,i);
for(i=0;i<limit;i++)
{
blueBuffer[i]=iCustom(NULL,0,"macdHelp",FastEMA,SlowEMA,SignalSMA,BollingerPeriod,BollingerDeviation,BollingerShift,4,i);
}
for(i=0;i<limit;i++)
{
osma1=iCustom(NULL,0,"macdHelp",FastEMA,SlowEMA,SignalSMA,BollingerPeriod,BollingerDeviation,BollingerShift,0,i);
osma2=iCustom(NULL,0,"macdHelp",FastEMA,SlowEMA,SignalSMA,BollingerPeriod,BollingerDeviation,BollingerShift,0,i+1);
fast=iCustom(NULL,0,"macdHelp",FastEMA,SlowEMA,SignalSMA,BollingerPeriod,BollingerDeviation,BollingerShift,3,i);
slow1=iCustom(NULL,0,"macdHelp",FastEMA,SlowEMA,SignalSMA,BollingerPeriod,BollingerDeviation,BollingerShift,4,i);
redBuffer[i]=slow1;
blueBuffer[i]=slow1;
if(i>0)
{
slow2=iCustom(NULL,0,"macdHelp",FastEMA,SlowEMA,SignalSMA,BollingerPeriod,BollingerDeviation,BollingerShift,4,i-1);
if(fast<slow1)
{
redBuffer[i]=0.0;
blueBuffer[i-1]=slow2;
}
else
{
redBuffer[i-1]=slow2;
blueBuffer[i]=0.0;
}
}
if(osma1>osma2)
ind_buffer4[i]=osma1;
else
ind_buffer4[i]=0.0;
if(osma1<osma2)
ind_buffer5[i]=osma1;
else
ind_buffer5[i]=0.0;
blueBorder[i]=osma1;
bandsUpper[i]=iCustom(NULL,0,"macdHelp",FastEMA,SlowEMA,SignalSMA,BollingerPeriod,BollingerDeviation,BollingerShift,1,i);
bandsLower[i]=iCustom(NULL,0,"macdHelp",FastEMA,SlowEMA,SignalSMA,BollingerPeriod,BollingerDeviation,BollingerShift,2,i);
bandsMiddle[i]=(bandsUpper[i]+bandsLower[i])/2.0;
}
return(0);
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
Comments