TrendEMA_V_1_001
Download scriptThis script is designed to provide traders with a clear, real-time visual summary of market trends and specific moving average values directly on their trading charts. Instead of requiring the user to manually interpret multiple lines or calculate values, it automates the identification of market direction and displays the data in an organized text format at a chosen corner of the screen.
Core Functionality
The logic operates by calculating three different types of Exponential Moving Averages (EMA) simultaneously. These represent different time horizons:
- Large EMA: Captures the long-term trend.
- Medium EMA: Captures the intermediate trend.
- Low EMA: Captures the short-term price action.
Trend Detection Logic
The script continuously monitors the relationship between these three averages to determine the current market state. It categorizes the market into three distinct phases:
- UpTrend: Identified when the values are stacked in an ascending order (Large < Medium < Low). When this occurs, the script displays an "UpTrend" label in Spring Green.
- DownTrend: Identified when the values are stacked in a descending order (Large > Medium > Low). When this occurs, the script displays a "DownTrend" label in Crimson.
- Sideways: If the averages do not fall into a clear ascending or descending sequence, the script identifies the market as "Sideways" and displays the label in Gold.
Visual Display & User Customization
Rather than just placing lines on a chart, this tool creates a clean text dashboard. It provides:
- Dynamic Data: It shows the exact numerical value of each EMA (Large, Medium, and Low) in real-time.
- Positioning: Users can choose which corner of the chart (e.g., top right, bottom left) the information should appear in.
- Timing: It allows users to choose whether to view the data for the current active candle or from previous bars.
- Readability: The tool includes customizable settings for font size and styling to ensure the data is easily readable regardless of the chart's complexity.
In summary, this script acts as a visual "dashboard," translating complex mathematical moving averages into simple color-coded trend labels and live price values for faster decision-making.
//+------------------------------------------------------------------+
//| 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 = 0; // 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
//--------------------------
int Fonts = 9;
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()
{
//----
//----
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, 60); //
//---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, 45); // 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 Black",Crimson);
ObjectSetText("Lma","Large EMA = "+DoubleToStr(Lma,5),Fonts,"Arial Bold",White);
ObjectSetText("Mma","Medium EMA = "+DoubleToStr(Mma,5),Fonts,"Arial Bold",White);
ObjectSetText("Nma","Low EMA = "+DoubleToStr(Nma,5),Fonts,"Arial Bold",White);
//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, 60);
ObjectCreate("Lma", OBJ_LABEL, 0, 0, 0);
ObjectSet("Lma", OBJPROP_CORNER,DisplayCorner);
ObjectSet("Lma", OBJPROP_XDISTANCE, 10);
ObjectSet("Lma", OBJPROP_YDISTANCE, 45); //
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 Black",SpringGreen);
ObjectSetText("Lma","Large EMA = "+DoubleToStr(Lma,5),Fonts,"Arial Bold",White);
ObjectSetText("Mma","Medium EMA = "+DoubleToStr(Mma,5),Fonts,"Arial Bold",White);
ObjectSetText("Nma","Low EMA = "+DoubleToStr(Nma,5),Fonts,"Arial Bold",White);
//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, 60);
ObjectCreate("Lma", OBJ_LABEL, 0, 0, 0);
ObjectSet("Lma", OBJPROP_CORNER,DisplayCorner);
ObjectSet("Lma", OBJPROP_XDISTANCE, 10);
ObjectSet("Lma", OBJPROP_YDISTANCE, 45);
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 Black",Gold);
ObjectSetText("Lma","Large EMA = "+DoubleToStr(Lma,5),Fonts,"Arial Bold",White);
ObjectSetText("Mma","Medium EMA = "+DoubleToStr(Mma,5),Fonts,"Arial Bold",White);
ObjectSetText("Nma","Low EMA = "+DoubleToStr(Nma,5),Fonts,"Arial Bold",White);
ObjectDelete("Nma-Trend");
ObjectDelete("Lma-Trend");
//ObjectDelete("Mma-Trend");
}
return(0);
}
//+---------------------End Of Code---------------------------------------------+
Comments