MA_filter_6MA_FlatTrend_direct
Download scriptThis tool is designed to help traders visualize market trends by analyzing the relationship between six different Moving Averages (MAs) simultaneously. Instead of cluttering your main price chart with multiple overlapping lines, this indicator simplifies the data into a clean, separate visual display that identifies the current "mood" of the market.
How the Logic Works
The script monitors six distinct moving averages, each calculated over different time periods (ranging from short-term to longer-term trends). By comparing these six values against one another, the indicator determines the strength and direction of the market trend.
The visual output is divided into three distinct states represented by different colors:
- Bullish Trend (Lime Green): This appears when the moving averages indicate a consistent upward movement. Depending on your settings, the logic identifies this as either all six averages increasing compared to their previous values or being arranged in a specific ascending order.
- Bearish Trend (Red): This appears when the moving averages indicate a consistent downward move. It signals that the trend is favoring the sellers, occurring when the averages are decreasing or arranged in a descending order.
- Neutral / Flat Market (Gold): This is the "filter" state. If the market is not clearly moving up or down—meaning the moving averages are tangled or moving sideways—the indicator switches to Gold. This helps traders identify periods of consolidation where the trend is unclear and trading may be less predictable.
Key Features
- Customizable Timeframes: You can adjust the tool to analyze different time scales, from 1-minute charts up to monthly views, allowing you to switch between "scalping" and long-term "swing" analysis effortlessly.
- Directional Filtering: The script includes a toggleable filter. This allows you to choose between two types of logic:
- Momentum-Based: Checking if the averages are currently rising or falling compared to their previous position.
- Position-Based: Checking if the averages are stacked in a specific order (e.g., the fastest moving average is above the slowest).
- Clean Visual Interface: By using a histogram style in a separate window, the tool removes visual "noise," providing you with a clear traffic light system (Green for Up, Red for Down, Gold for Neutral) to help guide your trading decisions.
//+------------------------------------------------------------------+
//| 4MAs Trend.mq4|
//| Flat Trend |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 3
#property indicator_color1 LimeGreen
#property indicator_color2 Red
#property indicator_color3 Gold
//---- input parameters
extern int Minutes=0;
extern int MA1_Period=7;
extern int MA1_Mode=3;
extern int MA2_Period=9;
extern int MA2_Mode=3;
extern int MA3_Period=11;
extern int MA3_Mode=3;
extern int MA4_Period=13;
extern int MA4_Mode=3;
extern int MA5_Period=15;
extern int MA5_Mode=3;
extern int MA6_Period=21;
extern int MA6_Mode=3;
extern bool DirectionFilterOn = true;
//extern int MaxBarsToCount=1000;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
string TimeFrameStr;
double MA1,MA2,MA3,MA4,MA5,MA6;
double MA1p,MA2p,MA3p,MA4p,MA5p,MA6p;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,5,LimeGreen);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,5, Red);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,5, Gold);
SetIndexBuffer(2,ExtMapBuffer3);
for(int i=0; i<=indicator_buffers; i++) SetIndexLabel(i,NULL);
switch(Minutes)
{
case 1 : TimeFrameStr="M1"; break;
case 5 : TimeFrameStr="M5"; break;
case 15 : TimeFrameStr="M15"; break;
case 30 : TimeFrameStr="M30"; break;
case 60 : TimeFrameStr="H1"; break;
case 240 : TimeFrameStr="H4"; break;
case 1440 : TimeFrameStr="D1"; break;
case 10080 : TimeFrameStr="W1"; break;
case 43200 : TimeFrameStr="MN"; break;
default : TimeFrameStr="TF0"; Minutes=0;
}
if (DirectionFilterOn)string name = " Direction Filter On "; else name = "";
IndicatorShortName("Flat Trend w 6MA ["+TimeFrameStr+"] "+name);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,limit, counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit= Bars-counted_bars;
for(i=limit; i>=0; i--)
{
ExtMapBuffer1[i]=0.0; ExtMapBuffer2[i]=0.0; ExtMapBuffer3[i]=0.0;
MA1=iMA(NULL,Minutes,MA1_Period,0,MA1_Mode,5,i);
MA2=iMA(NULL,Minutes,MA2_Period,0,MA2_Mode,5,i);
MA3=iMA(NULL,Minutes,MA3_Period,0,MA3_Mode,5,i);
MA4=iMA(NULL,Minutes,MA4_Period,0,MA4_Mode,5,i);
MA5=iMA(NULL,Minutes,MA5_Period,0,MA5_Mode,5,i);
MA6=iMA(NULL,Minutes,MA6_Period,0,MA6_Mode,5,i);
if (DirectionFilterOn)
{
MA1p=iMA(NULL,Minutes,MA1_Period,0,MA1_Mode,5,i+1);
MA2p=iMA(NULL,Minutes,MA2_Period,0,MA2_Mode,5,i+1);
MA3p=iMA(NULL,Minutes,MA3_Period,0,MA3_Mode,5,i+1);
MA4p=iMA(NULL,Minutes,MA4_Period,0,MA4_Mode,5,i+1);
MA5p=iMA(NULL,Minutes,MA5_Period,0,MA5_Mode,5,i+1);
MA6p=iMA(NULL,Minutes,MA6_Period,0,MA6_Mode,5,i+1);
if(MA1>MA1p&&MA2>MA2p&&MA3>MA3p&&MA4>MA4p&&MA5>MA5p&&MA6>MA6p) ExtMapBuffer1[i] = 1;
else
if(MA1<MA1p&&MA2<MA2p&&MA3<MA3p&&MA4<MA4p&&MA5<MA5p&&MA6<MA6p) ExtMapBuffer2[i] = 1;
else ExtMapBuffer3[i] = 1;
}
else
{
if(MA1>MA2 && MA2>MA3 && MA3>MA4 && MA4>MA5 && MA5>MA6) ExtMapBuffer1[i] = 1;
else
if(MA1<MA2 && MA2<MA3 && MA3<MA4 && MA4<MA5 && MA5<MA6) ExtMapBuffer2[i] = 1;
else ExtMapBuffer3[i] = 1;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments