EMAAngleZero_v1
Download scriptThis tool is designed to help traders visualize the momentum and "steepness" of an Exponential Moving Average (EMA) by calculating its slope. Rather than just looking at the price level of a moving average, this indicator measures how sharply that average is rising or falling at any given moment.
How it Works
The logic functions by comparing two different points on the same EMA line simultaneously:
- The Current Point: It identifies the current position of the EMA.
- The Historical Point: It looks back a specific number of bars (defined by your settings) to find an earlier point on that same EMA line.
By calculating the difference between these two points, the script determines the "angle" or trajectory of the trend.
Visual Interpretation
The indicator provides clear visual feedback through a three-color system displayed in a separate window:
- Green (Upward Trend): When the moving average is rising with a steepness that exceeds your defined threshold, the indicator highlights this as positive momentum.
- Red (Downward Trend): When the moving average is falling significantly enough to cross your downward threshold, it signals strong negative momentum.
- Yellow (Neutral/Flat Zone): This is the most distinct feature of the tool. If the angle of the EMA is very small—meaning the trend is "flat" or "sideways"—the indicator marks it in yellow. This helps traders identify periods of consolidation where the market is lacking a clear direction.
Key Customization Features
- EMA Period: You can choose how many bars are used to calculate the moving average (e.g., looking at a short-term trend vs. a long-term trend).
- Angle Threshold: This allows you to define what "flat" means to you. You can set how sensitive the indicator is when deciding whether the EMA is moving enough to be considered a trend or if it should be marked as neutral (Yellow).
- Shift Settings: These determine the distance between the two points used for the calculation. A larger shift allows you to see the broader slope of the trend, while a smaller shift focuses on immediate, short-term changes in direction.
In summary, this tool simplifies market analysis by stripping away price noise and highlighting exactly when a trend is gaining strength, losing steam, or moving into a period of indecision.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| EMAAngle.mq4 |
//| jpkfox |
//| |
//| You can use this indicator to measure when the EMA angle is |
//| "near zero". AngleTreshold determines when the angle for the |
//| EMA is "about zero": This is when the value is between |
//| [-AngleTreshold, AngleTreshold] (or when the histogram is red). |
//| EMAPeriod: EMA period |
//| AngleTreshold: The angle value is "about zero" when it is |
//| between the values [-AngleTreshold, AngleTreshold]. |
//| StartEMAShift: The starting point to calculate the |
//| angle. This is a shift value to the left from the |
//| observation point. Should be StartEMAShift > EndEMAShift. |
//| StartEMAShift: The ending point to calculate the |
//| angle. This is a shift value to the left from the |
//| observation point. Should be StartEMAShift > EndEMAShift. |
//| |
//| Modified by MrPip |
//| Red for down |
//| Yellow for near zero |
//| Green for up |
//| 10/15/05 MrPip |
//| Corrected problem with USDJPY and optimized code |
//| |
//+------------------------------------------------------------------+
#property copyright "jpkfox"
#property link "http://www.strategybuilderfx.com/forums/showthread.php?t=15274&page=1&pp=8"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 LimeGreen
#property indicator_color2 FireBrick
#property indicator_color3 Yellow
//---- indicator parameters
extern int EMAPeriod=34;
extern double AngleTreshold=0.2;
extern int StartEMAShift=6;
extern int EndEMAShift=0;
//---- indicator buffers
double UpBuffer[];
double DownBuffer[];
double ZeroBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(3);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 3 indicator buffers mapping
if(!SetIndexBuffer(0,UpBuffer) &&
!SetIndexBuffer(1,DownBuffer) &&
!SetIndexBuffer(2,ZeroBuffer))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("EMAAngleZero("+EMAPeriod+","+AngleTreshold+","+StartEMAShift+","+EndEMAShift+")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| The angle for EMA |
//+------------------------------------------------------------------+
int start()
{
double fEndMA, fStartMA;
double fAngle, mFactor, dFactor;
int nLimit, i;
int nCountedBars;
double angle;
int ShiftDif;
if(EndEMAShift >= StartEMAShift)
{
Print("Error: EndEMAShift >= StartEMAShift");
StartEMAShift = 6;
EndEMAShift = 0;
}
nCountedBars = IndicatorCounted();
//---- check for possible errors
if(nCountedBars<0)
return(-1);
//---- last counted bar will be recounted
if(nCountedBars>0)
nCountedBars--;
nLimit = Bars-nCountedBars;
dFactor = 3.14159/180.0;
mFactor = 10000.0;
if (Symbol() == "USDJPY") mFactor = 100.0;
ShiftDif = StartEMAShift-EndEMAShift;
mFactor /= ShiftDif;
//---- main loop
for(i=0; i<nLimit; i++)
{
fEndMA=iMA(NULL,0,EMAPeriod,0,MODE_EMA,PRICE_MEDIAN,i+EndEMAShift);
fStartMA=iMA(NULL,0,EMAPeriod,0,MODE_EMA,PRICE_MEDIAN,i+StartEMAShift);
// 10000.0 : Multiply by 10000 so that the fAngle is not too small
// for the indicator Window.
fAngle = mFactor * (fEndMA - fStartMA);
// fAngle = MathArctan(fAngle)/dFactor;
DownBuffer[i] = 0.0;
UpBuffer[i] = 0.0;
ZeroBuffer[i] = 0.0;
if(fAngle > AngleTreshold)
UpBuffer[i] = fAngle;
else if (fAngle < -AngleTreshold)
DownBuffer[i] = fAngle;
else ZeroBuffer[i] = fAngle;
}
return(0);
}
//+------------------------------------------------------------------+
Comments