This tool is designed to help traders identify the primary direction of the market by analyzing price momentum through three different layers of "Exponential Moving Averages" (EMAs). By comparing these three averages, the script simplifies complex price action into three distinct market conditions: UpTrend, DownTrend, or Sideway.
How it Works
The logic relies on three specific timeframes of data (Large, Medium, and Low) to create a visual hierarchy of price trends:
- The Large EMA: Acts as the long-term anchor, representing the broader market direction over a significant period.
- The Medium EMA: Tracks the mid-range momentum, showing how the price is behaving relative to the long-term trend.
- The Low EMA: Represents short-term price movement, capturing immediate fluctuations.
Market Analysis Logic
The script continuously monitors the relationship between these three values on the hourly chart to determine the current market state:
1. UpTrend Identification When the shortest moving average is higher than the medium one, and the medium one is higher than the longest one (Low > Medium > Large), the script identifies an UpTrend. This suggests that short-term momentum is pushing prices upward faster than the long-term average, indicating bullish strength.
2. DownTrend Identification Conversely, when the shortest moving average is lower than the medium one, and the medium one is lower than the longest one (Low < Medium < Large), the script identifies a DownTrend. This indicates that short-term momentum is dropping rapidly compared to the broader market movement, suggesting bearish pressure.
3. Sideway Market Identification If the moving averages are mixed—meaning they are neither perfectly stacked in ascending nor descending order—the script identifies the market as Sideway. This suggests a period of consolidation or "choppy" price action where there is no clear dominant direction, signaling to the trader that it may be best to avoid aggressive trend-following positions.
User Experience
Instead of requiring the trader to manually calculate these values, the script automatically performs this calculation in the background and displays the current status directly on the chart's comment area. It provides a clear, real-time text summary of the trend along with the specific numerical values for each of the three moving averages.
//+------------------------------------------------------------------+
//| TrendEMA.mq4 |
//| FxPars |
//| http://www.fxpars.com |
//+------------------------------------------------------------------+
#property copyright "FxPars"
#property link "http://www.fxpars.com"
#property indicator_chart_window
extern int LargeEMA=100;
extern int MediumEMA=10;
extern int LowEMA=5;
double Lma=0;
double Mma=0;
double Nma=0;
double pp=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
Lma=iMA(NULL,PERIOD_H1,LargeEMA,0,MODE_EMA,PRICE_CLOSE,1);
Mma=iMA(NULL,PERIOD_H1,MediumEMA,0,MODE_EMA,PRICE_CLOSE,1);
Nma=iMA(NULL,PERIOD_H1,LowEMA,0,MODE_EMA,PRICE_CLOSE,1);
if (Lma>Mma && Mma>Nma) {
Comment("DownTrend " + "\nLargeEMA= " + Lma + "\nMediumEMA= " + Mma + "\nLowEMA= " + Nma);
} else if (Lma<Mma && Mma<Nma) {
Comment("UpTrend " + "\nLargeEMA= " + Lma + "\nMediumEMA= " + Mma + "\nLowEMA= " + Nma);
} else {
Comment("Sideway " + "\nLargeEMA= " + Lma + "\nMediumEMA= " + Mma + "\nLowEMA= " + Nma);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments