SARMACD_v2
Download scriptThis custom indicator is designed to streamline the analysis of market momentum by combining two well-known technical analysis tools into a single visual signaling system. Instead of requiring a trader to monitor multiple separate charts or data streams, this script automates the comparison between different trend indicators to identify specific entry points.
How the Logic Works
The tool operates by evaluating the relationship between "Fast" and "Slow" price averages to determine market momentum, while simultaneously tracking the volatility and direction of price movements.
1. Momentum Analysis (MACD Component) The script looks at the Moving Averages Convergence Divergence (MACD). It calculates the difference between a fast-moving average (representing recent price action) and a slow-moving average (representing long-term trends). By comparing these to a "Signal" line, the tool identifies whether the market momentum is accelerating, decelerating, or shifting direction.
2. Volatility Tracking (Parabolic SAR Component) In addition to momentum, the script incorporates a "Stop and Reverse" (SAR) logic. This part of the calculation acts as a dynamic filter that monitors whether the current price is trending above or below a specific volatility threshold. It helps ensure that the signals are not just based on temporary momentum but also align with the broader price structure.
3. The Convergence Signal The core intelligence of this script lies in its "Agreement" logic. Rather than providing a signal every time the momentum shifts, the tool waits for both the MACD and the SAR components to agree simultaneously:
- Buy Signals: These appear when the momentum data indicates a shift toward an upward trend and the volatility filter confirms that the price is breaking out in the positive direction. The script then places a blue upward arrow on the chart.
- Sell Signals: These appear when both indicators align to suggest downward pressure, marking a potential reversal or continuation of a downtrend. The script then places a red downward arrow on the chart.
Summary for the User
In simple terms, this tool acts as a double-filter. It filters out "noise" by ensuring that you only see a visual signal when two different mathematical approaches to the market—one focused on speed/momentum and one focused on trend direction—point toward the same conclusion at the exact same time. This provides a cleaner chart and helps in identifying potential turning points with higher statistical confidence.
//+------------------------------------------------------------------+
//| Custom MACD.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_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalEMA=9;
//---- indicator buffers
double TriggerUP[];
double TriggerDN[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW,EMPTY,3,Blue);
SetIndexArrow(0,SYMBOL_ARROWUP);
SetIndexStyle(1,DRAW_ARROW,EMPTY,3,Red);
SetIndexArrow(1,SYMBOL_ARROWDOWN);
SetIndexBuffer(0,TriggerUP);
SetIndexBuffer(1,TriggerDN);
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int i,MACDTrigger,SARTrigger,counted_bars=IndicatorCounted();
double MACDHistCur,MACDHistPrev,Signal,MACD;
double alpha = 2.0 / (SignalEMA + 1.0);
double alpha_1 = 1.0 - alpha;
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
i=Bars-counted_bars;
while(i>0)
{
MACD=iMACD(NULL,0,FastEMA,SlowEMA,SignalEMA,PRICE_CLOSE,MODE_MAIN,i);
Signal=iMACD(NULL,0,FastEMA,SlowEMA,SignalEMA,PRICE_CLOSE,MODE_SIGNAL,i);
MACDHistPrev=MACDHistCur;
MACDHistCur=MACD-Signal;
if((MACDHistCur*MACDHistPrev)<0.0) MACDTrigger=((MACDHistCur<0.0)+1);
SARTrigger=((iSAR(NULL,0,0.02,0.2,i)>Close[i])+1);
if(MACDTrigger==SARTrigger)
{
if(MACDTrigger==1) TriggerUP[i]=(High[i]-Low[i])/2+Low[i]+Point*10;
if(MACDTrigger==2) TriggerDN[i]=(Low[i]-Low[i])/2+Low[i]-Point*10;
MACDTrigger=0;
SARTrigger=0;
}
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments