TrendEMA - Display Trend And MA Values
Download scriptThis script is designed to act as a visual navigation tool for traders using MetaTrader 4. Its primary purpose is to simplify market analysis by automatically identifying the current trend and displaying key technical data directly on your trading chart in real-time.
Core Functionality
The logic operates by monitoring three different Exponential Moving Averages (EMAs) simultaneously. Each EMA represents a different timeframe of price action:
- Large EMA: Represents long-term price trends.
- Medium EMA: Represents intermediate price movements.
- Low EMA: Represents short-term, immediate price fluctuations.
By comparing the values of these three averages against one another, the script categorizes the market into one of three distinct states:
1. UpTrend Detection
The script identifies an "UpTrend" when the moving averages are stacked in a specific ascending order (where the Long-term value is lower than the Medium-term, which is lower than the Short-term). When this occurs, the visual display on your chart updates to show an UpTrend status in green.
2. DownTrend Detection
Conversely, the script identifies a "DownTrend" when the averages are stacked in descending order (where the Long-term value is higher than the Medium-term, which is higher than the Short-term). In this scenario, the visual display updates to show a DownTrend status in crimson red.
3. Sideways (Neutral) Detection
If the price action does not clearly fit into an ascending or descending sequence—meaning the moving averages are intertwined or flat—the script classifies the market as "Sideways." The display will reflect this status in gold.
Visual and User Experience Features
Beyond just identifying trends, the script provides several user-friendly features to improve chart clarity:
- Dynamic On-Screen Dashboard: Instead of making you look at complex lines on a crowded chart, the script creates a clean text dashboard in a corner of your screen (customizable by the user).
- Real-Time Data Feed: The dashboard constantly updates to show the exact numerical values of all three EMAs. This allows for quick reference without having to hover over specific price points.
- Customizable Aesthetics: Users can personalize the display based on their preference, including:
- Font Size: Adjusting how large the text appears.
- Display Corner: Choosing which corner of the chart the information appears in.
- Data Point Selection: Choosing whether to view the data for the current live candle or a previous historical bar.
- Automatic Cleanup: The script includes "deinitialization" logic, which ensures that when you remove the indicator from your chart, it automatically deletes all temporary text objects, leaving your chart clean and uncluttered.
//+------------------------------------------------------------------+
//| TrendEMA - Display Trend And MA Values.mq4 |
//| Original Name TrendEMA.mq4 |
//| FxPars |
//| Original Source http://www.fxpars.com |
//+------------------------------------------------------------------+
#property copyright "FxPars"
#property link "http://www.fxpars.com"
#property indicator_chart_window
//---Display Trend and MA Values At User Select Corner - Added by Robert - 7/21/2010
//---Added User Select Font Size (Fontz) And Select Bar (Barz)For Current Or Past Bars
//---Changed hard coded MA TF from Period_H1 to "0" default current chart TF
//---Save As : TrendEMA - Display Trend And MA Values - 7/21/2010
//---Variables
extern int LargeEMA = 100;
extern int MediumEMA = 10;
extern int LowEMA = 5;
//---Added for User Comfort Settings
extern int Fontz = 12; // Font size 12 default
extern int DisplayCorner = 3; // Added for corner to display - default 3 bottom right
extern int Barz = 0; // Added to select MA current bar or previous bars : 0 = Current Bar Default
//--------------------------
double Lma = 0;
double Mma = 0;
double Nma = 0;
double pp = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("Lma-Trend");
ObjectDelete("Mma-Trend");
ObjectDelete("Nma-Trend");
ObjectDelete("Lma");
ObjectDelete("Mma");
ObjectDelete("Nma");
Comment("");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- Changed from hard code PERIOD_H1 to "0" default chart TF
Lma=iMA(NULL,0,LargeEMA,0,MODE_EMA,PRICE_CLOSE,Barz);
Mma=iMA(NULL,0,MediumEMA,0,MODE_EMA,PRICE_CLOSE,Barz);
Nma=iMA(NULL,0,LowEMA,0,MODE_EMA,PRICE_CLOSE,Barz);
//----
if (Lma>Mma && Mma>Nma) // DownTrend
{
Comment("\n * DownTrend * " + "\n LargeEMA= " + Lma + "\n MediumEMA= " + Mma + "\n LowEMA= " + Nma);
//---Try Trend only on top - start
ObjectCreate("Nma-Trend", OBJ_LABEL, 0, 0, 0);
ObjectSet("Nma-Trend", OBJPROP_CORNER,DisplayCorner); //
ObjectSet("Nma-Trend", OBJPROP_XDISTANCE, 10); //
ObjectSet("Nma-Trend", OBJPROP_YDISTANCE, 70); //
//---Try Trend only on top - end
ObjectCreate("Lma", OBJ_LABEL, 0, 0, 0);
ObjectSet("Lma", OBJPROP_CORNER,DisplayCorner); // Extern User setting
ObjectSet("Lma", OBJPROP_XDISTANCE, 10); // Adjust this for side to side display
ObjectSet("Lma", OBJPROP_YDISTANCE, 50); // Adjust this for up and down display
ObjectCreate("Mma", OBJ_LABEL, 0, 0, 0);
ObjectSet("Mma", OBJPROP_CORNER,DisplayCorner);
ObjectSet("Mma", OBJPROP_XDISTANCE, 10);
ObjectSet("Mma", OBJPROP_YDISTANCE, 30);
ObjectCreate("Nma", OBJ_LABEL, 0, 0, 0);
ObjectSet("Nma", OBJPROP_CORNER,DisplayCorner);
ObjectSet("Nma", OBJPROP_XDISTANCE, 10);
ObjectSet("Nma", OBJPROP_YDISTANCE, 15);
ObjectSetText("Nma-Trend","DownTrend ",Fontz,"Arial Bold",Crimson);
ObjectSetText("Lma","Large EMA = "+DoubleToStr(Lma,5),Fontz,"Arial Bold",SpringGreen);
ObjectSetText("Mma","Medium EMA = "+DoubleToStr(Mma,5),Fontz,"Arial Bold",Gold);
ObjectSetText("Nma","Low EMA = "+DoubleToStr(Nma,5),Fontz,"Arial Bold",Crimson);
//ObjectDelete("Nma-Trend");
ObjectDelete("Lma-Trend");
ObjectDelete("Mma-Trend");
}
//------------------------------------
else if (Lma<Mma && Mma<Nma) // UpTrend
{
Comment("\n * UpTrend * " + "\n LargeEMA= " + Lma + "\n MediumEMA= " + Mma + "\n LowEMA= " + Nma);
//---Trend on top
ObjectCreate("Lma-Trend", OBJ_LABEL, 0, 0, 0);
ObjectSet("Lma-Trend", OBJPROP_CORNER,DisplayCorner);
ObjectSet("Lma-Trend", OBJPROP_XDISTANCE, 20);
ObjectSet("Lma-Trend", OBJPROP_YDISTANCE, 70);
ObjectCreate("Lma", OBJ_LABEL, 0, 0, 0);
ObjectSet("Lma", OBJPROP_CORNER,DisplayCorner);
ObjectSet("Lma", OBJPROP_XDISTANCE, 10);
ObjectSet("Lma", OBJPROP_YDISTANCE, 50); //
ObjectCreate("Mma", OBJ_LABEL, 0, 0, 0);
ObjectSet("Mma", OBJPROP_CORNER,DisplayCorner);
ObjectSet("Mma", OBJPROP_XDISTANCE, 10);
ObjectSet("Mma", OBJPROP_YDISTANCE, 30);
ObjectCreate("Nma", OBJ_LABEL, 0, 0, 0);
ObjectSet("Nma", OBJPROP_CORNER,DisplayCorner);
ObjectSet("Nma", OBJPROP_XDISTANCE, 10);
ObjectSet("Nma", OBJPROP_YDISTANCE, 15);
ObjectSetText("Lma-Trend","UpTrend ",Fontz,"Arial Bold",SpringGreen);
ObjectSetText("Lma","Large EMA = "+DoubleToStr(Lma,5),Fontz,"Arial Bold",SpringGreen);
ObjectSetText("Mma","Medium EMA = "+DoubleToStr(Mma,5),Fontz,"Arial Bold",Gold);
ObjectSetText("Nma","Low EMA = "+DoubleToStr(Nma,5),Fontz,"Arial Bold",Crimson);
//ObjectDelete("Lma-Trend");
ObjectDelete("Mma-Trend");
ObjectDelete("Nma-Trend");
}
//-------------------------------------
else // Sideways
{
Comment("\n * Sideway * " + "\n LargeEMA= " + Lma + "\n MediumEMA= " + Mma + "\n LowEMA= " + Nma);
//---Trend on top
ObjectCreate("Mma-Trend", OBJ_LABEL, 0, 0, 0);
ObjectSet("Mma-Trend", OBJPROP_CORNER,DisplayCorner);
ObjectSet("Mma-Trend", OBJPROP_XDISTANCE, 30);
ObjectSet("Mma-Trend", OBJPROP_YDISTANCE, 70);
ObjectCreate("Lma", OBJ_LABEL, 0, 0, 0);
ObjectSet("Lma", OBJPROP_CORNER,DisplayCorner);
ObjectSet("Lma", OBJPROP_XDISTANCE, 10);
ObjectSet("Lma", OBJPROP_YDISTANCE, 50);
ObjectCreate("Mma", OBJ_LABEL, 0, 0, 0);
ObjectSet("Mma", OBJPROP_CORNER,DisplayCorner);
ObjectSet("Mma", OBJPROP_XDISTANCE, 10);
ObjectSet("Mma", OBJPROP_YDISTANCE, 30);
ObjectCreate("Nma", OBJ_LABEL, 0, 0, 0);
ObjectSet("Nma", OBJPROP_CORNER,DisplayCorner);
ObjectSet("Nma", OBJPROP_XDISTANCE, 10);
ObjectSet("Nma", OBJPROP_YDISTANCE, 15);
ObjectSetText("Mma-Trend","Sideways ",Fontz,"Arial Bold",Gold);
ObjectSetText("Lma","Large EMA = "+DoubleToStr(Lma,5),Fontz,"Arial Bold",SpringGreen);
ObjectSetText("Mma","Medium EMA = "+DoubleToStr(Mma,5),Fontz,"Arial Bold",Gold);
ObjectSetText("Nma","Low EMA = "+DoubleToStr(Nma,5),Fontz,"Arial Bold",Crimson);
ObjectDelete("Nma-Trend");
ObjectDelete("Lma-Trend");
//ObjectDelete("Mma-Trend");
}
return(0);
}
//+---------------------End Of Code---------------------------------------------+
Comments