4MAs Trend_v1

Download script
4MAs Trend_v1

This tool is designed to help traders identify and visualize market trends by analyzing the relationship between four different Moving Averages (MAs). Instead of cluttering your main price chart, this script operates in a separate window, providing a clear, color-coded signal of the current market momentum.

How the Logic Works

The script monitors the price action across various timeframes (ranging from 1 minute to monthly intervals) and calculates four distinct moving averages based on user-defined speeds. By comparing these averages against one another, the tool determines whether the market is in a structured trend or experiencing a period of consolidation.

Visual Signals & Interpretations

The indicator uses three different colors to represent specific market conditions:

  • Lime Green (Bullish Trend): This signal appears when all four moving averages are stacked in ascending order (from fastest to slowest). This indicates a strong, healthy upward momentum where the short-term price action is consistently higher than the long-term average.
  • Red (Bearish Trend): This signal appears when all four moving averages are stacked in descending order. It identifies a consistent downward trend where the short-term price action is falling faster than the long-term averages.
  • Gold (Neutral/Flat Market): The gold signal acts as a "filler" or "flat" indicator. It activates whenever neither a clear bullish nor a clear bearish trend is detected. This helps traders identify periods of market indecision, sideways movement, or consolidation where the moving averages are overlapping or not clearly ordered.

Key Features for the User

  • Customizable Timeframes: You can set the script to analyze specific timeframes (such as H1, H4, or Daily) to align with your preferred trading style.
  • Adjustable Sensitivity: The tool allows you to modify the values and modes of the four moving averages, enabling you to make the trend detection more sensitive or more stable depending on your strategy.
  • Simplified Decision Making: By condensing complex moving average crossovers into three distinct visual bars, the script removes the noise of multiple lines, allowing you to see at a glance whether the market is trending up, trending down, or remaining flat.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
4MAs Trend_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                    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