FlatTrend w MACD_v1

Download script
Author: Kirk Sloan
FlatTrend w MACD_v1

The FlatTrend indicator is designed to provide traders with a visual representation of market momentum and trend direction by analyzing specific price movements over different timeframes. Instead of cluttering the main price chart, it operates in a separate window, using color-coded bars to simplify the identification of bullish, bearish, and neutral market states.

Core Logic and Functionality

The script functions by processing historical data based on three distinct signals derived from the MACD (Moving Average Convergence Divergence) momentum indicator. Here is how it interprets the market:

  • Bullish Momentum (Lime Green): The tool identifies upward pressure when the primary MACD value is positive and sits above its signal line. When this condition is met, the indicator displays green bars, suggesting that the current trend has positive strength.
  • Bearish Momentum (Red): Conversely, the script detects downward pressure when the primary MACD value is negative and falls below its signal line. These moments are represented by red bars, highlighting a period where the market sentiment is leaning toward a decline.
  • Neutral/Flat Market (Gold): One of the unique features of this script is its ability to identify "flat" or indecisive zones. If neither the bullish nor the bearish conditions are met—meaning the market is lacking clear directional momentum—the indicator displays gold bars. This serves as a visual cue that the market may be ranging or consolidating.

Customization and Flexibility

The tool is built with several user-adjustable parameters to ensure it fits different trading styles:

  • Timeframe Selection: You can choose which specific timeframe (ranging from 1 minute to monthly views) the indicator should analyze. This allows you to see high-level trends while looking at smaller price movements, or vice versa.
  • MACD Sensitivity: The script includes adjustable settings for the "Fast," "Slow," and "Moving Average" components of the MACD. By tweaking these numbers, you can make the indicator more sensitive to quick price changes or more stable for long-term trend tracking.
  • Data Depth: The logic is designed to scan a significant amount of historical data (up to 1,000 bars), ensuring that the visual trend history is consistent and easy to read at a glance.

Summary for Traders

By translating complex mathematical oscillations into three simple colors (Red, Lime Green, and Gold), this indicator helps you quickly distinguish between trending markets and stagnant ones. It removes the guesswork of interpreting multiple overlapping lines, providing a clear "at-a-glance" view of whether the market is pushing up, pulling down, or staying flat.

Indicators Used
MACD Histogram
Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
FlatTrend w MACD_v1
//+------------------------------------------------------------------+
//|                                                    FlatTrend.mq4 |
//|                                                       Kirk Sloan |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Kirk Sloan"
#property link      "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 MACD_Fast = 8;
extern int MACD_Slow = 21;
extern int MACD_MA = 9;
extern int nBar = 1000;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double Ma;
double hhigh, llow;
double Psar;
double PADX,NADX;
string TimeFrameStr;
double MA1,MA2,MA3;
double MACD_Signal,MACD_Main;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
  SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,1,Red);
  SetIndexBuffer(0,ExtMapBuffer1);
  SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1, LimeGreen);
  SetIndexBuffer(1,ExtMapBuffer2);
  SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1, 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 MACD ("+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 < nBar; i++){
   ExtMapBuffer1[i]=0;
   ExtMapBuffer2[i]=0;
   ExtMapBuffer3[i]=0;
   

   MACD_Signal=iMACD(NULL,Minutes,MACD_Fast,MACD_Slow,MACD_MA,PRICE_CLOSE,MODE_SIGNAL,i);
   MACD_Main  =iMACD(NULL,Minutes,MACD_Fast,MACD_Slow,MACD_MA,PRICE_CLOSE,MODE_MAIN,i);
   
   if(MACD_Signal < MACD_Main && MACD_Main > 0)ExtMapBuffer2[i] = 1;
   if(MACD_Signal > MACD_Main && MACD_Main < 0)ExtMapBuffer1[i] = 1;
   if(ExtMapBuffer1[i] == 0 && ExtMapBuffer2[i] == 0)
   {ExtMapBuffer3[i] = 1;}
  
}
 
 
 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments