ttf - trend trigger factor

 
this is an excellent indicator and wonder if someone can make it to MT4.

here what exactly is in MT3

/*[[
Name := Trend Trigger Factor (TTF)
Reference := Technical Analysis of Stocks and Commodities, Dec. 2004,
p.28.
Author := Paul Y. Shimada
Link := PaulYShimada@Y...
Separate Window := Yes
First Color := Aqua
First Draw Type := Line
First Symbol := 217
Use Second Data := Yes
Second Color := Red
Second Draw Type := Line
Second Symbol := 218
]]*/
Inputs:
TTFbars(15),
//15=default number of bars for computation

mode_0Sep_1Main(1),
//0=Separate window Line (with dual trigger)
//1=Main window Histogram (colored bars)

barBegin(1000),
//<1000 recommended for faster speed
//0=All bars computed & plotted

show_Info(0),
//0=Hide on-chart Info
//1=Show on-chart Info & Print Tick Data to Journal
//-1=NEVER show
;
Variables: //Specific
IndicatorName("py.TTF"),
Version("S01"),
HighestHighRecent(0),
HighestHighOlder(0),
LowestLowRecent(0),
LowestLowOlder(0),
BuyPower(0),
SellPower(0),
TTF(0),
;
Variables: //Generic, mostly for module flow control
shift(0),
count(0),
is_First(True),
loopBegin(0),
prevBars(0),
PrevTime(0),
tick(0),
prevShift(99999),
badPlotBars(0),//Discarded first (old) bars with bad computed values
firstPlotBar(0),
CheckSum(0),
CheckSumPrev(0),
Msg(""),
;
/*======================*/
/* Begin Pre-Loop Setup */
/*======================*/
//Check for additional bars loading or total reloadng.
If Bars<prevbars or Bars-prevbars>1 Then is_First=True;
prevbars=Bars;

//Have any Inputs changed?
CheckSum=TTFbars+mode_0Sep_1Main+barBegin+show_Info;
If CheckSum!=CheckSumPrev Then is_First=True;
CheckSumPrev=CheckSum;
//--------------------------------------------------------------------

If is_First Then
{ /*
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.
*/
SetLoopCount(0);

/*==============*/
/* Check Inputs */
/*==============*/
If 0>TTFbars or TTFbars>299 Then
{ Msg=IndicatorName+" **Input Error** :"
+" TTFbars must be between 0 and 300. Cannot="+TTFbars;
Exit;
};
If mode_0Sep_1Main<>0 and mode_0Sep_1Main<>1 Then
{ Msg=IndicatorName+" **Input Error** : "
+" and mode_0Sep_1Main must be {0,1}. Cannot="+mode_0Sep_1Main;
Alert(Msg);
Exit;
};

//Comment to display IndicatorName & parameters
Msg=IndicatorName+".v"+Version+"("+TTFbars+")";
Print(Msg);
If show_Info!=-1 Then Comment(Msg);

//Usage
if show_Info==1 Then
Comment(Msg
+" Trend Trigger Factor (TTF)"
+"\n User-Inputs:"
+"\nTTFbars:"
+"\n 15=default Number of bars for computation."
+"\nmode_0Sep_1Main:"
+"\n 0=Separate window Line with dual trigger"
+"\n TTF>+100=Long"
+"\n TTF<-100=Short"
+"\n Else=Ranging"
+"\n 1=Main window Histogram with colored bars"
+"\nbarBegin:"
+"\n <1000 recommended for faster computation"
+"\n 0=All bars computed & plotted (slower)"
+"\nshow_Info:"
+"\n 0=Hide on-chart Info"
+"\n 1=Show on-chart Info & Print Tick data to Journal"
+"\n -1=Never show Comments"
);

If barBegin>0 and barBegin<Bars-1 Then
loopBegin=barBegin
Else
loopBegin=Bars-1; /*BarIndexNumber=shift=Bars-1...0*/

/*===================================*/
/* Specific for particular indicator */
/*===================================*/
loopBegin=loopBegin-TTFbars;//Cannot compute early bars
/* end Specific */

is_First=False;
};//if is_First
/*======================*/
/* end Pre-Loop Setup */
/*======================*/

loopBegin=loopBegin+1; //Replot previous bar
For shift=loopBegin Downto 0
{
/*=================================*/
/* Standard Specific Computations */
/*=================================*/
HighestHighRecent=High[Highest(MODE_HIGH,shift ,TTFbars)];
HighestHighOlder =High[Highest(MODE_HIGH,shift+TTFbars,TTFbars)];
LowestLowRecent =Low [Lowest (MODE_LOW ,shift ,TTFbars)];
LowestLowOlder =Low [Lowest (MODE_LOW ,shift+TTFbars,TTFbars)];
BuyPower =HighestHighRecent-LowestLowOlder;
SellPower=HighestHighOlder -LowestLowRecent;
TTF=(BuyPower-SellPower)/(0.5*(BuyPower+SellPower))*100;

Switch mode_0Sep_1Main
{
Case 0: //Separate window Line (with dual trigger)
SetIndexValue(shift,TTF);
//Dual value trigger +/-100
If TTF>=0 Then SetIndexValue2(shift,100)
Else SetIndexValue2(shift,-100);

Case 1: //Main Window Colored Bars
If TTF>=100 Then //Bull Trend, Blue bars
{
SetIndexValue(shift,High[shift]);
SetIndexValue2(shift,Low[shift]);
}
Else
If TTF<=-100 Then //Bear Trend, Red bars
{
SetIndexValue(shift,Low[shift]);
SetIndexValue2(shift,High[shift]);
}
Else //No Trend, No colored bars
{
SetIndexValue(shift,0);
SetIndexValue2(shift,0);
}
};//If TTF>=100 Then ... Else
};//Switch mode_0Sep_1Main
loopBegin=loopBegin-1;
};//For shift=Bars-1 Downto 0
 
I ever saw that...
It is "excellent" because (in my mind) it has a big mistake :

HighestHighRecent=High[Highest(MODE_HIGH,shift ,TTFbars)];
...
LowestLowRecent =Low [Lowest (MODE_LOW ,shift ,TTFbars)];



Writed like that, these functions look forward (compute a current value
by using future ones) : take a look on

Highest  lowest

definitions in MQL3 dictionary.

Reason: