The Flat Trend indicator is a specialized technical analysis tool designed to help traders visualize market momentum and trend direction by combining two distinct types of market data: trend strength (via the ADX) and price position (via the Parabolic SAR).
Core Logic and Data Processing
The script operates by analyzing historical price data over a user-defined timeframe (ranging from 1-minute intervals up to monthly views). To determine the signals shown on your chart, it looks at two primary components:
- Trend Strength (ADX): The tool compares current movement against previous movement to determine if the market is gaining or losing momentum. It essentially checks if the "force" of the trend is increasing or decreasing.
- Price Positioning (Parabolic SAR): This identifies where the price sits in relation to a calculated "stop" point. It helps distinguish whether the current price action is favoring an upward move or a downward move.
How the Signals Work
The indicator visualizes these combined factors as a series of histograms. The logic categorizes the market into four distinct states based on the interaction between momentum and price position:
- Bullish Momentum: When the indicators identify that price strength is increasing while the price maintains a specific upward positioning, the tool signals a primary bullish trend.
- Bearish Momentum: Conversely, when the indicators detect decreasing strength coupled with a specific downward price positioning, it highlights a bearish trend.
- Trend Transitions: The logic also accounts for nuances where the momentum might be moving in one direction while the price position suggests a different state. This allows the user to see "conflicting" signals, which can help identify periods of consolidation or potential trend reversals.
User Experience
For the trader, this means instead of looking at raw numbers, you receive a visual representation of market "health." By observing the different colored histograms, you can quickly identify whether the current market environment is characterized by strong upward movement, downward pressure, or a neutral state where trends are weakening. This allows for a more structured approach to identifying when to enter or exit a position based on the prevailing market "flow."
//+------------------------------------------------------------------+
//| 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 4
#property indicator_color1 Red
#property indicator_color2 LimeGreen
#property indicator_color3 Gold
//---- input parameters
extern int Minutes=15;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
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,2,Red);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2, LimeGreen);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1, Salmon);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,1, LightGreen);
SetIndexBuffer(3,ExtMapBuffer4);
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 < 400; i++){
ExtMapBuffer1[i]=0;
ExtMapBuffer2[i]=0;
ExtMapBuffer3[i]=0;
ExtMapBuffer4[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){
ExtMapBuffer4[i] = 1;
}
if (Psar > iClose(NULL, Minutes,i) && NADX > PADX){
ExtMapBuffer1[i] = 1;
}
if (Psar > iClose(NULL, Minutes,i) && PADX > NADX){
ExtMapBuffer3[i] = 1;
}
if (ExtMapBuffer1[i] == 0 && ExtMapBuffer2[i] == 0){
//ExtMapBuffer3[i] = 1;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments