stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Zorro
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=921
Page 6 of 12
Author:  jcl [ Tue Feb 19, 2013 10:18 am ]
Post subject:  Re: Zorro

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.
Author:  magft [ Fri Feb 22, 2013 11:04 am ]
Post subject:  Re: Zorro

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);
}
Author:  jcl [ Fri Feb 22, 2013 12:02 pm ]
Post subject:  Re: Zorro

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.
Author:  dudest [ Fri Feb 22, 2013 1:36 pm ]
Post subject:  Re: Zorro

@jcl: you got some serious mad skillz bro!
Author:  magft [ Fri Feb 22, 2013 10:59 pm ]
Post subject:  Re: Zorro

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
Author:  jcl [ Sun Feb 24, 2013 9:50 am ]
Post subject:  Re: Zorro

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.
Author:  jcl [ Mon Mar 25, 2013 8:23 am ]
Post subject:  Re: Zorro

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!
Author:  dudest [ Mon Mar 25, 2013 9:05 am ]
Post subject:  Re: Zorro

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!
Author:  jcl [ Tue Mar 26, 2013 7:15 am ]
Post subject:  Re: Zorro

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.
Author:  dudest [ Tue Mar 26, 2013 8:29 am ]
Post subject:  Re: Zorro

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 :)
All times are UTC Page 6 of 12