Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (wandaluciaia, AndrewAMD, 1 invisible), 765 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 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: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
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: 15
R
rki Offline
Newbie
rki  Offline
Newbie
R

Joined: Apr 2023
Posts: 15
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