Nyquist-Shannon Moving Average

User avatar
simplex
Trader
Posts: 127
Joined: Thu Feb 07, 2013 5:21 pm
Location: An insignificant small town close to an insignificant former capital at the Rhine River.

Nyquist-Shannon Moving Average

Post by simplex »

Hi Everybody!

Some days ago I came across a paper of Dr. Manfred Dürschner titled 'Moving Averages 3.0'. This title as well as the fact that in 2011 the author received a First prize of VTAD Award (German Association of Technical Analysts) for this particular paper got my attention. So I started to code the indicators Dr. Dürschner proposed in mq4.

Find his paper here to download:
http://www.vtad.de/sites/files/forschun ... itte_3.pdf
I only found it in German - so good luck out there! :D

Core indicator is a moving average that follows the Nyquist-Shannon sampling theorem (see: http://en.wikipedia.org/wiki/Nyquist%E2 ... ng_theorem). The Nyquist MA is being composed of a single smoothed and a double smoothed LWMA which finally are mapped by the formula NMAW = (alpha+1) * MA1 - alpha * MA2, where alpha is a function of the sampling frequencies of the LWMAs - see program code for details.

Dr. Dürschner cites John Ehlers' 2001 paper 'Signal Analysis Concepts' and points out, that Ehlers' Zero Lag MA presented in this paper violates the Nyquist-Shannon sampling theorem. I will check this out later and code Ehlers' ZeroLag with a correction according to Nyquist-Shannon and see what happens as compared with the original. (Correction: I re-read Ehlers' article and did not find any MA described in detail here. On p. 3 there is only a theoretical concept for a zero lag MA. Ehlers describes a double smoothed MA where both stages produce the same amount of lag, i.e. must have the same averaging length. This really would be a violation of Nyquist-Shannon, but has nothing to do with the well-known Ehlers' ZeroLag MA. This is not based on a double smoothing concept, but on an adaptive error correction of a standard EMA. Sorry for the confusion - it was late last night! :roll: )

In short, the theorem says that when one MA is being sampled onto its own signal the sampling period of the second MA must not be larger that half the period of the first MA. A violation of this law can lead to 'ghost signals' like Moiré patterns some of you might know from digital photography (see wikipedia link for an example).

Describing two 'Trading Systems' that consist only of one oscillator each Dr. Dürschner proposed the following algorithms:

1. An Aroon Oscillator(5) placed over a Nyquist MA(89, 21) output and sharpened by an Inverse Fisher Transform.

2. A Stochastic-RSI (Stoch 3, RSI 5) placed over Nyquist MA(8, 3) output and sharpened by an Inverse Fisher Transform.

He proposed the Aroon for medium term trading on daily stock charts, the SRSI for short term trading on M15 DAX papers.

The backtesting results he describes are outstanding (104 individual tests on stock titles over 11 years). Average net profits 4600% based on Nyquist MA, 1200% based on Ehlers' MA, 800% based on LWMA, 110% Buy&Hold. My personal opinion: I do not think that it's legitimate to compare the results in this manner, because he choose equal periodicity (89 cycles) for each of the MAs used. IMO the MAs should have been adjusted in a way that all of them show similar smoothing, which definitely is not the case for the above mentioned settings.

Anyway ...

... to check usability for FX I also coded both oscillators based on a standard iMA so we can compare them with the Nyquist results. See following image:
screen_nyquist.JPG
I chose AUDCHF on H1 because it showed a rather clear picture last week - didn't want things to become too complicated for a start. Then I placed a Nyquist MA(32, 8, LWMA, Close) on the chart - see green line. This may be compared with the standard LWMA(6, Close) - see violet line. There's not much of a difference, IMO.

Next are both Stochastic RSI(Stoch 3, RSI 5): based on Nyquist(32, 8, Typical) in blue and LWMA(15, Typical) in green. I tuned both frequencies in a way that they fit the peak on June 27, 11:00 very timely. Doing so, the Nyquist variant gives most signals one or two bars before the iMA variant, but also shows significantly more whipsaw signals (grey rectangles).

For the Aroon Oscillator I followed Dr. Dürschner's proposal for 89 periods primary smoothing and 21 periods secondary, both LWMA on Median. Then I tuned the iMA-based Aroon to the very same base frequency: LWMA(21, Median). Both Aroons show very similar results, the Nyquist variant signaling 1 bar earlier in average.

My personal conclusion: I do not see a real added value in the Nyquist based oscillators as compared with the iMA based ones - which are easier to realize and consume fewer computer ressources. But the signals produced seem to be clear and timely, it might be possible to integrate them in a trading system successfully.

Call for German speaking coders: if you like to, please have a closer look at the original paper, and compare the algorithm details with my code. Maybe I didn't get every detail correctly and we can further optimize the results. Any feedback appreciated!

Experienced traders: I would be interested in your opinion about the usability of these indicators for practical trading, maybe in an EA.

Indicators' details:

General:
priceUsed: price constant
maMode: iMA constant

Nyquist MA:
priPeriod: Nyquist primary (if 0: set default = 4.0 * secPeriod)
secPeriod: Nyquist secondary period

Stochastic RSI:
rsiPeriod: RSI period
stochPeriod: stochastic fastK period
useFisher: use inverse Fisher transform or don't
useProxy: use price proxy or direct price array

Aroon parameters:
aroonPeriod: Aroon period
showNyquistFisher: show Inverse Fisher Transform based on Aroon(Nyquist MA)
showDirectFisher : show Inverse Fisher Transform based on Aroon(price array)
showNyquistAroon : show Aroon(Nyquist MA) without IFT
showDirectAroon : show Aroon(price array) without IFT

Now: play with the tools & have fun!

Jürgen

Addendum:

I found an English language version of Dr. Dürschner's paper in 2012 issue of IFTA Journal, downloadable here:
http://www.ifta.org/publications/journal/
You do not have the required permissions to view the files attached to this post.
Last edited by simplex on Thu Jul 04, 2013 5:17 pm, edited 2 times in total.
If you can't explain it simply, you don't understand it well enough. (Albert Einstein)
It appears that the Weighted Moving Average was invented by a trader who did not have a firm grasp of filter theory in hopes of reducing lag. (John F. Ehlers)
User avatar
Jemook
Trader
Posts: 1085
Joined: Thu May 10, 2012 10:19 am
Location: Bondi, Sydney, Australia

Re: Nyquist-Shannon Moving Average

Post by Jemook »

Jürgen love the detail you went into with this. German engineering at it's finest :)
Please note I am no longer affiliated with Global Prime. I've moved on to my next adventure with Afterprime.

Catch me here: https://www.afterprime.com
garyfritz

Re: Nyquist-Shannon Moving Average

Post by garyfritz »

simplex wrote:Core indicator is a moving average that follows the Nyquist-Shannon sampling theorem. The Nyquist MA is being composed of a single smoothed and a double smoothed LWMA which finally are mapped by the formula NMAW = (alpha+1) * MA1 - alpha * MA2, where alpha is a function of the sampling frequencies of the LWMAs - see program code for details.
Yikes! I thought you were going to translate it into English. :lol:

I have a weak understanding of Nyquist-Shannon sampling, and some familiarity with Ehlers' ZeroLag, but not enough to comment very intelligently on your analysis, unfortunately.
Dr. Dürschner cites John Ehlers' 2001 paper 'Signal Analysis Concepts' and points out, that Ehlers' Zero Lag MA presented in this paper violates the Nyquist-Shannon sampling theorem.
What exactly do you mean that it violates N-S sampling? Are you saying the ZeroLag calculation samples more than half the period of the first MA?
My personal opinion: I do not think that it's legitimate to compare the results in this manner, because he choose equal periodicity (89 cycles) for each of the MAs used. IMO the MAs should have been adjusted in a way that all of them show similar smoothing, which definitely is not the case for the above mentioned settings.
Yes, definitely. Not all averages respond the same as an SMA.
Doing so, the Nyquist variant gives most signals one or two bars before the iMA variant, but also shows significantly more whipsaw signals (grey rectangles).
That was also my immediate impression. I suspect you could get similar quicker signals with more whipsaws just by using a shorter length on a more traditional MA.

Gary
User avatar
simplex
Trader
Posts: 127
Joined: Thu Feb 07, 2013 5:21 pm
Location: An insignificant small town close to an insignificant former capital at the Rhine River.

Re: Nyquist-Shannon Moving Average

Post by simplex »

garyfritz wrote:
simplex wrote:Dr. Dürschner cites John Ehlers' 2001 paper 'Signal Analysis Concepts' and points out, that Ehlers' Zero Lag MA presented in this paper violates the Nyquist-Shannon sampling theorem.
What exactly do you mean that it violates N-S sampling? Are you saying the ZeroLag calculation samples more than half the period of the first MA?
Gary
Dr. Dürschner doesn't really give much detail on this particular issue. That's what I meant when I stated I would take Ehlers' ZeroLag MA and check it out ... later this week ... now it's 2:30 am and I feel like catching some sleep!

cu, Jürgen
If you can't explain it simply, you don't understand it well enough. (Albert Einstein)
It appears that the Weighted Moving Average was invented by a trader who did not have a firm grasp of filter theory in hopes of reducing lag. (John F. Ehlers)
User avatar
simplex
Trader
Posts: 127
Joined: Thu Feb 07, 2013 5:21 pm
Location: An insignificant small town close to an insignificant former capital at the Rhine River.

Re: Nyquist-Shannon Moving Average

Post by simplex »

simplex wrote:
garyfritz wrote:
simplex wrote:Dr. Dürschner cites John Ehlers' 2001 paper 'Signal Analysis Concepts' and points out, that Ehlers' Zero Lag MA presented in this paper violates the Nyquist-Shannon sampling theorem.
What exactly do you mean that it violates N-S sampling? Are you saying the ZeroLag calculation samples more than half the period of the first MA?
Gary
Dr. Dürschner doesn't really give much detail on this particular issue. That's what I meant when I stated I would take Ehlers' ZeroLag MA and check it out ... later this week ... now it's 2:30 am and I feel like catching some sleep!

cu, Jürgen
Gary,

I posted a correction in post 1 - this has nothing to do with the well known Ehlers ZeroLag MA. Just a theoretical concept Ehlers described and Dr. Dürschner relates to.

Regards, Jürgen
If you can't explain it simply, you don't understand it well enough. (Albert Einstein)
It appears that the Weighted Moving Average was invented by a trader who did not have a firm grasp of filter theory in hopes of reducing lag. (John F. Ehlers)
Profitiser
Posts: 2
Joined: Tue Jun 12, 2012 4:55 pm

Re: Nyquist-Shannon Moving Average

Post by Profitiser »

simplex wrote:Hi Everybody!

Some days ago I came across a paper of Dr. Manfred Dürschner titled 'Moving Averages 3.0'. This title as well as the fact that in 2011 the author received a First prize of VTAD Award (German Association of Technical Analysts) for this particular paper got my attention. So I started to code the indicators Dr. Dürschner proposed in mq4. ....
Hi Simplex,
thanx for these indis. It seems really that you are the first having implemented Duerschners indis in mq4. I also like your mqh - approach of function implementation.

Nevertheless I couldn't start Nyquist the indis up to now. I could compile them in the editor but the ex4 file couldn't be opened in my Empty4 client (I am using an XTB client; as German you probably know the XTB broker). Any idea for a solution ? I'll check the maths once more as you requested.
User avatar
simplex
Trader
Posts: 127
Joined: Thu Feb 07, 2013 5:21 pm
Location: An insignificant small town close to an insignificant former capital at the Rhine River.

Re: Nyquist-Shannon Moving Average

Post by simplex »

Profitiser wrote:Hi Simplex,
thanx for these indis. It seems really that you are the first having implemented Duerschners indis in mq4. I also like your mqh - approach of function implementation.

Nevertheless I couldn't start Nyquist the indis up to now. I could compile them in the editor but the ex4 file couldn't be opened in my Empty4 client (I am using an XTB client; as German you probably know the XTB broker). Any idea for a solution ? I'll check the maths once more as you requested.
Hi Profitiser,

sorry for my late answer - have been quite busy last week (non FX).

Any messages after compilation?
Did you try it on a different client? I didn't have any problems running them on Alpari UK and Global Prime.

IMO there's nothing really special in my coding, so at the moment I have no idea why they don't run on your client.

Let's stay in touch. I would also be interested in your proceedings to make it run.

simplex
If you can't explain it simply, you don't understand it well enough. (Albert Einstein)
It appears that the Weighted Moving Average was invented by a trader who did not have a firm grasp of filter theory in hopes of reducing lag. (John F. Ehlers)
emiko
Posts: 6
Joined: Tue Aug 20, 2013 2:26 am

Re: Nyquist-Shannon Moving Average

Post by emiko »

Thanks for provision i will give it a try, cheers.
forexlover
Posts: 2
Joined: Tue Aug 27, 2013 8:56 am

Nyquist-Shannon Moving Average

Post by forexlover »

Hi all.. Thanks for the indicator.. I use mobing averages and this idea looks great. I downloaded your indicator but i cannot load it on my chart. I use hotforex platform. What am i missing?
User avatar
renexxxx
Trader
Posts: 860
Joined: Sat Dec 31, 2011 3:48 am

Nyquist-Shannon Moving Average

Post by renexxxx »

forexlover » Sun Oct 18, 2015 10:23 pm wrote:Hi all.. Thanks for the indicator.. I use mobing averages and this idea looks great. I downloaded your indicator but i cannot load it on my chart. I use hotforex platform. What am i missing?
Try it with the attached .mqh in the \Include folder. Since v600 and above, the compiler has changed dramatically. Eg. the enum type identifier was introduced and therefore it became a reserved word. I have just renamed the enum variable in the attached file, and all compiles well. There were a few compiler warnings in the StochRSI-indicators, and I have removed those as well.
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Indicators”