Gamestudio Links
Zorro Links
Newest Posts
Z9 getting Error 058
by madpower2000. 07/17/26 19:03
Purchase A8 full licence version
by ukgamer. 07/17/26 05:52
New Lic: When does the Support clock start?
by Student_64151. 07/17/26 01:38
New Zorro version 3.11
by madpower2000. 07/16/26 13:49
What are you working on?
by NeoDumont. 07/15/26 16:38
Zorro version 3.0 prerelease!
by madpower2000. 07/14/26 20:11
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (1 invisible), 2,950 guests, and 36 spiders.
Key: Admin, Global Mod, Mod
Newest Members
riggi89, shuhari, KD1990, Ephraim, Student_64151
19223 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
LowPass filter is not the same as Workshop 4a #485845
04/28/22 02:43
04/28/22 02:43
Joined: Apr 2022
Posts: 18
Singapore
V
vinitrinh Offline OP
Newbie
vinitrinh  Offline OP
Newbie
V

Joined: Apr 2022
Posts: 18
Singapore
I've seen other posts that shared the formula of the LowPass filter and have tried the workshop 4a script. However, it seems like the formula is not producing the same results as the inbuilt LowPass filter.

Below is the code for recreating the experiment.
Comment the second low pass codes for Trends and MMI to replicate results.

Also attached are the backtest results of using the inbuilt LowPass and that of using Workshop 4a's lowpass.

Do we know the exact formula of the inbuilt lowpass?

Code
var lowpass(vars In,int Period)
{
  var a = 1./(1+Period);
  vars Out = series(In[0],3);
  return Out[0] = (a-0.25*a*a)*In[0]
    + 0.5*a*a*In[1]
    - (a-0.75*a*a)*In[2]
    + (2-2*a)*Out[1]
    - (1-a)*(1-a)*Out[2];
}

function run()
{
	EndDate = 20171231; // fixed simulation period 
	Verbose = 2;
	LookBack = 300;	// needed for MMI
	asset("EUR/USD");
	set(LOGFILE,PLOTNOW); // log all trades

	vars Prices = series(priceClose());
	vars Trends = series(LowPass(Prices,300));
    vars Trends = series(lowpass(Prices,300));
    vars Trends2 = series(lowpass(Prices,300));

	
	Stop = 30*ATR(100); // very distant stop
	
	vars MMI_Raws = series(MMI(Prices,300));
	vars MMI_Smooths = series(LowPass(MMI_Raws,300));
    vars MMI_Smooths = series(lowpass(MMI_Raws,300));
	
	if(falling(MMI_Smooths)) 
	{
		if(valley(Trends))
			enterLong();
		else if(peak(Trends))
			enterShort();
	}

    string Row = strf(
        "%02i/%02i/%02i %02i:%02i,%.5f,%.5f,%.5f,%.5f,%.5f,%.5f\n",
        day(),month(),year()%100,hour(),minute(),
        priceO(),priceH(),priceL(),priceC(), Trends[0], Trends2[0]);

    if(is(INITRUN))
        file_delete("Data\\export.csv");
        // Create header row here
        // file_append("Data\\export.csv",Row);
    else
        file_append("Data\\export.csv",Row);
}

Attached Files inbuilt LowPass.pngworkshop4a LowPass.png
Re: LowPass filter is not the same as Workshop 4a [Re: vinitrinh] #485847
04/28/22 07:48
04/28/22 07:48
Joined: Jul 2000
Posts: 28,124
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,124
Frankfurt
That's right. The internal filters use a slightly different conversion of time period to a: 2./(1+Period). That's the usual 'smoothing formula' that is also used for EMA and other accumulating indicators.

The filter is the same, only the time period is different. I believe in the tutorial 1./(1+Period) was used for better explaining the int/var issue, but I think we'll also change the tutorial to the more common formula.

Re: LowPass filter is not the same as Workshop 4a [Re: vinitrinh] #487404
04/08/23 19:22
04/08/23 19:22
Joined: Apr 2023
Posts: 19
R
rki Offline
Newbie
rki  Offline
Newbie
R

Joined: Apr 2023
Posts: 19
this is the Python code

def lowpass (Data, period):
a=2.0/(1+period)
out=[]
for i in range(2, len(Data)):
if i==2:
LP=np.array([Data[0] for _ in range(3)])
print (LP)

LP[0]=(a-0.25*a*a)*Data[i-2] + 0.5*a*a*Data[i-1] - (a-0.75*a*a)*Data[i] + 2*(1.-a)*LP[1] - (1.-a)*(1.-a)*LP[2]
out.append (LP[0])
LP=np.roll(LP, 1)
return out

Re: LowPass filter is not the same as Workshop 4a [Re: vinitrinh] #487656
07/02/23 13:26
07/02/23 13:26
Joined: Apr 2022
Posts: 18
Singapore
V
vinitrinh Offline OP
Newbie
vinitrinh  Offline OP
Newbie
V

Joined: Apr 2022
Posts: 18
Singapore
Thanks for the helpful responses, both.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1