Low Pass vs SMA

Quote from jcl:

I'm not sure that the Java code is correct, at least it calculates the function in a different way with a loop. The correct way would be to shift the series arrays first by 1, then calculate only the [0] term. Can't you just download Zorro or any other platform such as Ninja Trader that directly supports series? This would spare a long discussion or long workarounds in code - you can then just directly enter the code and test Lowpass vs. SMA in one minute.
So, as a programmer, you cannot answer whether my code is correct?
 
Quote from luckyputanski:

Whether SMA or LP is a trading system or not, is another story. JCL claims that low pass is much more effective than SMA and that's what I'm trying to establish in this thread.

They're both 100% effective at calculating the number they claim to be calculating.
 
Quote from panzerman:

Getting a zero lag moving average is easy:

Step 1: Calculate a MA (any MA) of price
Step 2: Calculate a second MA of the first MA using the same parameters.
Step 3: 2*MA1-MA2 = zero lag MA

However, having a zero lag MA doesn't give you any better performance as an indicator than any other MA. Again, do some proper back testing and prove it for yourself.

I replaced sma260 with this and results are pathetic.
 
Quote from luckyputanski:

So, as a programmer, you cannot answer whether my code is correct?
Well, you're a programmer too and are not sure, or are you? I can also only compare your code with mine.

Not even God can see at a first glance if a code works correct or not - that's why we have debuggers. Your code works in a different way than mine, but it appears indeed correct at a second glance. However you would save yourself and me a lot time when we used a similar platform so that there's no uncertainty if it's correctly implemented or not.

With your code, can you replicate the curve that I posted?

That would be the first step, the next step would be to determine when and under which circumstances less lag generates better performance - or not.
 
By the way, there are many alternative functions with low lag - you might try them too. This is the Zero-Lag MA by John Ehlers:

Code:
// Zero-lag Moving Average
var rError;
var rEMA;
var ZMA(var* Data,int Period)
{
	var *vEMA = series(*Data,2);
	var *vZMA = series(*Data,2);
	var a = smoothF(Period);
	vEMA[0] = a*Data[0]+(1.-a)*vEMA[1];	
	rEMA = vEMA[0]; 

	rError = 1000000;
	var Gain,GainLimit=5,BestGain=0;
	for(Gain=-GainLimit; Gain < GainLimit; Gain += 0.1)
	{
		vZMA[0] = a*(vEMA[0] + Gain*(Data[0]-vZMA[1])) + (1-a)*vZMA[1];
		var Error = Data[0] - vZMA[0];
		if(abs(Error) < rError) {
			rError = abs(Error);
			BestGain = Gain;
		}
	}
	return vZMA[0] = a*(vEMA[0] + BestGain*(Data[0]-vZMA[1])) + (1-a)*vZMA[1];
}

It has not zero lag of course, but it has low lag, almost like a lowpass filter. And this is a 3 pole Butterworth filter:

Code:
var Butterworth(var *Data,int Period)
{
	var a = exp(-PI / Period);
	var b = 2*a*cos(1.738*PI / Period);
	var c = a*a;
	var c1 = b + c;
	var c2 = -(c + b*c);
	var c3 = c*c;
	var c0 = 1 - c1 - c2 - c3;

	var* Filt = series(*Data,4);
	return Filt[0] = c0*Data[0] + c1*Filt[1] + c2*Filt[2] + c3*Filt[3];
}

I haven't done much with those functions yet, but they might be worth testing when you need faster signals from an MA.
 
Quote from kut2k2:

The problem with "zero-lag" MAs is that they are often noisier than the original signal.
Yes, all functions that manipulate the frequency spectrum of the signal add more or less noise. This is also true for normal MAs without zero lag.
 
Quote from jcl:

Yes, all functions that manipulate the frequency spectrum of the signal add more or less noise. This is also true for normal MAs without zero lag.
Not true. Normal MAs are lowpass filters, and the output of a lowpass filter is always less noisy than the input, otherwise what's the point of using them? "Zero-lag MAs" aren't true lowpass filters, so no surprise that they add noise.
 
Quote from kut2k2:

Not true. Normal MAs are lowpass filters, and the output of a lowpass filter is always less noisy than the input, otherwise what's the point of using them?
You're right of course: not the noise, but the signal-to-noise ratio can become worse. The absolute noise, i.e. the high frequencies in the price signal, are always reduced by all functions mentioned here.
 
Back
Top