TrendEMA_V_1

Download script
Author: FxPars
TrendEMA_V_1

This script is designed to act as a visual dashboard for traders, providing real-time information about the current market trend and specific moving average values directly on the trading chart. Instead of cluttering the screen with multiple lines, it consolidates this data into a clean, readable text display in a corner of your choice.

How the Logic Works

The script functions by monitoring three different Exponential Moving Averages (EMAs) simultaneously. These represent three different "speeds" of price history:

  • Large EMA: Captures long-term trends.
  • Medium EMA: Tracks intermediate price movements.
  • Low EMA: Reacts quickly to short-term price fluctuations.

By comparing the relationship between these three values, the script automatically determines the current market "mood" and displays it to you:

1. DownTrend Detection If the Large EMA is higher than the Medium EMA, and the Medium EMA is higher than the Low EMA, the script identifies a "DownTrend." It will display this status in Crimson text on your chart.

2. UpTrend Detection Conversely, if the Large EMA is lower than the Medium EMA, and the Medium EMA is lower than the Low EMA, the script identifies an "UpTrend" and displays it in SpringGreen text.

3. Sideways Market Detection If the relationship between these three averages does not clearly fall into an upward or downward sequence (meaning the price is moving horizontally or consolidating), the script labels the market as "Sideways" and displays it in Gold text.

Key Features for the User

  • Real-Time Data Tracking: The script constantly updates the exact numerical values of all three EMAs. This allows you to see the precise price levels at a glance without having to hover your mouse over lines on the chart.
  • Customizable Visibility: You can choose exactly where on the screen the information appears (e.g., top right, bottom left) and adjust the font sizes for both the trend description and the numerical values to suit your preference.
  • Timeframe Flexibility: The script is designed to work with the current chart timeframe automatically, ensuring that the data you see always matches the period you are currently trading.
  • Clean Interface: By using "Object Labels," the script ensures that the text stays fixed in your chosen corner, providing a professional and organized workspace for active trading.
Indicators Used
Moving average indicator
10 Views
0 Downloads
0 Favorites
TrendEMA_V_1
//+------------------------------------------------------------------+
//|                       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 Trend_Fontz   = 12;  // Font size 12 default for trend description
extern int EMA_Fonts     = 9;   // Font Size 9 default for the EMAs
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
//--------------------------

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, 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 ",Trend_Fontz,"Arial Black",Crimson);  
       ObjectSetText("Lma","Large EMA = "+DoubleToStr(Lma,5),EMA_Fonts,"Arial Bold",White);  
       ObjectSetText("Mma","Medium EMA = "+DoubleToStr(Mma,5),EMA_Fonts,"Arial Bold",White);
       ObjectSetText("Nma","Low EMA = "+DoubleToStr(Nma,5),EMA_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 ",Trend_Fontz,"Arial Black",SpringGreen);  
      ObjectSetText("Lma","Large EMA = "+DoubleToStr(Lma,5),EMA_Fonts,"Arial Bold",White);  
      ObjectSetText("Mma","Medium EMA = "+DoubleToStr(Mma,5),EMA_Fonts,"Arial Bold",White);
      ObjectSetText("Nma","Low EMA = "+DoubleToStr(Nma,5),EMA_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 ",Trend_Fontz,"Arial Black",Gold);  
      ObjectSetText("Lma","Large EMA = "+DoubleToStr(Lma,5),EMA_Fonts,"Arial Bold",White);  
      ObjectSetText("Mma","Medium EMA = "+DoubleToStr(Mma,5),EMA_Fonts,"Arial Bold",White);
      ObjectSetText("Nma","Low EMA = "+DoubleToStr(Nma,5),EMA_Fonts,"Arial Bold",White);

           ObjectDelete("Nma-Trend"); 
           ObjectDelete("Lma-Trend");
         //ObjectDelete("Mma-Trend");
     }
   return(0);
  }
//+---------------------End Of Code---------------------------------------------+

Comments