Instantaneous Trend
The Instantaneous Trend AFL code for Amibroker, combined with Amibroker Data Feeder, is a powerful tool for traders. It calculates the trend’s instantaneous direction, allowing traders to identify trend changes promptly. When paired with real-time market data from Amibroker Data Feeder, this code becomes more efficient, providing traders with accurate trend signals for making informed entry and exit decisions.
/ SetBarsRequired(200, 0); // Ehlers formulas // from Ehlers, John F. Cybernetic Analysis for Stocks and Futures. Wiley. 2004. // Chapter 1, p. 1. Code on p. 7. function InverseFisher(array) { e2y = exp(2 * array); return (e2y - 1)/(e2y + 1); } function Normalize(array, arraylen) // Figure 1.7 on p. 7 { MaxH = HHV(array, arraylen); MinL = LLV(array, arraylen); Value1[0] = array[0]; // Initialize as array for(i = 1; i < BarCount; i++) { Value1[i] = .5 * 2 * ((array[i] - MinL[i]) / (MaxH[i] - MinL[i]) - .5) + .5 * Value1[i-1]; if (Value1[i] > .9999) Value1[i] = .9999; if (Value1[i] < -.9999) Value1[i] = -.9999; } return Value1; } function Fisher(array) // Figure 1.7 on p. 7 { F = array; F = .25 * log((1+ array)/(1 - array)) + .5 * Ref(F, -1); return F; } Med = (H+L)/2; // Fisher Transform FisherXform = Fisher(Normalize(Med, 10)); //Plot(FisherXform, "Fisher Transform", colorRed, styleLine); //Plot(Ref(FisherXform, -1), "", colorBlue, styleLine); //PlotGrid(2); //PlotGrid(-2); col_bar = IIf(FisherXform > Ref(FisherXform,-1),colorGreen, colorRed); _SECTION_END(); _SECTION_BEGIN("Ehlers Instantaneous Trend"); //------------------------------------------------------------------------------ // // Formula Name: Ehlers Instantaneous Trend // Author/Uploader: Not Too Swift // E-mail: // Date/Time Added: 2005-03-20 00:25:13 // Origin: // Keywords: // Level: medium // Flags: indicator // Formula URL: http://www.amibroker.com/library/formula.php?id=444 // Details URL: http://www.amibroker.com/library/detail.php?id=444 // //------------------------------------------------------------------------------ // // This is a zero lag trend indicator with an interesting predictive trigger. // //------------------------------------------------------------------------------ SetBarsRequired(200, 0); // Ehlers ITrend // from Ehlers, John F. Cybernetic Analysis for Stocks and Futures. Wiley. 2004. // Chapter 3, p. 21. Code on p. 24. function ITrend(array, alpha) { // initialize early array values and declare as array it = array; //it = (array[2] - 2*array[1] + array[0])/4; This initialization takes a long time to converge. for(i = 2; i < BarCount; i++) { it[i] = (alpha - alpha*alpha/4)*array[i] + .5*alpha*alpha*array[i-1] - (alpha - .75*alpha*alpha)*array[i-2] + 2*(1 - alpha)*it[i-1] - (1 - alpha)*(1 - alpha)*it[i-2]; } return it; } function ITrendTrigger(array) { trigger = 2*array - Ref(array, -2); return trigger; } Med = (H+L)/2; Plot(C,"close",col_bar,styleCandle); // Instantaneous Trend Plot(Med, "", colorBlack, styleLine); trend = ITrend(Med, .07); Plot(trend, "ITrend", colorBlue, styleLine); Plot(ITrendTrigger(trend), "", colorRed, styleLine); _SECTION_END(); _SECTION_BEGIN("Fibo for all bars"); TimeFrameSet( in15Minute*2 ); DH=Ref(H,-1); DL=Ref(L,-1); DC=Ref(C,-1); pd = (O+ DH+ DL + DC )/4; sd1 = (2*pd)-DH; sd2 = pd -(DH - DL); sd3 = Sd1 - (DH-DL); rd1 = (2*pd)-DL; rd2 = pd +(DH -DL); rd3 = rd1 +(DH-DL); //Plot (pd,"Pivot",colorBlue,styleDots); //Plot (rd1," R1 ",35,styleDots); //Plot (rd2," R2 ",35,styleDots); //Plot (rd3," R3 ",35,styleDots); //Plot (sd1," S1 ",4,styleDots); //Plot (Sd2," S2 ",4,styleDots); //Plot (Sd3," S3 ",4,8+16); /* style = IIf(ParamList("Chart style", "styleCandle|styleBar")=="styleCandle",64,128+4); Plot (C,Date ()+" close",1,style); //ENABLE THIS TO HAVE CANDLES AS WELL */ TimeFrameRestore(); Title = EncodeColor(colorWhite)+ "LINKON'S PIVOT TRADING SYSTEM" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) + " - " + Date() +" - " //+ WriteIf(Col_action==colorGreen, EncodeColor(colorGreen)+"stay LONG","")+ WriteIf(Col_action==colorRed, EncodeColor(colorRed)+"stay SHORT","")+ WriteIf(Col_action==colorBlack, EncodeColor(colorYellow)+"No Trend","")+"\n" + "Vol= "+ WriteVal(V) +WriteIf ( V > MA(V,26) ,EncodeColor(colorGreen)+" UP "+ (V/MA(V,26))*100 + " %", EncodeColor(colorRed)+" DOWN "+ (V/MA(V,26))*100 + " %") + EncodeColor(colorGreen)+ "\n R3 : "+ EncodeColor(colorWhite)+RD3 + EncodeColor(colorGreen)+ "\n R2 : "+ EncodeColor(colorWhite)+RD2 + EncodeColor(colorGreen)+ "\n R1 : "+ EncodeColor(colorWhite)+RD1+ EncodeColor(colorGreen)+ "` Hi: "+ EncodeColor(colorWhite)+H + EncodeColor(colorBlue)+ "\n Pivot : "+ EncodeColor(colorWhite)+pd + EncodeColor(colorYellow)+ "` Op: "+ EncodeColor(colorWhite)+O+ EncodeColor(colorAqua)+ "Cl: "+ EncodeColor(colorBrightGreen)+C + EncodeColor(colorRed)+ "\n S1 : "+ EncodeColor(colorWhite)+SD1+ EncodeColor(colorRed)+ "` Lo: "+ EncodeColor(colorWhite)+L + EncodeColor(colorRed)+ "\n S2 : "+ EncodeColor(colorWhite)+SD2 + EncodeColor(colorRed)+ "\n S3 : "+ EncodeColor(colorWhite)+SD3 ; _SECTION_END();