BtTT-S
Download scriptThe BtTrendTrigger is a technical analysis tool designed to identify and visualize market trends by measuring the momentum between recent price action and historical price boundaries. Unlike simple moving averages that follow price, this script focuses on "power dynamics"—analyzing who is currently in control: the buyers or the sellers.
Core Logic and Mechanism
The logic operates through a multi-stage calculation process to smooth out market noise and pinpoint significant trend shifts:
1. Momentum Calculation (Buy vs. Sell Power) The tool looks at a specific window of recent price bars (determined by user settings). It identifies the highest high and lowest low within that "recent" window and compares them against the highest high and lowest low of the "older" period immediately preceding it.
- Buy Power: Measures the distance from the older low to the recent high.
- Sell Power: Measures the distance from the older high to the recent low.
By comparing these two values, the script calculates a Trend Trigger Factor (TTF). This factor represents the percentage of dominance; a positive value indicates bullish pressure, while a negative value indicates bearish pressure.
2. Smoothing and Signal Refinement To prevent the indicator from reacting erratically to minor price fluctuations, the raw TTF undergoes a series of mathematical smoothing steps (similar to an Exponential Moving Average). This filters out "jitter" and ensures that only sustained movements in price momentum are captured.
The script then applies a final weighting calculation to refine the curve, resulting in a smoother line that reflects the underlying trend's strength more clearly.
3. Signal Generation (The Triggers) The primary goal of the indicator is to provide visual cues for potential trend reversals or continuations based on specific thresholds:
- Bullish Signals: The tool monitors when the smoothed value crosses from a negative state into a positive state, or when it breaks above a specific upper threshold (the "Positive" limit). When these conditions are met, it marks a point on the chart to alert the user of upward momentum.
- Bearish Signals: Conversely, it tracks when the value drops below a lower threshold (the "Negative" limit) or crosses from positive to negative. These actions trigger markers indicating downward pressure.
Summary for the User
In simple terms, this script acts as a momentum gauge. It looks at how much "effort" buyers are exerting compared to sellers over a set period of time. By smoothing this data, it identifies the moment when one side clearly overtakes the other. On your chart, this translates to visual markers that highlight where the trend is gaining strength or where a significant shift in momentum may be occurring.
//+------------------------------------------------------------------------+
//| MQL to MQ4 by Maloma BtTrendTrigger-T.mq4 |
//| Modified version of Trend Trigger Factor by Tartan |
//| Technical Analysis of Stocks and Commodities, Dec. 2004,p.28. M.H. Pee |
//+------------------------------------------------------------------------+
#property copyright "Paul Y. Shimada"
#property link "PaulYShimada@Y..."
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Gold
#property indicator_color2 Red
#include <stdlib.mqh>
#include <stderror.mqh>
//---- indicator parameters
extern int TTFbars=15; //15=default number of bars for computation.
extern int t3_period=5;
extern double b=0.7;
extern int ppor=50;
extern int mpor=-50;
extern int barBegin=1000; //<1000 recommended for faster speed, 0=All bars computed & plotted.
//---- indicator buffers
double Buffer1[],B1[];
double Buffer2[],B2[];
// Variable Specific:
string IndicatorName="py.TTF";
string Version="S01(MQL4 by maloma)";
double HighestHighRecent=0, HighestHighOlder=0, LowestLowRecent=0, LowestLowOlder=0;
double BuyPower=0, SellPower=0, TTF=0, ks = 0, kb = 0, kss = 0, ksb = 0;
double t3=0, e1=0, e2=0, e3=0, e4=0, e5=0, e6=0, c1=0, c2=0, c3=0, c4=0, r=0, w1=0, w2=0, b2=0, b3=0;
double ATTF[];
int m = 0;
// Variable Generic, mostly for module flow control:
int shift=0, count=0;
bool is_First=True;
int loopBegin=0, prevBars=0, PrevTime=0, tick=0, prevShift=99999, firstPlotBar=0, badPlotBars=0; //Discarded first (old) bars with bad computed values
double CheckSum=0, CheckSumPrev=0;
string Msg="";
int init()
{
//---- indicator buffers mapping
SetIndexBuffer(0,B1);
SetIndexBuffer(1,B2);
//---- drawing settings
SetIndexStyle(0,DRAW_LINE,EMPTY,2);
SetIndexArrow(0,217);
SetIndexStyle(1,DRAW_LINE,EMPTY,2);
SetIndexArrow(1,218);
//----
SetIndexEmptyValue(0,EMPTY_VALUE);
SetIndexEmptyValue(1,EMPTY_VALUE);
//---- name for DataWindow
SetIndexLabel(0,"BTT1");
SetIndexLabel(1,"BTT2");
//---- initialization done
IndicatorShortName("BtTrendTrigger");
ArrayResize(ATTF,barBegin);
return(0);
}
int start()
{
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;
/*======================*/
/* Begin Pre-Loop Setup */
/*======================*/
//Check for additional bars loading or total reloadng.
if (Bars < prevBars || Bars - prevBars > 1) is_First = True;
prevBars = Bars;
//Have any Inputs changed?
CheckSum = TTF + barBegin;
if (CheckSum != CheckSumPrev) is_First = True;
CheckSumPrev = CheckSum;
//--------------------------------------------------------------------
if (is_First)
{/*This block executes ONLY First Time for each Attachment-To-Chart. If MT is closed or another Profile is selected,
the values & parameters for this module are saved, and when MT or this Profile is restarted, it would not be the First
Time Attachment-To-Chart. So this block would not execute unless the value of "Bars" has changed. */
int SetLoopCount=0;
/*==============*/
/* Check Inputs */
/*==============*/
if (0 > TTFbars || TTFbars > 299)
{
Msg = IndicatorName + " **Input Error** :" + " TTFbars must be between 0 and 300. Cannot=" + TTFbars;
Alert(Msg);
return(0);
}
//BarIndexNumber=shift=Bars-1..0
if (barBegin > 0 && barBegin < Bars - 1) {loopBegin = barBegin;} else {loopBegin = Bars - 1;}
/*===================================*/
/* Specific for particular indicator */
/*===================================*/
loopBegin = loopBegin - TTFbars; //Cannot compute early bars
/* end Specific */
is_First = False;
}
/*======================*/
/* end Pre-Loop Setup */
/*======================*/
loopBegin = loopBegin + 1; //Replot previous bar
m=0;
for (shift = loopBegin; shift>=0; shift--)
{m=m+1;
/*=================================*/
/* Standard Specific Computations */
/*=================================*/
HighestHighRecent = High[Highest(Symbol(),0,MODE_HIGH,TTFbars,shift-TTFbars+1)];
HighestHighOlder = High[Highest(Symbol(),0,MODE_HIGH,TTFbars,shift+1)];
LowestLowRecent = Low [Lowest(Symbol(),0,MODE_LOW,TTFbars,shift-TTFbars+1)];
LowestLowOlder = Low [Lowest(Symbol(),0,MODE_LOW,TTFbars,shift+1)];
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;
Buffer1[shift-1]=TTF;
ATTF[m]=TTF;
if( (ATTF[m-1]<ATTF[m] && ATTF[m]<ppor && ATTF[m-1]>0) ) kb=0;
if( (ATTF[m-1]>ATTF[m] && ATTF[m]>mpor && ATTF[m-1]<0) ) ks=0;
if( (ATTF[m-1]<0 && ATTF[m]>0) ) ksb=0;
if( (ATTF[m-1]>0 && ATTF[m]<0) ) kss=0;
if( ATTF[m-1]<mpor && ATTF[m]>mpor && kb == 0 ) { kb=1;B1[shift]=Low[shift]-6*Point;}
if( ((ATTF[m-1]>ppor && ATTF[m]<ppor) || (ATTF[m-1]>0 && ATTF[m]<0)) && ksb == 0 ) {
ksb=1;B1[shift]=High[shift];}
if( ATTF[m-1]>ppor && ATTF[m]<ppor && ks == 0 ) { ks=1;B2[shift]=High[shift]+6*Point;}
if( ((ATTF[m-1]<mpor && ATTF[m]>mpor) || (ATTF[m-1]<0 && ATTF[m]>0)) && kss == 0 ) {
kss=1;B2[shift]=Low[shift];}
//Dual value trigger +/-100
if (TTF >= 0) {Buffer2[shift-1]=ppor;} else {Buffer2[shift-1]=mpor;}
Comment(shift," ",m," ",ATTF[m]);
}
return(0);
}
Comments