FlatTrend V2_v2
Download scriptThe FlatTrend indicator is designed to provide visual clarity regarding market direction by identifying specific trend signals through the combination of momentum and price position. Instead of relying on a single data point, it synthesizes three different technical components—Parabolic SAR, ADX (Average Directional Index), and Price Action—to categorize market movements into distinct visual signals.
How the Logic Works
The script scans historical price data and applies a set of conditions to determine which "signal" should appear on your chart. Here is the breakdown of the logic:
1. Momentum Filtering (ADX) The indicator uses the ADX to measure the strength of a trend. It specifically compares the current momentum against the previous period's momentum to see if the "push" in price is increasing or decreasing. This helps ensure the script isn't just reacting to minor noise but is aware of whether the market energy is shifting.
2. Price Positioning (Parabolic SAR) The logic incorporates the Parabolic SAR, which is a common tool used to determine the "turning point" of a trend. The script looks at where the price sits in relation to theseSAR dots:
- If the price is above the SAR dot, it suggests an upward bias.
- If the price is below the SAR dot, it suggests a downward bias.
3. Signal Synthesis The indicator combines these two factors to produce four distinct visual outputs (represented as different colored histograms):
- Bullish Momentum: When the price is above the SAR dot and the momentum is showing an upward trend, the script identifies a strong buying signal.
- Bearish Momentum: When the price is below the SAR dot and momentum is moving downward, the script identifies a strong selling signal.
- Trend Conflicts: The logic also accounts for "mixed" signals—scenarios where the price might be moving in one direction, but the underlying momentum is beginning to weaken or shift in the opposite direction.
User Experience
From a visual standpoint, the script translates these complex calculations into clear, color-coded bars in a separate window. By looking at the colors and heights of these bars, a trader can quickly see whether the current market environment supports an aggressive move, a trend continuation, or a potential shift in sentiment based on the predefined timeframes (ranging from 1-minute charts to monthly views).
/*-----------------------------+
| |
| 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 4
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Yellow
//---- input parameters
extern int Minutes=0;
//---- 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,3,Red);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,3,Green);
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 < 20000; 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