MACD+OsMA
Download scriptThis custom trading tool is designed to provide a multi-layered analysis of market momentum and price trends by combining three distinct technical indicators into a single visual display. Instead of relying on a single metric, it synthesizes data to help traders identify the speed, direction, and strength of price movements more clearly.
Core Functionality
The script works by calculating three specific data points simultaneously:
- Trend Differentiation (MACD): The tool first calculates the difference between two different types of moving averages—one that reacts quickly to recent price changes and one that follows the broader trend more slowly. By subtracting the slow average from the fast average, it highlights whether the market is gaining momentum or losing steam.
- Signal Smoothing: To filter out "noise" (minor, insignificant price fluctuations), the tool takes the results of the first calculation and applies a secondary smoothing process. This creates a "signal line," which helps traders distinguish between temporary price blips and sustained trend shifts.
- Oscillation Analysis (OsMA): Finally, the script incorporates an Oscillating Moving Average. This provides a visual representation of the momentum's strength, appearing as a histogram. It allows you to see at a glance whether the current trend is accelerating or decelerating.
How it Works for the User
When applied to a trading chart, the script opens a separate window below your main price graph. Rather than showing you just one line, it provides a comprehensive view of market health:
- The Main Line: Represents the primary MACD value, showing the gap between short-term and long-term price actions.
- The Signal Line: Acts as a guide for the main line; when the main line crosses above or below this signal, it often suggests a potential change in market direction.
- The Histogram: Provides a visual "weight" to the momentum. It helps you see the magnitude of the move, making it easier to judge if a trend is becoming exhausted or is gaining significant power.
By combining these three elements into one interface, the script allows you to observe the relationship between price speed and historical averages in a unified way, aimed at providing a clearer picture of market behavior than any single indicator could offer alone.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| Custom MACD+OsMA.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Silver
#property indicator_color2 Red
#property indicator_color3 Silver
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexDrawBegin(1,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2) && !SetIndexBuffer(2,ind_buffer3))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
SetIndexLabel(2,"OsMA");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
ind_buffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA,i);
for(i=0; i<limit; i++)
ind_buffer3[i]=iOsMA(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,i);
//---- done
return(0);
}
Comments