mqcodes_v1
Download scriptThis custom technical indicator is designed to provide traders with a multi-layered view of market momentum and trend direction by combining three distinct mathematical models into a single visual tool. Instead of relying on just one type of data, it overlays different calculation methods to help identify where the price is heading and how fast it is moving.
Core Components of the Logic
The indicator operates by calculating three specific data points simultaneously:
- The MACD Line: The primary engine of this tool compares two different types of moving averages—one "fast" and one "slow." By measuring the distance between these two averages, the tool shows the strength of the current trend. When the gap widens, it indicates increasing momentum; when it narrows, it suggests the trend may be losing steam.
- The Signal Line: This component takes the data from the MACD line and applies a smoothing filter to it. Think of this as a "trend of a trend." It helps filter out minor market noise, allowing you to see the broader direction of the momentum more clearly. It is primarily used to identify potential turning points where the main momentum shifts direction.
- The OsMA (Oscillator of Moving Averages): This adds an extra layer of depth by calculating the differences between moving averages as a histogram. While the MACD lines show the current relationship between prices, the OsMA helps visualize the velocity and "volume" of those movements over time, providing a more comprehensive picture of market dynamics.
How it Works Together
The logic follows a sequential flow:
- It first determines the gap between short-term and long-term price trends to create the base momentum.
- It then smooths that momentum to create a "Signal" for easier interpretation.
- Finally, it calculates an oscillator to highlight the underlying changes in those averages.
By viewing these three elements together, the indicator allows you to see not just where the price is going, but the intensity and reliability of that movement. This provides a more nuanced perspective than using any of these tools individually, helping to distinguish between minor price fluctuations and significant trend shifts.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//compile//------------------------------------------------------------------+
//| 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