4MAs%20Trend
Download scriptThis tool is designed to help traders visualize market trends by analyzing the relationship between four different Moving Averages (MAs). Instead of cluttering your main chart with multiple lines, it condenses this information into a clean histogram displayed in a separate window at the bottom of your trading screen.
How the Logic Works
The script monitors the price action based on a timeframe of your choice (ranging from 1 minute up to monthly charts). It calculates four specific Moving Averages simultaneously and evaluates their positions relative to one another to determine the "health" of the trend.
1. Identifying Bullish Momentum (Green) The tool looks for a "perfect stack" where all four moving averages are lined up in ascending order. Specifically, if the fastest average is above the second, the second is above the third, and the third is above the fourth, the indicator registers a strong upward trend. This is displayed as a Lime Green bar.
2. Identifying Bearish Momentum (Red) Conversely, the tool monitors for a "perfect descent." If the fastest average is below the second, the second is below the third, and the third is below the fourth, it signifies a strong downward trend. This is displayed as a Red bar.
3. Identifying Neutrality or Consolidation (Gold) When the market is not clearly trending in either direction—meaning the moving averages are tangled, overlapping, or failing to maintain a consistent stack—the indicator registers a neutral state. These moments are displayed as Gold bars, highlighting periods of consolidation or indecision.
Key Features for the User
- Customizable Timeframes: You can adjust the "Minutes" setting to align the analysis with your preferred trading style (e.g., H1, H4, Daily).
- Adjustable Sensitivity: The tool allows you to modify the values and calculation modes of the four Moving Averages, letting you tailor how quickly or slowly the indicator reacts to price changes.
- Visual Clarity: By isolating these signals into a separate histogram window, the tool allows you to see the "big picture" of the trend at a glance without distracting from the price action on your main chart.
//+------------------------------------------------------------------+
//| 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