Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

phase21

Zero Lag Moving Averages

Recommended Posts

Hi All,

 

Having looked at the thread on Hull MA, I thought this might be of interest to others.

 

When I got interested in technical analysis, I was very keen on using indicators, etc, like most newbies, and came across the following formula for significantly reducing the lag inherent in moving averages.

 

That was a while ago, and am now more interested in reading price and volume, but thought others might be able to make better use of it than I have.

 

The basic formula is:

&EMAOne := MovingAvgMethod (Close , Periods , 2)

&EMATwo := MovingAvgMethod (&EMAOne , Periods , 2)

&Diff := &EMAOne - &EMATwo

&EMAOne + &Diff

 

Replace "MovingAvgMethod" with whatever MA you prefer.

 

And here's a pic comparing several different MAs with/out Zero Lag, including Hull:

attachment.php?attachmentid=12539&stc=1&d=1248896583

 

Regards,

ZeroLagMAs.thumb.PNG.12605083171c7fc5541bf349589eb2d6.PNG

Share this post


Link to post
Share on other sites

Hello Minetoo,

 

The code I posted above is a direct copy from a function in Trade Navigator. I use TN for trading and quick prototyping of ideas. You can define functions in TN, but it doesn't have a programming language to speak of.

 

However, you should be able to plonk this code/algorithm into a template you use for defining functions in your favourite software, hence no "*.eld". :(

 

But, below is some code which does the same thing in AmiBroker. AB has a "C"-like programming language.

 

Define the function:

/*=============================================================================

Zero-Lag Moving Averages

 

This AFL contains functions to calc moving averages with minimal lag.

=============================================================================*/

 

//-----------------------------------------------------------------------------

function ZeroLagMovingAvg(ValToSmooth, BarsToUse)

/*

This AFL smooths the input data, and then removes as much lag as possible.

 

Note: Original source of the formula not known.

-----------------------------------------------------------------------------*/

{

// Declare local variables

local result ;

local MAOne ;

local MATwo ;

local MADiff ;

 

// Initialise the local variables.

result = Null ;

 

// Your code goes in here

MAOne = MA(ValToSmooth , BarsToUse) ;

MATwo = MA(MAOne , BarsToUse) ;

MADiff = MAOne - MATwo ;

result = MAOne + MADiff ;

 

// Declare which variable/value to be returned to the user/calling function

return result ;

}

 

 

Call the function:

/*=============================================================================

Zero-Lag Moving Averages

 

This AFL plotts the moving averages with minimal lag.

=============================================================================*/

 

#pragma nocache ;

#include_once <ZeroLagMovingAvg.afl> ;

 

ValToSmooth = ParamField("Price field", 3) ;

BarsToUse = Param("Bars to use", 13, 2, 1000, 1, 1) ;

SmoothedVal = ZeroLagMovingAvg(ValToSmooth, BarsToUse) ;

 

Plot(SmoothedVal, "ZeroLagMovingAvg", colorBlue, styleLine | styleDots | styleThick, 0, 0, 0) ;

 

 

Note: I tend to define things as componentised as possible, a-la building blocks, and draw them all together as late as possible/appropriate. That way I can separate the visuals from the calcs.

 

 

Regards,

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.