Skip to main content

Zero lag indicator for Amibroker (AFL)

konidena over 15 years ago Amibroker (AFL)

  • Rating:
    3 / 5 (Votes 6)
  • Tags:
    amibroker, moving average, zero lag

FRom S& C mag of November 2010. Hope You will like it
Subrahmanyam

Indicator / Formula

Copy & Paste Friendly
_SECTION_BEGIN("Zero Lag Indicator");
// Zero-Lag Indicator for AmiBroker 
// TASC Traders Tips November 2010 
// 

Length = Param("Length", 32, 0, 100 ); 
GainLimit = Param("Gain limit", 22, 1, 100 ); 
Threshold = Param("Threshold", 0.75, 0.1, 10, 0.01 ); 

alpha = 2 / ( Length + 1 ); 

iEMA = AMA( Close, alpha ); 

EC = Close[ 0 ]; 

for( bar = 0; bar < BarCount; bar++ ) 
{ 
 EC1 = EC; 

 LeastError = 1e9; 
 BestEC = 0; 

 for( gain = -0.1 * GainLimit; gain < 0.1 * GainLimit; gain += 0.1 ) 
 { 
   EC = alpha * ( iEMA[ bar ] + gain * ( Close[ bar ] - EC1 ) ) + 
       ( 1 - alpha ) * EC1; 

   Error = abs( Close[ bar ] - EC ); 

   if( Error < LeastError ) 
   { 
    LeastError = Error; 
    BestEC = EC; 
   } 
 } 
 iEC[ bar ] = BestEC;   
 iLeastError[ bar ] = LeastError; 
} 
Plot( iEMA, "EMA", colorRed ); 
Plot( iEC, "EC" + _PARAM_VALUES(), colorYellow, styleThick ); 
Plot( C, "Close", ParamColor("Color", colorGreen ), ParamStyle("Style") | GetPriceStyle() ); 

// strategy rules 
Buy = Cross( iEC, iEMA ) AND 100 * iLeastError / Close > Threshold; 
Short = Cross( iEMA, iEC ) AND 100 * iLeastError / Close > Threshold; 
Sell = Short; 
Cover = Buy; 
PlotShapes( IIf( Buy, shapeDigit9 + shapePositionAbove, shapeNone ), colorGreen ); 
// trade on next bar open 
SetTradeDelays( 1, 1, 1, 1 ); 
BuyPrice = SellPrice = CoverPrice = ShortPrice = Open; 
_SECTION_END();

3 comments

over 15 years ago

Hello Ayuraveda,

Magazines are prepared at least 1 month in advance, for reasons that you might guess.
Traders’tips (from S & C mag), provides nearly every month some interesting formulas.
Here is the link for Zero lag indicator: http://www.traders.com/Documentation/FEEDbk_docs/2010/11/TradersTips.html

Thank you Konidena for this formula.

Regards,

3. iwan
over 15 years ago

It’s a good AFL. I’like to combine with one of the Gupp AFl.
So, very powerfull. Thank’s a lot for contribution AFL.

Regards,

Leave Comment

Please login here to leave a comment.