FlatTrend w MACD
Download scriptThe FlatTrend indicator is a specialized technical analysis tool designed to help traders identify specific market conditions by analyzing momentum and price action. Instead of cluttering the main price chart, it operates in a separate window, providing clear visual signals based on three distinct market states.
Core Logic and Functionality
The script functions by monitoring the relationship between different moving averages (specifically utilizing the MACD logic) to determine the "health" of a trend. It categorizes market behavior into three distinct colors, each representing a different trading environment:
- Bullish Momentum (Lime Green): The indicator identifies a positive trend when the primary momentum is above zero and rising faster than the signal line. This suggests that buying pressure is currently dominant.
- Bearish Momentum (Red): Conversely, the indicator flags a negative trend when the primary momentum falls below zero and is decreasing more sharply than the signal line. This signifies that selling pressure is taking control.
- Neutral / Flat Market (Gold): When the market is neither showing strong bullish momentum nor strong bearish momentum—effectively "flat" or consolidating—the indicator highlights this state in gold. This helps traders recognize periods of indecision where the trend may be sideways.
Key Features
- Flexible Timeframes: The tool is highly adaptable. It can be configured to analyze various time intervals, ranging from short-term 1-minute charts to long-term monthly views. This allows users to switch between "scalping" (fast movements) and "swing trading" (slow movements) seamlessly.
- Customizable Sensitivity: You can adjust the internal calculations (Fast, Slow, and MA periods) to fine-tune how quickly the indicator reacts to price changes, allowing it to be tailored to different asset classes like Forex, Stocks, or Commodities.
- Visual Clarity: By using a histogram format in a dedicated window, the script removes visual noise from your primary price chart, allowing you to focus on the trend's direction while keeping the "heartbeat" of the market momentum visible at all times.
Summary for the User
In simple terms, this tool acts as a filter. It looks at the underlying math of the market and tells you: "Is the price moving up with strength (Green), moving down with strength (Red), or just wandering sideways (Gold)?" It simplifies complex data into three easy-to-read visual signals.
//+------------------------------------------------------------------+
//| 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