Zorro

Post Reply
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Re: Zorro

Post by jcl »

The Laguerre function as a separate indicator is easy:

Code: Select all

var Laguerre(var data, var alpha)
{
   vars L0 = series(),L1 = series(),L2 = series(),L3 = series();

   L0[0] = alpha*data + (1-alpha)*L0[1];
   L1[0] = -(1-alpha)*L0[0] + L0[1] + (1-alpha)*L1[1];
   L2[0] = -(1-alpha)*L1[0] + L1[1] + (1-alpha)*L2[1];
   L3[0] = -(1-alpha)*L2[0] + L2[1] + (1-alpha)*L3[1];
   return (L0[0] + 2*L1[0] + 2*L2[0] + L3[0]) / 6;
}

function run()
{
   set(PLOTPRICE+PLOTNOW);
   StartDate=20120903;
   EndDate=20120904;
   PlotBars = 500;
   BarPeriod=1;

   plot("ALF",Laguerre(price(),0.5),0,RED);
}
And the link you posted indeed leads to John Ehler's original code, so the adaptive part should also be pretty straightforward. I have no time today, but will post it in the next days if you don't get it running before.
magft
Trader
Posts: 195
Joined: Tue Nov 15, 2011 9:59 pm
Location: East Midlands, UK

Re: Zorro

Post by magft »

jcl wrote:The Laguerre function as a separate indicator is easy:

Code: Select all

var Laguerre(var data, var alpha)
{
   vars L0 = series(),L1 = series(),L2 = series(),L3 = series();

   L0[0] = alpha*data + (1-alpha)*L0[1];
   L1[0] = -(1-alpha)*L0[0] + L0[1] + (1-alpha)*L1[1];
   L2[0] = -(1-alpha)*L1[0] + L1[1] + (1-alpha)*L2[1];
   L3[0] = -(1-alpha)*L2[0] + L2[1] + (1-alpha)*L3[1];
   return (L0[0] + 2*L1[0] + 2*L2[0] + L3[0]) / 6;
}

function run()
{
   set(PLOTPRICE+PLOTNOW);
   StartDate=20120903;
   EndDate=20120904;
   PlotBars = 500;
   BarPeriod=1;

   plot("ALF",Laguerre(price(),0.5),0,RED);
}
And the link you posted indeed leads to John Ehler's original code, so the adaptive part should also be pretty straightforward. I have no time today, but will post it in the next days if you don't get it running before.
JCL

Thanks for the help i've had a go at the adaptive part but it is still not quite right. When you have time see if you can spot any errors.

Code: Select all

//+------------------------------------------------------------------+
//|   AdaptiveLaguerreFilter.mq4
//+------------------------------------------------------------------+

int    _LookBack    = 20;
int    _Median      = 5;
//extern int    PriceType   = PRICE_MEDIAN;
int    _Length      = 7;

function UpdateAlpha(var Data, var LastVal)
{
	vars Diff=series();
	vars SortDiff=series();

	if(LastVal==0) LastVal=Data;
	Diff[0] = (abs(ZMA(series(MedPrice()),_Length) - LastVal));

	MinMax(Diff,_LookBack);
	double alpha=0.5;
	if(rMax-rMin!=0) 
	{
		*SortDiff=(*Diff-rMin)/(rMax-rMin);
   	alpha=Median(SortDiff,_Median);
	}   
   
   return(alpha);
}

var Laguerre(var data, var alpha, bool Adaptive)
{
   vars L0 = series(),L1 = series(),L2 = series(),L3 = series();

	static var Filter;
	
	if (Adaptive)
	{
		alpha=UpdateAlpha(data,Filter);	
	}
	
   L0[0] = alpha*data + (1-alpha)*L0[1];
   L1[0] = -(1-alpha)*L0[0] + L0[1] + (1-alpha)*L1[1];
   L2[0] = -(1-alpha)*L1[0] + L1[1] + (1-alpha)*L2[1];
   L3[0] = -(1-alpha)*L2[0] + L2[1] + (1-alpha)*L3[1];
   Filter=(L0[0] + 2*L1[0] + 2*L2[0] + L3[0]) / 6;
   return (Filter);
}

function run()
{
   set(PLOTPRICE+PLOTNOW);
   StartDate=20120903;
   EndDate=20120904;
   PlotBars = 500;
   BarPeriod=1;

   plot("ALF",Laguerre(price(),0.5,false),0,RED);
   plot("ALF2",Laguerre(price(),0.5,true),0,BLUE);
}
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Re: Zorro

Post by jcl »

As far as I see, your conversion is correct, but Ehlers himself made a slight mistake with his alpha adaption. Alpha is initially 0, but then the Laguerre function also returns 0 and stays this way. This probably happened with your code. So you need to give alpha a lower limit.

