Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, SBGuy, TipmyPip, ozgur), 923 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
LowPass vs EMA #425051
06/25/13 21:39
06/25/13 21:39
Joined: Jun 2013
Posts: 3
P
pstoto76 Offline OP
Guest
pstoto76  Offline OP
Guest
P

Joined: Jun 2013
Posts: 3
Hi I am new in this forum. I have been through zorro tutorial and I was very impressed by it so I decided to spend more time on it to understand more deeply how it worked. Naturally, I start reading the book "Cybernetic Analysis of Stocks and Futures" and the algorithm for the Low Pass function. I have to be honest, even if I have some background in math I haven't understand the algorithm explanation (which requires some electronic/physic background).
Still, I implemented it in mql4 in order to compare it with the exponential moving average. If you compare the LowPass(100) with the EMA(50) you get exactly the same peak and valley with no lagging. The point then, is I don't really see the added value of the LowPass filter. I wonder if I missed something??? (in the image the LowPass(100) is in red and the EMA(50) in green).

Re: LowPass vs EMA [Re: pstoto76] #425055
06/25/13 23:08
06/25/13 23:08

A
acidburn
Unregistered
acidburn
Unregistered
A



I wonder how you checked that peak and valleys are exactly at the same place? Hopefully not by eyeballing few data points? Our eyes are imperfect tool for such precise measurement, that's why we have Zorro for such daunting tasks. grin

Here's quick and dirty script that trades peaks and walleys for your example. I took the liberty to add ALMA to the party (not yet available in Zorro, but soon...). EMA50 took 571 trades, and LP100 only 360. So, it looks like LP100 is much smoother than EMA50. ALMA got even less trades, only 292. And of all three, only ALMA actually came out profitable, but that is of course a pure coincidence. If it only was that easy, you trade MA or a simple crossover and your wallet gets fatter every day. grin

Code:
#define CYAN 0x00ffff
#define ORANGE 0xff8000

var ALMA(var *Data, int Period, int sigma, var offset)
{
	var m = floor(offset * (Period - 1));
	var s = Period / sigma;
	var alma, wSum;
	int i;

	for (i = 0; i < Period; i++) {
		var w = exp(-((i - m) * (i - m)) / (2 * s * s));
		alma += Data[Period - 1 - i] * w;
		wSum += w;
	}
	
	return alma / wSum;
}

var ALMA(var *Data, int Period) {
	return ALMA(Data, Period, 6, 0.85);
}

function run()
{
	set(PLOTNOW|PLOTPRICE);
	StartDate = 2012;
	LookBack = 400;
	BarPeriod = 60;
	PlotWidth = 8000;

	vars Close = series(priceClose());
	vars MA1 = series(EMA(Close, 50));
	vars MA2 = series(LowPass(Close, 100));
	vars MA3 = series(ALMA(Close, 100));

	if (peak(MA1)) {
		if (!NumOpenLong)
			enterLong();
	} else if (valley(MA1)) {
		if (!NumOpenShort)
			enterShort();
	}

	plot("EMA50", MA1[0], 0, BLUE);
	plot("LP100", MA2[0], 0, ORANGE);
	plot("ALMA100", MA3[0], 0, CYAN);
}




Re: LowPass vs EMA [Re: ] #425070
06/26/13 07:41
06/26/13 07:41
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
I can confirm that LP100, when correctly implemented, has very different peaks and valleys than EMA50. It is not possible to emulate a LP function with an EMA. Regardless how you set the EMA's time frame, you can only match a few peaks or valleys, but most won't match.

The reason is the different frequency response of LP and EMA. EMA is a first order lowpass filter, LP is second order.

Admittedly the curves in your screenshot look quite similar - in fact they both look like EMA variants. A LP line is normally smoother and has no small ripples as in your screenshot at the left side. But that might be just chance, it's hard to tell at this scale.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1