FlatTrend w MACD_v2

Download script
Author: Kirk Sloan
FlatTrend w MACD_v2

The Flat Trend indicator is designed to help traders visualize market momentum and identify specific phases of price movement by utilizing the MACD (Moving Average Convergence Divergence) technical analysis tool. Instead of cluttering the main price chart, this script operates in a separate window, providing a clean, color-coded summary of market conditions.

Core Functionality

The logic behind this indicator revolves around identifying three distinct market states based on the relationship between two specific components of the MACD: the Main line and the Signal line. It translates these mathematical movements into a visual histogram using three different colors.

How the Logic Works

The script monitors price data over user-defined timeframes (ranging from 1 minute to monthly charts) and applies the following rules to determine which color to display:

  • Bullish Momentum (Lime Green): When the market shows signs of upward strength—specifically when the Main line is above zero and the Signal line falls below it—the indicator highlights this as a positive trend.
  • Bearish Momentum (Red): Conversely, when the market shows signs of downward pressure—where the Main line is below zero and the Signal line rises above it—the indicator marks this as a negative trend.
  • Neutral/Flat Market (Gold): The indicator also identifies "flat" periods. If neither the bullish nor the bearish conditions are met (meaning the market is in a state of equilibrium or lacking a clear directional push), the script displays a gold signal.

Key Features for Users

  • Customizable Timeframes: You can adjust the analysis period to match your trading style, whether you are looking at fast-paced scalping minutes or long-term daily trends.
  • Adjustable Sensitivity: The logic includes customizable settings for the MACD's "Fast," "Slow," and "MA" parameters, allowing you to fine-tune how quickly the indicator reacts to price changes.
  • Visual Clarity: By using a histogram format in a separate window, it removes the noise of the main price candles, allowing you to see the underlying "pulse" of the trend at a glance.

In summary, this tool acts as a filtering system that categorizes market behavior into three simple zones: active buying pressure, active selling pressure, or a neutral "flat" state, helping traders make more informed decisions based on current momentum.

Indicators Used
MACD Histogram
Miscellaneous
Implements a curve of type %1
18 Views
0 Downloads
0 Favorites
FlatTrend w MACD_v2
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

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