FlatTrend_v1
Download scriptThe FlatTrend indicator is designed to help traders visualize market momentum and identify specific price actions by analyzing three distinct mathematical layers of data simultaneously. Instead of cluttering the main price chart, it creates a visual history in a separate window to signal whether the market is trending in a specific direction or experiencing a period of consolidation.
How the Logic Works
The script functions by constantly monitoring the relationship between three different technical components: ADX (Average Directional Index), Parabolic SAR, and Close Prices.
Here is the breakdown of how it interprets the market:
- Trend Identification: The tool looks at the ADX values to determine if the strength of a movement is increasing or decreasing. By comparing current momentum against previous momentum, it decides if the "push" behind the price is growing in either an upward or downward direction.
- Price Confirmation: It cross-references this momentum with the Parabolic SAR—a common tool used to identify potential trend reversals. The script checks where the current market price sits in relation to these SAR levels.
- Visual Signals: The logic translates these complex calculations into three distinct visual markers:
- Green Signals: These appear when the price is consistently moving above specific trend levels while momentum is strengthening upward. This suggests a bullish environment.
- Red Signals: These appear when the price falls below key trend levels while downward momentum is intensifying. This suggests a bearish environment.
- Gold Signals: This is the "neutral" state. If neither a strong upward nor a strong downward trend is detected by the logic, the indicator marks the area in gold. This typically represents a "flat" or sideways market where there is no clear direction, signaling to the trader that it may be best to wait for a breakout.
Customization
The script allows you to define the specific time interval (such as 5 minutes, 1 hour, or daily) at which these calculations should occur. This ensures that the trend signals stay relevant to your specific trading style, whether you are a scalper looking at quick movements or a long-term investor monitoring daily shifts.
/*-----------------------------+
| |
| 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=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