4MAs Trend

The 4MAs Trend indicator is a specialized trading tool designed to simplify market analysis by identifying the prevailing direction of price movements. Rather than cluttering your main chart with multiple overlapping lines, this script processes data in the background and provides a clear visual summary of market momentum in a separate window.

How the Logic Works

The core logic of this tool relies on the relationship between four different Moving Averages (MAs). These averages act as filters that smooth out "market noise," allowing the script to determine whether the price is trending upward, downward, or remaining stagnant.

1. Multi-Timeframe Analysis The tool allows you to select a specific timeframe (ranging from 1-minute intervals up to monthly data). By doing this, the indicator looks at the "big picture" of the market, ensuring that the signals you see are based on the broader trend rather than just temporary price fluctuations.

2. Trend Identification (The Core Signals) The script constantly compares four different moving averages against each other. It categorizes the market into three distinct states:

  • Bullish Momentum (Lime Green): When all four moving averages are stacked in ascending order (where the fastest average is above the second fastest, and so on), the tool identifies a strong upward trend. This is signaled by a green histogram.
  • Bearish Momentum (Red): Conversely, if all four moving averages are stacked in descending order (where the fastest average is below the second fastest, and so on), the tool identifies a strong downward trend. This is signaled by a red histogram.
  • Neutral / Flat Market (Gold): If the moving averages are not clearly stacked in either direction, the tool recognizes that there is no clear trend. In these instances, it signals a "flat" or neutral market with a gold histogram.

Key Benefits for the User

  • Visual Clarity: By moving the data to a separate window and using a histogram format, it keeps your main price chart clean while still providing essential trend data.
  • Simplified Decision Making: You don't need to manually plot four different lines and interpret their crossovers. The script does the math for you, translating complex data into three easy-to-read colors.
  • Customizable Sensitivity: The logic can be adjusted via input parameters, allowing you to change the length of the moving averages or the timeframe to suit your specific trading style—whether you are a day trader looking for quick moves or a long-term investor following macro trends.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
4MAs Trend
//+------------------------------------------------------------------+
//|                                                    4MAs Trend.mq4 |
//|                                                      |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 LimeGreen
#property indicator_color3 Gold
//---- input parameters
extern int Minutes=60;
extern int MA1_Value=5;
extern int MA1_Mode=0;
extern int MA2_Value=13;
extern int MA2_Mode=0;
extern int MA3_Value=34;
extern int MA3_Mode=3;
extern int MA4_Value=55;
extern int MA4_Mode=3;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
string TimeFrameStr;
double MA1,MA2,MA3,MA4;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
  SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2,Red);
  SetIndexBuffer(0,ExtMapBuffer1);
  SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2, LimeGreen);
  SetIndexBuffer(1,ExtMapBuffer2);
  SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2, Gold);
  SetIndexBuffer(2,ExtMapBuffer3);

switch(Minutes)
   {
      case 1 : TimeFrameStr="Period_M1"; break;
      case 5 : TimeFrameStr="Period_M5"; break;
      case 15 : TimeFrameStr="Period_M15"; break;
      case 30 : TimeFrameStr="Period_M30"; break;
      case 60 : TimeFrameStr="Period_H1"; break;
      case 240 : TimeFrameStr="Period_H4"; break;
      case 1440 : TimeFrameStr="Period_D1"; break;
      case 10080 : TimeFrameStr="Period_W1"; break;
      case 43200 : TimeFrameStr="Period_MN1"; break;
      default : TimeFrameStr="Current Timeframe"; Minutes=0;
   }
   IndicatorShortName("Flat Trend w 4 MAs ("+TimeFrameStr+")");  

 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----

for (int i = 0; i < 300; i++){
   ExtMapBuffer1[i]=0;
   ExtMapBuffer2[i]=0;
   ExtMapBuffer3[i]=0;
   
   MA1=iMA(NULL,Minutes,MA1_Value,0,MA1_Mode,PRICE_CLOSE,i);
   MA2=iMA(NULL,Minutes,MA2_Value,0,MA2_Mode,PRICE_CLOSE,i);
   MA3=iMA(NULL,Minutes,MA3_Value,0,MA3_Mode,PRICE_CLOSE,i);
   MA4=iMA(NULL,Minutes,MA4_Value,0,MA4_Mode,PRICE_CLOSE,i);


   if(MA1 > MA2 && MA2 > MA3 && MA3 > MA4 )ExtMapBuffer2[i] = 1;
   if(MA1 < MA2 && MA2 < MA3 && MA3 < MA4 )ExtMapBuffer1[i] = 1;

   if(ExtMapBuffer1[i] == 0 && ExtMapBuffer2[i] == 0)  {ExtMapBuffer3[i] = 1;}
  
}
 
 
 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments