Trend Trigger (Bars)

Download script
Author: Copyright � 2005, MetaQuotes Software Corp.
Trend Trigger (Bars)

The Trend Trigger (Bars) is a specialized technical analysis tool designed to help traders identify the prevailing momentum of the market by comparing price action across different timeframes within a single chart. Instead of looking at simple price movements, this script analyzes the "power" behind current trends versus past price levels to determine whether the market is leaning aggressively toward a buyout or a selloff.

How the Logic Works

The core logic of this indicator functions through three distinct stages:

1. Comparative Range Analysis The tool looks back at two different windows of time on your chart (defined by the "Bars" setting). It identifies four critical price points:

  • The highest peak and lowest valley from the most recent period.
  • The highest peak and lowest valley from a previous period.

By comparing these, the script calculates "Buy Power" and "Sell Power." Essentially, it measures how far the current high is reaching compared to past lows, and how far past highs are sitting compared to current lows. This helps isolate which side of the market has the most "reach" or momentum.

2. Momentum Scoring Once the Buy and Sell powers are calculated, the script converts these into a percentage-based score. This score represents the relative strength of the trend:

  • A high positive score indicates significant upward momentum.
  • A high negative score indicates significant downward momentum.
  • A score near zero suggests a neutral or balanced market where no clear trend is dominating.

3. Smoothing and Filtering To prevent the data from being too "noisy" or jumpy (which can happen with raw price fluctuations), the script applies a mathematical smoothing process. It uses a series of weighted calculations to refine the momentum score, ensuring that the resulting trend signals are stable and reflect sustained movement rather than temporary spikes.

Visual Interpretation

The indicator translates these complex calculations into a visual histogram on your chart:

  • Strong Upward Trends: When the momentum exceeds a specific positive threshold, the tool highlights the data to signify a dominant buying environment.
  • Strong Downward Trends: When the momentum drops below a specific negative threshold, it signals a dominant selling environment.
  • Neutral Zones: When the market is undecided or moving sideways, the indicator maintains a baseline, helping traders avoid entering positions in "choppy" markets where there is no clear direction.

In summary, this tool acts as a momentum filter. It strips away the distraction of minor price fluctuations to show you the "big picture" of whether the current market energy is pushing aggressively upward or downward based on historical price boundaries.

Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
Trend Trigger (Bars)
//+------------------------------------------------------------------+
//|                                         Trend Trigger (Bars).mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Pink
#property indicator_color2 Aqua
//---- input parameters
extern int       TTFbars=15;
extern int       t3_period=5;
extern double    b=0.7;
//---- buffers
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];

// Variable Specific:
string IndicatorName = "py.TTF";
string Version = "S01";
double HighestHighRecent,
       HighestHighOlder,
       LowestLowRecent,
       LowestLowOlder,
       BuyPower,
       SellPower,TTF;
double t3,e1,e2,e3,e4,e5,e6,c1,c2,c3,c4,r,w1,w2,b2,b3;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, Red);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, White);
   SetIndexBuffer(1, ExtMapBuffer2);
//----
   SetIndexDrawBegin(0,10);
   SetIndexDrawBegin(1,10);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   
   b2 = b * b;
   b3 = b2 * b;
   c1 = (-b3);
   c2 = (3 * (b2 + b3));
   c3 = (-3) * (2 * b2 + b + b3);
   c4 = (1 + 3 * b + b3 + 3 * b2);

   r = t3_period;

   if (r < 1) r = 1;
   r = 1 + 0.5 * (r - 1);
   w1 = 2 / (r + 1);
   w2 = 1 - w1 ;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//---- 
   int limit = Bars-counted_bars-1;
   for(int i=limit; i>0; i--)
   {	
     HighestHighRecent = High[Highest(NULL,0,MODE_HIGH,TTFbars,i)];
	  HighestHighOlder = High[Highest(NULL,0,MODE_HIGH,TTFbars,i + TTFbars)];
	  LowestLowRecent = Low [Lowest(NULL,0,MODE_LOW,TTFbars,i)];
	  LowestLowOlder = Low [Lowest(NULL,0,MODE_LOW,TTFbars,i+TTFbars)];
	  BuyPower = HighestHighRecent - LowestLowOlder;
	  SellPower = HighestHighOlder - LowestLowRecent;
	  TTF = (BuyPower - SellPower) / (0.5 * (BuyPower + SellPower)) * 100;

	  e1 = w1 * TTF + w2 * e1;
	  e2 = w1 * e1 + w2 * e2;
	  e3 = w1 * e2 + w2 * e3;
	  e4 = w1 * e3 + w2 * e4;
	  e5 = w1 * e4 + w2 * e5;
	  e6 = w1 * e5 + w2 * e6;

	  TTF = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3;
     
     if (TTF >= 100) {
       ExtMapBuffer1[i]=Low[i];
       ExtMapBuffer2[i]=High[i];
     } 
     else if (TTF <= -100) {
       ExtMapBuffer1[i]=High[i];
       ExtMapBuffer2[i]=Low[i];
     } 
     else {
       ExtMapBuffer1[i]=Low[i];
       ExtMapBuffer2[i]=Low[i];
     } 
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments