4MAs_FlatTrend
Download scriptThe 4MAs Trend indicator is a visual trading tool designed to help identify market direction and potential periods of consolidation or "flat" markets. It operates by analyzing the relationship between four distinct Moving Averages (MAs) simultaneously, providing a clear summary of market momentum in a dedicated sub-window on your chart.
Core Functionality
The script calculates four different moving averages based on user-defined settings. These averages act as filters to smooth out price fluctuations, allowing you to see the underlying trend more clearly. The indicator specifically looks for "perfect alignment" among these four lines to signal market strength:
- Bullish Momentum (Lime Green): When the market is in a strong uptrend, the fastest moving average sits above the second, which is above the third, and so on, down to the slowest average. When this stacked order occurs, the indicator highlights a bullish trend.
- Bearish Momentum (Red): Conversely, when the market is in a strong downtrend, the order is reversed: the fastest moving average sits below all others. This signals a consistent downward move.
- Neutral/Flat Market (Gold): This is a unique feature of the script. If the four moving averages are neither perfectly stacked in an uptrend nor a downtrend—meaning they are overlapping or tangled—the indicator highlights this as a "flat" market.
Key Features for Traders
- Dynamic Timeframe Selection: The tool can be configured to analyze various periods, ranging from 1-minute intervals up to monthly views, allowing you to maintain consistency across different trading styles.
- Visual Clarity: Rather than cluttering your main price chart with multiple lines, this script concentrates the data into a single histogram-style view. This helps you quickly identify whether the current environment is trending or sideways at a glance.
- Customizable Sensitivity: Users can adjust the values and calculation modes of the four moving averages to fine-tune how "sensitive" the indicator is to price changes, making it adaptable to different assets (like Forex, Stocks, or Commodities).
By simplifying complex overlapping data into three distinct visual signals, this script helps traders avoid "choppy" markets and stay aligned with the dominant price movement.
//+------------------------------------------------------------------+
//| 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=0;
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,3,Red);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,3, LimeGreen);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,3, 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 < 900; 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