FlatTrend Alert

Download script
Author: Kirk Sloan
FlatTrend Alert

The Flat Trend Alert is a specialized technical analysis tool designed to help traders identify specific momentum shifts and periods of market stagnation. By utilizing the MACD (Moving Average Convergence Divergence) indicator, the script filters out standard market "noise" to highlight three distinct market states visually in a dedicated window.

How the Logic Works

The script analyzes price action based on the timeframes you select (ranging from 1-minute charts to monthly views). It processes historical data to categorize market movement into three primary signals:

  • Bullish Momentum (Blue Signal): The tool identifies conditions where the MACD Main line is above zero and crossing over its signal line. This represents an active upward trend, which the script highlights in Royal Blue.
  • Bearish Momentum (Red Signal): Conversely, the tool tracks when the MACD Main line falls below zero and crosses under its signal line. This indicates downward momentum and is highlighted in Red.
  • Flat/Neutral Market (Gold Signal): One of the script's key features is its ability to detect "flat" markets. If the price action is neither showing active bullish nor bearish momentum, the script flags this as a neutral zone, displayed in Gold.

Automated Alerts

Beyond visual representation, the script acts as an automated monitor. It tracks real-time changes in these market states and triggers immediate audible alerts on your platform:

  • A "Blue color show up" alert sounds when the market shifts into a bullish trend.
  • A "Red color show up" alert sounds when the market shifts into a bearish trend.

By distilling complex moving average calculations into three clear visual cues, this tool allows you to quickly distinguish between active trends and consolidation periods at a glance.

Indicators Used
MACD Histogram
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
11 Views
0 Downloads
0 Favorites
FlatTrend Alert
//+------------------------------------------------------------------+
//|                                              FlatTrend Alert.mq4 |
//|                                                       Kirk Sloan |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Kirk Sloan"
#property link      "http://www.metaquotes.net"
#property link      "Alert by Goen"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 RoyalBlue
#property indicator_color3 Gold
//---- input parameters
extern int Minutes=0;
extern int MACD_Fast = 12;
extern int MACD_Slow = 26;
extern int MACD_MA = 9;
extern int BarsToCount = 10000;
//---- 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,4,Red);
  SetIndexBuffer(0,ExtMapBuffer1);
  SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,4, RoyalBlue);
  SetIndexBuffer(1,ExtMapBuffer2);
  SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,4, 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 < BarsToCount; 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;}
   
     
}
 
   static int lastalert=0;
   if(ExtMapBuffer2[0] == 1 && ExtMapBuffer2[1] != 1 && lastalert!=Bars) 
   {  Alert("Blue color show up"); lastalert=Bars;
   }
   if(ExtMapBuffer1[0] == 1 && ExtMapBuffer1[1] != 1 && lastalert!=Bars)
   {   Alert("Red color show up"); lastalert=Bars;
   }

 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments