FlatTrend V2

Download script
Author: Kirk Sloan
FlatTrend V2

The Flat Trend indicator is designed to provide traders with a visual representation of market momentum and price direction by synthesizing three distinct technical analysis tools into a single, easy-to-read histogram. Instead of looking at cluttered charts full of different lines, this script simplifies the market environment into specific "signal" states based on the relationship between price action, trend strength, and volatility.

How the Logic Works

The indicator operates by analyzing four specific conditions simultaneously. It looks at three core components:

  1. Price Positioning: It identifies whether the current market price is trading above or below a specific dynamic threshold (the Parabolic SAR). This helps determine if the immediate trend is moving upward or downward.
  2. Trend Strength & Momentum: It utilizes the ADX (Average Directional Index) to measure the "intensity" of a trend. By comparing two different levels of this indicator, it determines whether momentum is gaining strength or losing steam.
  3. Timeframe Context: The logic is customizable, allowing you to view these signals on various timeframes ranging from 1-minute snapshots to monthly overviews, ensuring the data remains relevant to your specific trading style.

Interpreting the Signals

The script outputs four different colored histograms, each representing a unique combination of price movement and momentum:

  • Bullish Momentum (Lime Green): This occurs when the price is positioned above the trend threshold and the primary momentum indicator is increasing. It suggests a strengthening upward move.
  • Bearish Momentum (Red): This appears when the price falls below the trend threshold while momentum is simultaneously driving downward. It indicates a strengthening downward move.
  • Secondary Trend Indicators (Gold & Light Green): These provide nuanced views where the momentum might be moving in one direction, but the price action or secondary strength levels suggest a different underlying pressure.

Summary for the User

Essentially, this tool acts as a "filter" for market noise. It looks at the background math of trend strength and price location to tell you not just if the price is moving, but how strongly it is moving in that direction. When the histograms light up, they confirm that multiple technical factors are aligning in the same direction, helping you identify clear trends while ignoring minor market fluctuations.

Price Data Components
Series array that contains close prices for each bar
Indicators Used
Movement directional indexParabolic Stop and Reverse system
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
FlatTrend V2
//+------------------------------------------------------------------+
//|                                                    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=5;
//---- 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