Flat Trend
Download scriptThe Flat Trend indicator is designed to provide traders with a visual representation of market momentum and trend direction by filtering out "noise" and identifying clear price movements. Instead of cluttering the main chart, it operates in a separate window, using three distinct colors to signal different market conditions.
Core Logic and Mechanics
The script analyzes price action by combining three different technical components: ADX (Average Directional Index), the Parabolic SAR, and Price Close values. Here is how the logic interprets the market:
- Trend Strength Tracking: The script uses the ADX to measure the strength of a trend. By comparing two different periods of this index simultaneously, it can determine if the current momentum is accelerating or decelerating.
- Price Positioning: It monitors where the current market price sits in relation to the Parabolic SAR (a technical tool used to identify potential reversal points).
- Signal Filtering: Rather than reacting to every small wiggle in the price, the script looks for a "confluence"—meaning multiple conditions must be met at once before a signal is displayed.
Visual Signals Explained
The indicator translates these complex calculations into three simple visual states:
- Bullish Momentum (Lime Green): This appears when the price is trading above the Parabolic SAR and the momentum index shows an upward trend. It suggests that buyers are in control and the trend has strength behind it.
- Bearish Momentum (Red): This signal triggers when the price falls below the Parabolic SAR and the momentum index indicates a downward shift. This suggests that sellers are dominant.
- Flat/Neutral Market (Gold): When the market is neither showing strong bullish momentum nor strong bearish momentum, the indicator displays a gold signal. This indicates a "flat" or sideways market where there is no clear direction, helping traders avoid entering trades in choppy, indecisive conditions.
Customization and Timeframes
One of the key features of this script is its flexibility regarding time. You can set it to monitor specific intervals (ranging from 1-minute and 5-minute charts up to daily and monthly views). The indicator automatically adjusts its name and internal calculations to match your chosen timeframe, ensuring that the trend analysis remains relevant to your specific trading style.
//+------------------------------------------------------------------+
//| 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=5;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double Ma;
double hhigh, llow;
double Psar;
double PADX,NADX;
string TimeFrameStr;
//+------------------------------------------------------------------+
//| 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 ("+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;
PADX=iADX(NULL,Minutes,14 ,PRICE_CLOSE,1,i);
NADX=iADX(NULL,Minutes,14 ,PRICE_CLOSE,2,i);
Psar = iSAR(NULL,Minutes,0.02,0.2,i) ;
if (Psar < iClose(NULL, Minutes,i) && PADX > NADX){
ExtMapBuffer2[i] = 1;
}
if (Psar > iClose(NULL, Minutes,i) && NADX > PADX){
ExtMapBuffer1[i] = 1;
}
if (ExtMapBuffer1[i] == 0 && ExtMapBuffer2[i] == 0){
ExtMapBuffer3[i] = 1;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments