Zorro
-
jcl
- Trader
- Posts: 82
- Joined: Wed Oct 31, 2012 8:04 am
- Location: Frankfurt / Germany
Re: Zorro
Ok, trailing a basket is quite similar to entering and exiting trades with it. Only difference is that you now need a specific function for trailing. The standard trailing would trail every asset individually, not all together.
You can see an example of a specific trailing function in the manual under "Trade Parameters". Your function has to trail using not the asset price but the overall price of the basket, which is calculated as in the code snippet under "Tips&Tricks".
You can see an example of a specific trailing function in the manual under "Trade Parameters". Your function has to trail using not the asset price but the overall price of the basket, which is calculated as in the code snippet under "Tips&Tricks".
-
falsedave
- Trader
- Posts: 53
- Joined: Sun Aug 26, 2012 5:00 pm
Re: Zorro
Hello again,
I'm trying to develop yet another strategy in Zorro. Now I'm probably used to to way Empty4/MT5 backtests thing takes the starting capital and works its way through and displays how much you would have at the end of the test.
With Zorro using code to reinvest profit from workshop 6, I end up with a value for capital of many thousands as as it gets further through the test. Would this be the drawdown when get to be using higher lotsizes. ? Is it possible to test in the Empty4 style ? Give the strategy £2000 and see how much it would make ?
Also when using WFO Zorro seems to always choose the values with the least trades. I can have 600 trades and 200% proftablity but it will pick the values that only take 10 trades and have about 10% profitablity. If 8/10 trades are profitable rather that 400/600 it does have a better win rate but the profits are a hell of a lot smaller as well. Am I doing something wrong here when it comes to WFO ?
I'm trying to develop yet another strategy in Zorro. Now I'm probably used to to way Empty4/MT5 backtests thing takes the starting capital and works its way through and displays how much you would have at the end of the test.
With Zorro using code to reinvest profit from workshop 6, I end up with a value for capital of many thousands as as it gets further through the test. Would this be the drawdown when get to be using higher lotsizes. ? Is it possible to test in the Empty4 style ? Give the strategy £2000 and see how much it would make ?
Also when using WFO Zorro seems to always choose the values with the least trades. I can have 600 trades and 200% proftablity but it will pick the values that only take 10 trades and have about 10% profitablity. If 8/10 trades are profitable rather that 400/600 it does have a better win rate but the profits are a hell of a lot smaller as well. Am I doing something wrong here when it comes to WFO ?
-
jcl
- Trader
- Posts: 82
- Joined: Wed Oct 31, 2012 8:04 am
- Location: Frankfurt / Germany
Re: Zorro
Yes, you don't need starting capital for testing a strategy performance. Obviously the performance of a strategy should not depend on what you enter as starting capital. It is the whole point of Zorro to do a real test and not a pseudo test Empty4 style. But if you want, you can enter a starting capital with the Balance parameter - you can see the example under "Tips&Tricks".
The required capital is calculated from the equity curve, so when reinvesting profits as in workshop 6, the displayed capital is required at the end of the test period, not at the start. The starting capital is the value you got without reinvesting profits.
The WFO training process selects the parameter values with the most, not with the least trades. But you can modify that. In the file "default.c" you'll find a function named "objective" that calculates the selection criterion. You can see that more trades are preferred. You can also define your own objective function in your script and thus have different selection criteria.
The required capital is calculated from the equity curve, so when reinvesting profits as in workshop 6, the displayed capital is required at the end of the test period, not at the start. The starting capital is the value you got without reinvesting profits.
The WFO training process selects the parameter values with the most, not with the least trades. But you can modify that. In the file "default.c" you'll find a function named "objective" that calculates the selection criterion. You can see that more trades are preferred. You can also define your own objective function in your script and thus have different selection criteria.
-
falsedave
- Trader
- Posts: 53
- Joined: Sun Aug 26, 2012 5:00 pm
Re: Zorro
O.k So what I have at the moment is.
But then when running a test 2012-2013 I get.
90Win compiling................
BackTest: 90Win EUR/USD 2012..2013
Read 90Win_EURUSD.fac
Profit 765$ MI 58$ DD 556$ Capital 1478$
Trades 137 Win 38% Avg +69.8p Bars 30
AR 76% PF 1.47 SR 0.96 UI 26.4% Error 48%
Would this mean that with £200 the system would fail as the capital result is £1478. Surely the lotsizes couldnt have got that high to get this result.
Code: Select all
if(is(INITRUN)) Balance = 200;
if(OptimalFLong > 0 or OptimalFShort > 0)
{
Margin = 200*(OptimalFLong+OptimalFShort)/2;
Margin += ( (WinLong-LossLong)*OptimalFLong + (WinShort-LossShort)*OptimalFShort )/2;
if (Margin > MARGINLIMIT)
{
Margin = MARGINLIMIT;
}
}90Win compiling................
BackTest: 90Win EUR/USD 2012..2013
Read 90Win_EURUSD.fac
Profit 765$ MI 58$ DD 556$ Capital 1478$
Trades 137 Win 38% Avg +69.8p Bars 30
AR 76% PF 1.47 SR 0.96 UI 26.4% Error 48%
Would this mean that with £200 the system would fail as the capital result is £1478. Surely the lotsizes couldnt have got that high to get this result.
-
jcl
- Trader
- Posts: 82
- Joined: Wed Oct 31, 2012 8:04 am
- Location: Frankfurt / Germany
Re: Zorro
No. The required capital is calculated from the equity curve. When you reinvest, drawdown is increased, and so is the required capital. Therefore the $1478 is the capital that you need at the _end_ of the simulation for continuing trading, not at the start. You can calculate the starting capital only from a test run without reinvesting.
Also, your initial balance has no effect because you're doing nothing with it. When you want to simulate a Empty4 style test, you need to calculate the margin or lot size from the current balance, just as in the typical Empty4 EAs. This will then make the strategy result dependent on the initial capital.
Also, your initial balance has no effect because you're doing nothing with it. When you want to simulate a Empty4 style test, you need to calculate the margin or lot size from the current balance, just as in the typical Empty4 EAs. This will then make the strategy result dependent on the initial capital.
-
falsedave
- Trader
- Posts: 53
- Joined: Sun Aug 26, 2012 5:00 pm
Re: Zorro
O.k so I changed the code to
Would that be correct ? Over 1 year 2012-2013 I think I get the correct result :
But if I do the same but only test 2008-2009 I get.
Reinvested
Am I right in thinking that from £80 reinvested it could have made 6 million in a year ? If that result is true. I'll buy you the sports car of your choice
But its not 571% growth? . I would then need 1,865,551 to continue trading through 2009 - 2010. Which so long a profit is larger than Capital would be no problem. Am I right.
Sorry for all the stupid questions. You've been a great help JCL.
Code: Select all
if(is(INITRUN)) Balance = 200;
if(OptimalFLong > 0 or OptimalFShort > 0)
{
Margin = Balance/100*(OptimalFLong+OptimalFShort)/2;
Margin += ( (WinLong-LossLong)*OptimalFLong + (WinShort-LossShort)*OptimalFShort )/2;
if (Margin > MARGINLIMIT)
{
Margin = MARGINLIMIT;
}
}Code: Select all
Reinvested
90Win compiling.................
BackTest: 90Win EUR/USD 2012..2013
Read 90Win_EURUSD.fac
Profit 150$ MI 11$ DD 73$ Capital 200$
Trades 136 Win 38% Avg +13.8p Bars 31
AR 113% PF 1.74 SR 1.43 UI 14.0% Error 48%
Not reivested
90Win compiling.................
BackTest: 90Win EUR/USD 2012..2013
Read 90Win_EURUSD.fac
Profit 114$ MI 9$ DD 23$ Capital 75$
Trades 136 Win 38% Avg +10.5p Bars 31
AR 206% PF 1.99 SR 1.80 UI 10.3% Error 49%But if I do the same but only test 2008-2009 I get.
Reinvested
Code: Select all
90Win run..
BackTest: 90Win EUR/USD 2008..2009
Read 90Win_EURUSD.fac
Profit 6323738$ MI 264186$ DD 452415$ Capital 1865551$
Trades 271 Win 44% Avg +291685.3p Bars 32
AR 571% PF 4.16 SR 1.68 UI 3.9% Error 33%
Not Reinvested
90Win compiling.................
BackTest: 90Win EUR/USD 2008..2009
Read 90Win_EURUSD.fac
Profit 608$ MI 25$ DD 34$ Capital 80$
Trades 264 Win 44% Avg +28.8p Bars 32
AR 610% PF 3.45 SR 2.87 UI 2.5% Error 34%Am I right in thinking that from £80 reinvested it could have made 6 million in a year ? If that result is true. I'll buy you the sports car of your choice
Sorry for all the stupid questions. You've been a great help JCL.
-
jcl
- Trader
- Posts: 82
- Joined: Wed Oct 31, 2012 8:04 am
- Location: Frankfurt / Germany
Re: Zorro
I fear I won't get the sports car at this point, as the result is unrealistic. You must test more than 2 years - I think 4 years is the minimum. It must also be a WFO test, not a mere backtest. A backtest with optimized data is too optimistic due to overfitting bias.
You can see that your backtest gets 610% annual profit with no reinvesting - this high percentage is the result of overfitting and of a too short test period. It can not be achieved with the relatively simple algorithms of workshop 6. That's why you need a WFO test here.
When you reinvest, the annual gain, the 571%, is also not a useful performance measure as it's calculated from the end capital, not from the start capital. Instead, CAGR or some similar measure must be used for a reinvesting system. Zorro can not calculate the CAGR directly because the start capital must be known for that. Theoretically two tests were required for this, one with and one without reinvesting. This had to be done manually at the moment, it's not implemented yet as an automatic process. That's why the manual states that the values in the performance report are for systems without reinvesting only.
You can see that your backtest gets 610% annual profit with no reinvesting - this high percentage is the result of overfitting and of a too short test period. It can not be achieved with the relatively simple algorithms of workshop 6. That's why you need a WFO test here.
When you reinvest, the annual gain, the 571%, is also not a useful performance measure as it's calculated from the end capital, not from the start capital. Instead, CAGR or some similar measure must be used for a reinvesting system. Zorro can not calculate the CAGR directly because the start capital must be known for that. Theoretically two tests were required for this, one with and one without reinvesting. This had to be done manually at the moment, it's not implemented yet as an automatic process. That's why the manual states that the values in the performance report are for systems without reinvesting only.
-
magft
- Trader
- Posts: 195
- Joined: Tue Nov 15, 2011 9:59 pm
- Location: East Midlands, UK
Re: Zorro
jcl
Another question for you, i've been trying to put the ALF Empty4 indicator in Zorro for testing but i cannot get it to work correctly and i think i am missing something very simple but can't spot it!
I have attached the mq4 file that i based the code on and the Zorro code is below.
Any help would be gladly appreciated.
Regards
Mike
Another question for you, i've been trying to put the ALF Empty4 indicator in Zorro for testing but i cannot get it to work correctly and i think i am missing something very simple but can't spot it!
I have attached the mq4 file that i based the code on and the Zorro code is below.
Any help would be gladly appreciated.
Regards
Mike
Code: Select all
//+------------------------------------------------------------------+
//| AdaptiveLaguerreFilter.mq4
//+------------------------------------------------------------------+
int _LookBack = 20;
int _Median = 5;
//extern int PriceType = PRICE_MEDIAN;
int _Length = 7;
function run()
{
set(PLOTPRICE+PLOTNOW);
StartDate=20120901;
NumBars=500;
BarPeriod=1;
var *L0=series(0);
var *L1=series(0);
var *L2=series(0);
var *L3=series(0);
var *Filter=series(0);
int limit=_Median+2;
int i,j;
var *Diff=series(0);
double sortDiff[5];//_Median
var *priceH=series(priceHigh());
var *priceL=series(priceLow());
var *priceMedian=series((*priceH+*priceL)/2);
//var *Price=series(price());
for (i=limit;i>=0;i--)
{
//price
double _price = ZMA(priceMedian,_Length);//iNoLagMa(iMA(NULL,0,1,0,MODE_SMA,PriceType,i),Length,alphas,0,i);
Diff[i] = abs(_price - Filter[i+1]);
//adaptive
double _HH = Diff[i];
double _LL = Diff[i];
for (j=0; j<_LookBack; j++)
{
if (Diff[i+j] > _HH) {_HH = Diff[i+j];}
if (Diff[i+j] < _LL) {_LL = Diff[i+j];}
}
double alpha = 0.5;
if (_HH!=_LL)
{
for (j=0;j<_Median;j++) sortDiff[j] = (Diff[i+j]-_LL)/(_HH-_LL);
// ArraySort(sortDiff,WHOLE_ARRAY,0,MODE_ASCEND);
//
// if (MathMod(Median,2.0) != 0)
// alpha = sortDiff[Median/2];
// else alpha = (sortDiff[Median/2]+sortDiff[(Median/2)-1])/2;
alpha=Median(sortDiff,_Median);
}
//Laguerre
L0[i] = alpha*_price + (1 - alpha)*L0[i+1];
L1[i] = -(1 - alpha)*L0[i] + L0[i+1] + (1 - alpha)*L1[i+1];
L2[i] = -(1 - alpha)*L1[i] + L1[i+1] + (1 - alpha)*L2[i+1];
L3[i] = -(1 - alpha)*L2[i] + L2[i+1] + (1 - alpha)*L3[i+1];
Filter[i] = (L0[i] + 2.0 * L1[i] + 2.0 * L2[i] + L3[i]) / 6.0;
}
plot("ALF",Filter[0],0,RED);
}
You do not have the required permissions to view the files attached to this post.
-
jcl
- Trader
- Posts: 82
- Joined: Wed Oct 31, 2012 8:04 am
- Location: Frankfurt / Germany
Re: Zorro
Ok, that's the problems that I spot:
- Sep 1, 2012 was a weekend. So your simulation contains no bars.
- For zooming in a certain period use StartDate and EndDate, not NumBars. NumBars would stop the simulation after the number of bars. For limiting the number of bars in the chart use PlotBars instead.
- You tried to convert code from Empty4, but Empty4 does not support series. The "for (i=limit;i>=0;i--)" etc. loop looks like a Empty4 workaround for replacing series. It makes no sense in other platforms.
If you have the choice, always use the original code from the author of that system for conversion, not some mq4 version. I believe Laguerre filters have been used by John Ehlers, but John Ehlers would never use Empty4, he has most likely published this indicator for TradeStation. So try to get the TradeStation version of the code. It happens frequently that the mq4 version of indicators from other platforms does not work properly, and converting it would also convert the errors.
When developing a complex indicator, split it into parts if possible - in this case, program the Laguerre filter first, and if it works, then add the alfa adaption. I do not really understand in the code how the alfa adation is supposed to work, but the Laguerre filter itself is pretty straightforward:
- Sep 1, 2012 was a weekend. So your simulation contains no bars.
- For zooming in a certain period use StartDate and EndDate, not NumBars. NumBars would stop the simulation after the number of bars. For limiting the number of bars in the chart use PlotBars instead.
- You tried to convert code from Empty4, but Empty4 does not support series. The "for (i=limit;i>=0;i--)" etc. loop looks like a Empty4 workaround for replacing series. It makes no sense in other platforms.
If you have the choice, always use the original code from the author of that system for conversion, not some mq4 version. I believe Laguerre filters have been used by John Ehlers, but John Ehlers would never use Empty4, he has most likely published this indicator for TradeStation. So try to get the TradeStation version of the code. It happens frequently that the mq4 version of indicators from other platforms does not work properly, and converting it would also convert the errors.
When developing a complex indicator, split it into parts if possible - in this case, program the Laguerre filter first, and if it works, then add the alfa adaption. I do not really understand in the code how the alfa adation is supposed to work, but the Laguerre filter itself is pretty straightforward:
Code: Select all
//+------------------------------------------------------------------+
//| AdaptiveLaguerreFilter.mq4
//+------------------------------------------------------------------+
function run()
{
set(PLOTPRICE+PLOTNOW);
StartDate=20120903;
EndDate=20120904;
PlotBars = 500;
BarPeriod=1;
var *L0=series(0);
var *L1=series(0);
var *L2=series(0);
var *L3=series(0);
var *Filter=series(0);
double alpha = 0.5;
//Laguerre
L0[0] = alpha*price() + (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[0] = (L0[0] + 2*L1[0] + 2*L2[0] + L3[0]) / 6;
plot("ALF",Filter[0],0,RED);
}-
magft
- Trader
- Posts: 195
- Joined: Tue Nov 15, 2011 9:59 pm
- Location: East Midlands, UK
Re: Zorro
Thanks for the response, i did get the basic version working like you posted before but was unable to get it working as a separate function that can be called.jcl wrote:Ok, that's the problems that I spot:
- Sep 1, 2012 was a weekend. So your simulation contains no bars.
- For zooming in a certain period use StartDate and EndDate, not NumBars. NumBars would stop the simulation after the number of bars. For limiting the number of bars in the chart use PlotBars instead.
- You tried to convert code from Empty4, but Empty4 does not support series. The "for (i=limit;i>=0;i--)" etc. loop looks like a Empty4 workaround for replacing series. It makes no sense in other platforms.
If you have the choice, always use the original code from the author of that system for conversion, not some mq4 version. I believe Laguerre filters have been used by John Ehlers, but John Ehlers would never use Empty4, he has most likely published this indicator for TradeStation. So try to get the TradeStation version of the code. It happens frequently that the mq4 version of indicators from other platforms does not work properly, and converting it would also convert the errors.
When developing a complex indicator, split it into parts if possible - in this case, program the Laguerre filter first, and if it works, then add the alfa adaption. I do not really understand in the code how the alfa adation is supposed to work, but the Laguerre filter itself is pretty straightforward:
Code: Select all
//+------------------------------------------------------------------+ //| AdaptiveLaguerreFilter.mq4 //+------------------------------------------------------------------+ function run() { set(PLOTPRICE+PLOTNOW); StartDate=20120903; EndDate=20120904; PlotBars = 500; BarPeriod=1; var *L0=series(0); var *L1=series(0); var *L2=series(0); var *L3=series(0); var *Filter=series(0); double alpha = 0.5; //Laguerre L0[0] = alpha*price() + (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[0] = (L0[0] + 2*L1[0] + 2*L2[0] + L3[0]) / 6; plot("ALF",Filter[0],0,RED); }
I found a link for a generic version of the adaptive part to update the alphas here.
My current code is still not quite right, any thing obviously wrong
Code: Select all
set(PLOTPRICE+PLOTNOW);
StartDate=20120903;
EndDate=20120904;
PlotBars = 500;
BarPeriod=1;
var *L0=series(0);
var *L1=series(0);
var *L2=series(0);
var *L3=series(0);
var *Filter=series(0);
var *Diff=series(0);
var *SortDiff=series(0);
Diff[0] = (abs(ZMA(series(MedPrice()),_Length) - Filter[1]));
MinMax(Diff,_LookBack);
SortDiff[0]=((Diff[0]-rMin)/(rMax-rMin));
double alpha = 0.5;
if(rMin!=rMax) alpha=Median(SortDiff,_Median);
//Laguerre
L0[0] = alpha*MedPrice() + (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[0] = (L0[0] + 2*L1[0] + 2*L2[0] + L3[0]) / 6;
plot("ALF",Filter[0],0,RED);Mike