Code: Select all

	vars Filt = series();
	vars Diff = series(abs(price() - Filt[1]));
	MinMax(Diff,20);
	vars SortDiff = series((Diff[0] - rMin)/(rMax - rMin));
	var alpha = Median(SortDiff,5); 
	Filt[0] = Laguerre(series(price()),max(alpha,0.5));
   
   plot("ALF",Filt[0],0,RED);
"Laguerre" is my function above, without the internal alpha adaption.
dudest
Trader
Posts: 1847
Joined: Tue May 08, 2012 2:37 pm

Re: Zorro

Post by dudest »

@jcl: you got some serious mad skillz bro!
magft
Trader
Posts: 195
Joined: Tue Nov 15, 2011 9:59 pm
Location: East Midlands, UK

Re: Zorro

Post by magft »

jcl

Thanks again for your help, i'm slowly learning how to get the code correct.

I've still not managed to figure out how to basket trade successfully yet, i want to use a basket sl/tp but not managed to get far yet. Is valLong a cash value or in pips?

For completeness here is the Laguerre and ALF code.

Code: Select all

//+------------------------------------------------------------------+
//|   AdaptiveLaguerreFilter.mq4
//+------------------------------------------------------------------+

int    _LookBack    = 20;
int    _Median      = 5;
//extern int    PriceType   = PRICE_MEDIAN;
int    _Length      = 7;
var    _alpha0      = 0.5;

var Laguerre(var data, var alpha)
{
   vars L0 = series(),L1 = series(),L2 = series(),L3 = series();

   L0[0] = alpha*data + (1-alpha)*L0[1];
   L1[0] = -(1-alpha)*L0[0] + L0[1] + (1-alpha)*L1[1];
   L2[0] = -(1-alpha)*L1[0] + L1[1] + (1-alpha)*L2[1];
   L3[0] = -(1-alpha)*L2[0] + L2[1] + (1-alpha)*L3[1];
   return (L0[0] + 2*L1[0] + 2*L2[0] + L3[0]) / 6;
}

function run()
{
   set(PLOTPRICE+PLOTNOW);
   StartDate=20120903;
   EndDate=20120904;
   PlotBars = 500;
   BarPeriod=1;

	vars Filt = series();
	Filt[0]=Laguerre(price(),_alpha0);
	
   vars ALF = series();
   vars Diff = series(abs(price() - Filt[1]));
   MinMax(Diff,_LookBack);
   vars SortDiff = series((Diff[0] - rMin)/(rMax - rMin));
   var alpha = Median(SortDiff,_Median); 
   ALF[0] = Laguerre(price(),max(alpha,_alpha0));
   
   plot("Laguerre Filter",Filt[0],0,RED);
   plot("ALF",ALF[0],0,BLUE);
}
Reagrds

Mike
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Re: Zorro

Post by jcl »

All prices are in cash, not pips. For conversion to pips divide the price by the PIP variable.

For an sl of an artificial asset you must replace the normal sl by a special trade function. This function then calculates the total basket price and exits all basket trades when the price reaches the sl limit.

An example of a trade function can be found under "Trade Parameters" in the manual.
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Re: Zorro

Post by jcl »

Zorro version 1.06 is now available at http://zorro-trader.com! New features have been implemented in this version:

- Curves can now be plotted as an average over all oversampling cycles.
- Laguerre filter function as suggested by magft.
- New commands for display text and color signals.
- Command line options for starting Zorro from external programs.
- Seasonal analysis functions.

Under http://manual.zorro-trader.com/new.htm you'll find a more comprehensive list of the features and known issues of the recent version.

By the way, Zorro is a contestant in the FXCM Freestyle App Challenge at http://forexfreestyle.challengepost.com/submissions.htm. If you like Zorro, vote for it!
dudest
Trader
Posts: 1847
Joined: Tue May 08, 2012 2:37 pm

Re: Zorro

Post by dudest »

jcl wrote:Zorro version 1.06 is now available at http://zorro-trader.com! New features have been implemented in this version:

- Curves can now be plotted as an average over all oversampling cycles.
- Laguerre filter function as suggested by magft.
- New commands for display text and color signals.
- Command line options for starting Zorro from external programs.
- Seasonal analysis functions.

Under http://manual.zorro-trader.com/new.htm you'll find a more comprehensive list of the features and known issues of the recent version.

By the way, Zorro is a contestant in the FXCM Freestyle App Challenge at http://forexfreestyle.challengepost.com/submissions.htm. If you like Zorro, vote for it!
Goodstuff jcl!, Zorro definitely has my vote.

PS: how's that Empty4 bridge coming along? :)

Cheers!
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Re: Zorro

Post by jcl »

Thanks! The Empty4 plugin is almost ready - just some final optimizations have to be done - and will be most likely released together with the next version, 1.07.
dudest
Trader
Posts: 1847
Joined: Tue May 08, 2012 2:37 pm

Re: Zorro

Post by dudest »

jcl wrote:Thanks! The Empty4 plugin is almost ready - just some final optimizations have to be done - and will be most likely released together with the next version, 1.07.
Suweeet!, thanks :)
Post Reply

Return to “Coders Hangout”