/*[[ Name := Trend Trigger Modified Reference := Technical Analysis of Stocks and Commodities, Dec. 2004,p.28. M.H. Pee TTF Author := Paul Y. Shimada Link := PaulYShimada@Y... Notes := Modified version of Trend Trigger Factor by mikesbon (thanks to perkyz) Separate Window := Yes First Color := SkyBlue First Draw Type := Line First Symbol := 217 Use Second Data := Yes Second Color := LightSeaGreen Second Draw Type := Line Second Symbol := 218 ]]*/ Input: TTFbars(15); //15=default number of bars for computation. Input: t3_period(5); Input: b(0.7); Input: mode_0Sep_1Main(0); //0=Separate window Line (with dual trigger), 1=Main window Histogram (colored bars). Input: barBegin(1000); //<1000 recommended for faster speed, 0=All bars computed & plotted. Input: show_Info(0); //0=Hide on-chart Info, 1=Show on-chart Info & Print Tick Data to Journal, -1=NEVER show. // Variable Specific: Variable: IndicatorName("py.TTF"); Variable: Version("S01"); Variable: HighestHighRecent(0); Variable: HighestHighOlder(0); Variable: LowestLowRecent(0); Variable: LowestLowOlder(0); Variable: BuyPower(0); Variable: SellPower(0); Variable: TTF(0); Variable: t3(0); Variable: e1(0); Variable: e2(0); Variable: e3(0); Variable: e4(0); Variable: e5(0); Variable: e6(0); Variable: c1(0); Variable: c2(0); Variable: c3(0); Variable: c4(0); Variable: r(0); Variable: w1(0); Variable: w2(0); Variable: b2(0); Variable: b3(0); // Variable Generic, mostly for module flow control: Variable: shift(0); Variable: count(0); Variable: is_First(True); Variable: loopBegin(0); Variable: prevBars(0); Variable: PrevTime(0); Variable: tick(0); Variable: prevShift(99999); Variable: badPlotBars(0); //Discarded first (old) bars with bad computed values Variable: firstPlotBar(0); Variable: CheckSum(0); Variable: CheckSumPrev(0); Variable: Msg(""); 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 then 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 or Bars - prevbars > 1 Then is_First = True; prevbars = Bars; //Have any Inputs changed? CheckSum = TTF + 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)" + "\nUser-Inputs:" + "\nTTFbars:" + "\n15=default Number of bars for computation." + "\nmode_0Sep_1Main:" + "\n0=Separate window Line with dual trigger" + "\nTTF>+100 = Long" + "\nTTF<-100 = Short" + "\nElse=Ranging" + "\n1=Main window Histogram with colored bars" + "\nbarBegin:" + "\n<1000 recommended for faster computation" + "\n0=All bars computed & plotted (slower)" + "\nshow_Info:" + "\n0=Hide on-chart Info" + "\n1=Show on-chart Info & Print Tick data to Journal" + "\n-1=Never show Comments"); //BarIndexNumber=shift=Bars-1..0 If barBegin > 0 and barBegin < Bars - 1 Then loopBegin = barBegin Else loopBegin = Bars - 1; /*===================================*/ /* 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; 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; SetIndexValue(shift,TTF); 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; };