FlatTrend V21_v1

Download script
Author: Kirk Sloan
FlatTrend V21_v1

This tool is designed to help traders identify and visualize market trends by analyzing the relationship between price movement, momentum, and volatility. Rather than cluttering your main chart with multiple lines, it generates a dedicated visual display (a histogram) that summarizes these complex technical factors into clear signals.

How the Logic Works

The script operates by simultaneously monitoring three distinct types of technical data:

  • Trend Velocity (ADX): The tool looks at the Average Directional Index (ADX) to determine the strength of the current market movement. It compares the current strength against the previous period to see if momentum is accelerating or decelerating.
  • Price Position (Parabolic SAR): It tracks the Parabolic Stop and Reverse indicator, which acts as a dynamic "ceiling" or "floor." The script checks whether the current price is trading above or below these specific trend boundaries.
  • Timeframe Flexibility: You can choose the specific time period (from 1 minute up to monthly charts) that you want the logic to analyze, allowing you to switch between scalping views and long-term trends seamlessly.

How the Signals are Generated

The script combines these three factors to determine which bar to light up in the indicator window. The logic follows a specific set of rules:

  1. Bullish Momentum: When the price is positioned above the trend boundary and the momentum is increasing, the tool identifies a positive trend.
  2. Bearish Momentum: When the price falls below the trend boundary while momentum remains high, the tool signals a downward shift.
  3. Trend Transitions: The script continuously compares current data against past data to detect "crossovers." If the momentum flips (e.g., from strengthening to weakening) while the price stays on one side of the boundary, it provides a visual cue that the trend may be flattening or reversing.

User Experience

For the trader, this means you don't have to manually calculate if the market is getting "tired" or if the trend is actually breaking. The indicator does the heavy lifting by scanning these three variables and providing a visual representation of the market's health, helping you identify whether the current price action is supported by strong momentum or if it is losing steam.

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
16 Views
0 Downloads
0 Favorites
FlatTrend V21_v1
/*-----------------------------+
|			       |
| 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 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