fyi to everyone... i found that the Z2Fx script i was running is not FIFO compliant so Zorro won't work correctly for FXCM USA demos. i emailed the developers and they were kind enough to promptly reply:
"no, the Z2fx script is not FIFO compliant. It just limits the assets to Forex only. A FIFO compliant version will be included in one of the next Zorro updates.
You can find a list of all current known issues with Zorro 1.01 here:
http://zorro-trader.com/manual/en/new.htm
---------
I guess if you use FXCM uk you can avoid this problem now.
--------
Edit: i setup FXCM uk like i should have before. i'll switch over to the USA script version whenever it shows up someday.
Zorro
-
Dewey McG
- Trader
- Posts: 435
- Joined: Sat Nov 26, 2011 4:20 pm
- Location: Tampa FL
Re: Zorro
I have been playing with Zorro ever since Steve was kind enough to send out a notice about it. Know that I have had next to nothing when it comes to experience in coding. Zorro is surprisingly easy to learn to use to get started and so far I have been able to prove conclusively that a few ideas I had simply do not work.
On their forum is an example of how using Zorro can be of tremendous value to first determine if a strategy is a good one, then how to test, optimize and walk forward the strategy to get the most out of it.
Let's look at a popular strategy on FF called The7 Trading Strategy: http://www.forexfactory.com/showthread.php?t=386701
The strategy is simple enough:
Here are the rules: Do not trade only 1 pair. Use your money management and positions wisely and allow room for as many pairs as possible. The point here is that we want the winners to outrun the losers..
Place a 5 EMA High and 5 EMA Low on the chart. Short when red candle closes inside the channel, long when blue candle closes inside the channel. Closing candle has to open outside the channel to become a valid signal. Let it run until you see opposite signal. Stop Loss is high/low from last candle.
Jcl, the chief engineer for Zorro, published a script to run this on their platform:
function run()
{
// Open a Daily chart
BarPeriod = 1440;
// Place a 5 EMA High and 5 EMA Low on the chart.
var EMA5H = EMA(series(priceHigh()),5);
var EMA5L = EMA(series(priceLow()),5);
// Stop Loss is high/low from last candle.
Stop = priceHigh(1) - priceLow(1);
// Short when candle closes inside the channel
if(priceOpen() > EMA5H && priceClose() < EMA5H && priceClose() > EMA5L)
enterShort();
// same for long. Let it run until you see opposite signal
if(priceOpen() < EMA5L && priceClose() > EMA5L && priceClose() < EMA5H)
enterLong();
}
Tests revealed the following:
It returns 10% per year on EUR/USD, 84% on AUD/USD, and 45% on USD/CAD. It loses money with GBP/USD, USD/CHF, and USD/JPY.
Not something to bet the bank on but a decent start making it worth investigating further. He then did some tweaking, the primary difference being using a lowPass filter instead of the EMA's, then another member tried it with USD/CHF instead of USD/CAD :
function run()
{
set(TESTNOW|PLOTNOW|PARAMETERS);
NumWFOCycles = 8;
BarPeriod = 1440;
while(asset(loop("EUR/USD","AUD/USD","USD/CHF")))
{
var Period = optimize(5,3,15);
var EMA5H = LowPass(series(priceHigh()),3*Period);
var EMA5L = LowPass(series(priceLow()),3*Period);
Stop = (HH(2) - LL(2)) * optimize(1,0.5,5);
if(priceOpen() > EMA5H && priceClose() < EMA5H && priceLow() > EMA5L)
enterShort();
else if(priceOpen() < EMA5L && priceClose() > EMA5L && priceHigh() < EMA5H)
enterLong();
}
}
Added in were commands to optimize and do a walk forward analysis to find the best for each pair—much simpler and faster than trying to do this with Empty4!
The results:
471% annual return and 8617 pips per year!
Walk-Forward Test TheSeven portfolio - performance report
Simulation period 05.04.2008-07.08.2012
Test period 17.03.2010-07.08.2012
WFO test cycles 7 x 106 bars (153 days)
Training cycles 8 x 600 bars (124 weeks)
Lookback time 80 bars (115 days)
Gross win/loss $2627 / -$978 (20620 pips)
Average profit $689/year, $57/month, $3/day
Max drawdown -$93 (MAE -$373)
Max down time 272 days from Mar 2011
Largest margin $54
Trade volume $109043 ($45570/year)
Capital required $146
Number of trades 124 (51/year)
Percent winning 58%
Max win/loss $138 / -$52
Avg trade profit $13 (+$36 / -$19)
Avg trade bars 29 (+34 / -22)
Max trade bars 223 (323 days)
Time in market 485%
Max open trades 11
Max win/loss streak 12 / 5
Annual return 471%
Profit factor 2.69 (PRR 2.08)
Sharpe ratio 1.53
Kelly criterion 0.51
OptimalF .082
Ulcer index 7%
Prediction error 44%
Trade details OptF ProF Win/Loss Cycles
AUD/USD total .090 1.31 23/24 \X/\XX/
EUR/USD total .100 7.14 28/12 //\X//X
USD/CHF total .059 1.60 21/16 \//\XX/
total .000 ---- 0/0 .......
AUD/USD:L .090 2.57 17/10 \//.\//
AUD/USD:S .000 0.68 6/14 \\/\/\/
EUR/USD:L .046 2.37 9/6 ./\///\
EUR/USD:S .155 14.54 19/6 //\\.//
USD/CHF:L .110 4.10 11/2 \././//
USD/CHF:S .009 1.17 10/14 \//\\\/
JCL suggested even more tweaking, such as testing BarOffset values for each pair.
From what I have seen, Zorro looks to be a worthwhile tool.
Converting this particular strategy to Mql will need a lowpass filter. I found one (attached) but am not sure how good this is or whether it does the same as the one Zorro uses.
On their forum is an example of how using Zorro can be of tremendous value to first determine if a strategy is a good one, then how to test, optimize and walk forward the strategy to get the most out of it.
Let's look at a popular strategy on FF called The7 Trading Strategy: http://www.forexfactory.com/showthread.php?t=386701
The strategy is simple enough:
Here are the rules: Do not trade only 1 pair. Use your money management and positions wisely and allow room for as many pairs as possible. The point here is that we want the winners to outrun the losers..
Place a 5 EMA High and 5 EMA Low on the chart. Short when red candle closes inside the channel, long when blue candle closes inside the channel. Closing candle has to open outside the channel to become a valid signal. Let it run until you see opposite signal. Stop Loss is high/low from last candle.
Jcl, the chief engineer for Zorro, published a script to run this on their platform:
function run()
{
// Open a Daily chart
BarPeriod = 1440;
// Place a 5 EMA High and 5 EMA Low on the chart.
var EMA5H = EMA(series(priceHigh()),5);
var EMA5L = EMA(series(priceLow()),5);
// Stop Loss is high/low from last candle.
Stop = priceHigh(1) - priceLow(1);
// Short when candle closes inside the channel
if(priceOpen() > EMA5H && priceClose() < EMA5H && priceClose() > EMA5L)
enterShort();
// same for long. Let it run until you see opposite signal
if(priceOpen() < EMA5L && priceClose() > EMA5L && priceClose() < EMA5H)
enterLong();
}
Tests revealed the following:
It returns 10% per year on EUR/USD, 84% on AUD/USD, and 45% on USD/CAD. It loses money with GBP/USD, USD/CHF, and USD/JPY.
Not something to bet the bank on but a decent start making it worth investigating further. He then did some tweaking, the primary difference being using a lowPass filter instead of the EMA's, then another member tried it with USD/CHF instead of USD/CAD :
function run()
{
set(TESTNOW|PLOTNOW|PARAMETERS);
NumWFOCycles = 8;
BarPeriod = 1440;
while(asset(loop("EUR/USD","AUD/USD","USD/CHF")))
{
var Period = optimize(5,3,15);
var EMA5H = LowPass(series(priceHigh()),3*Period);
var EMA5L = LowPass(series(priceLow()),3*Period);
Stop = (HH(2) - LL(2)) * optimize(1,0.5,5);
if(priceOpen() > EMA5H && priceClose() < EMA5H && priceLow() > EMA5L)
enterShort();
else if(priceOpen() < EMA5L && priceClose() > EMA5L && priceHigh() < EMA5H)
enterLong();
}
}
Added in were commands to optimize and do a walk forward analysis to find the best for each pair—much simpler and faster than trying to do this with Empty4!
The results:
471% annual return and 8617 pips per year!
Walk-Forward Test TheSeven portfolio - performance report
Simulation period 05.04.2008-07.08.2012
Test period 17.03.2010-07.08.2012
WFO test cycles 7 x 106 bars (153 days)
Training cycles 8 x 600 bars (124 weeks)
Lookback time 80 bars (115 days)
Gross win/loss $2627 / -$978 (20620 pips)
Average profit $689/year, $57/month, $3/day
Max drawdown -$93 (MAE -$373)
Max down time 272 days from Mar 2011
Largest margin $54
Trade volume $109043 ($45570/year)
Capital required $146
Number of trades 124 (51/year)
Percent winning 58%
Max win/loss $138 / -$52
Avg trade profit $13 (+$36 / -$19)
Avg trade bars 29 (+34 / -22)
Max trade bars 223 (323 days)
Time in market 485%
Max open trades 11
Max win/loss streak 12 / 5
Annual return 471%
Profit factor 2.69 (PRR 2.08)
Sharpe ratio 1.53
Kelly criterion 0.51
OptimalF .082
Ulcer index 7%
Prediction error 44%
Trade details OptF ProF Win/Loss Cycles
AUD/USD total .090 1.31 23/24 \X/\XX/
EUR/USD total .100 7.14 28/12 //\X//X
USD/CHF total .059 1.60 21/16 \//\XX/
total .000 ---- 0/0 .......
AUD/USD:L .090 2.57 17/10 \//.\//
AUD/USD:S .000 0.68 6/14 \\/\/\/
EUR/USD:L .046 2.37 9/6 ./\///\
EUR/USD:S .155 14.54 19/6 //\\.//
USD/CHF:L .110 4.10 11/2 \././//
USD/CHF:S .009 1.17 10/14 \//\\\/
JCL suggested even more tweaking, such as testing BarOffset values for each pair.
From what I have seen, Zorro looks to be a worthwhile tool.
Converting this particular strategy to Mql will need a lowpass filter. I found one (attached) but am not sure how good this is or whether it does the same as the one Zorro uses.
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
Just a remark about the 471% annual return. This is to be taken with a grain of salt. Zorro calculates the annual return similar to the Calmar ratio, which in turn is based on the system drawdown. The drawdown however is a result of the win/loss pattern of trades, and therefore subject to random fluctuations. So, the real annual return of that system can be anything between ~ 200% and 500%.
A solution would be to calculate the drawdown not from the real equity/balance curve, but from a Monte Carlo Simulation. Such an algorithm is planned for a future Zorro version; until then better use not the average annual return, but the profit factor or the Sharpe ratio as performance gauges.
A solution would be to calculate the drawdown not from the real equity/balance curve, but from a Monte Carlo Simulation. Such an algorithm is planned for a future Zorro version; until then better use not the average annual return, but the profit factor or the Sharpe ratio as performance gauges.
Last edited by jcl on Mon Nov 05, 2012 3:37 pm, edited 2 times in total.
-
scheinwerfer
- Trader
- Posts: 42
- Joined: Mon Dec 12, 2011 12:36 am
Re: Zorro
How big case is overoptimization in Z?
-
jcl
- Trader
- Posts: 82
- Joined: Wed Oct 31, 2012 8:04 am
- Location: Frankfurt / Germany
Re: Zorro
Overfitting by optimization is normally not a case because walk forward analysis is on principle not affected by overoptimization.
However there are many other causes for bias in the test result, and they can not be completely avoided. The mere act of developing a strategy already causes bias whenever you test the strategy and let the test results affect the development process. So this is a non-trivial issue.
However there are many other causes for bias in the test result, and they can not be completely avoided. The mere act of developing a strategy already causes bias whenever you test the strategy and let the test results affect the development process. So this is a non-trivial issue.
-
garyfritz
Re: Zorro
jcl, I wondered about the "return" reported by Zorro. Your actual return is going to be hugely affected by the risk level you use when trading. If you risk 5% per trade you'll (probably) make a lot more profit than if you risk 1%, but you'll suffer higher drawdowns. Zorro doesn't seem to take this into account at all, or if it does I don't understand it. Could you expand on that some please?
I assume you must use some modification of the original Calmar ratio, since it's defined as the CAGR / WorstDrawdown over a 3-yr period. Do you just calculate CAGR / DD for whatever period the test runs over?
I assume you must use some modification of the original Calmar ratio, since it's defined as the CAGR / WorstDrawdown over a 3-yr period. Do you just calculate CAGR / DD for whatever period the test runs over?
-
jcl
- Trader
- Posts: 82
- Joined: Wed Oct 31, 2012 8:04 am
- Location: Frankfurt / Germany
Re: Zorro
No, the return is not affected by the risked margin. If you risk 5% of your initial capital, then both the profit and the drawdown are 5 times higher than when you risk 1%. Because the return is proportional to the ratio of both, this results in the same annual return. Note the return is not the CAGR, as profits are not reinvested in the test.
For calculating the return, the drawdown must be normalized to 3 years. This does not happen yet in the Zorro release version that you download from our website - it uses the not normalized drawdown, resulting in a return that depends on the test period. The default test period is about 4 years, so the return is slightly pessimistic. You can find this problem explained in the remarks to the performance report. However the latest Zorro version currently in beta test normalizes the drawdown to 3 years for further calculations, so the return then does not depend anymore on the test period.
For calculating the return, the drawdown must be normalized to 3 years. This does not happen yet in the Zorro release version that you download from our website - it uses the not normalized drawdown, resulting in a return that depends on the test period. The default test period is about 4 years, so the return is slightly pessimistic. You can find this problem explained in the remarks to the performance report. However the latest Zorro version currently in beta test normalizes the drawdown to 3 years for further calculations, so the return then does not depend anymore on the test period.
-
garyfritz
Re: Zorro
I believe you're using "return" to mean profit / DD ? I usually refer to "return" as profit, usually CAGR, so I had some confusion there. Obviously the profit is hugely affected by the risk level, but profit / DD is too.
You're familiar with Kelly values / Optimal F. Profits increase roughly linearly at small fractions of Kelly, but they flatten out and DECREASE as you increase the risk level beyond full Kelly. Drawdowns keep increasing but asymptotically approach 100%. So the profit/DD ratio changes dramatically as you increase to (dangerously) higher levels of risk. See e.g. the graph I posted in this discussion about Kelly:

But profit / DD is not constant, even at lower levels of risk. On the left side of the chart above you can see that the profit (green) is curving UP -- accelerating -- while the DD is curving DOWN -- decelerating. So their ratio is not constant even at small levels of risk.
I have a backtest spreadsheet for a system portfolio I trade, and I can set the risk parameters to any fraction of Kelly I want. This chart shows the 3-year CAGR / WorstDD for that portfolio, for FractionOfKelly ranging from 1% to 10%. (The Kelly values in this portfolio average around 0.25 so 1% fraction corresponds to about 0.25% risk per trade, 10% fraction corresponds to about 2.5% risk per trade.) You can see that even at these low levels of risk, the "return" (CAGR / WorstDD) is not constant, and it doesn't even increase linearly.
So I don't understand how you can ignore the risk level...
Not true, especially at higher levels of risk. Zorro may be assuming small levels of risk where profit and DD do increase somewhat linearly, but even there the profit/DD ratio is not constant.jcl wrote:No, the return is not affected by the risked margin. If you risk 5% of your initial capital, then both the profit and the drawdown are 5 times higher than when you risk 1%..
You're familiar with Kelly values / Optimal F. Profits increase roughly linearly at small fractions of Kelly, but they flatten out and DECREASE as you increase the risk level beyond full Kelly. Drawdowns keep increasing but asymptotically approach 100%. So the profit/DD ratio changes dramatically as you increase to (dangerously) higher levels of risk. See e.g. the graph I posted in this discussion about Kelly:
But profit / DD is not constant, even at lower levels of risk. On the left side of the chart above you can see that the profit (green) is curving UP -- accelerating -- while the DD is curving DOWN -- decelerating. So their ratio is not constant even at small levels of risk.
I have a backtest spreadsheet for a system portfolio I trade, and I can set the risk parameters to any fraction of Kelly I want. This chart shows the 3-year CAGR / WorstDD for that portfolio, for FractionOfKelly ranging from 1% to 10%. (The Kelly values in this portfolio average around 0.25 so 1% fraction corresponds to about 0.25% risk per trade, 10% fraction corresponds to about 2.5% risk per trade.) You can see that even at these low levels of risk, the "return" (CAGR / WorstDD) is not constant, and it doesn't even increase linearly.
So I don't understand how you can ignore the risk level...
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
The reason of the confusion is that you talked about CAGR and I talked about profit. CAGR depends of course on the risk level, but it is irrelevant for trading algorithms: it is a measure for a money management algorithm, for reinvesting profits.
When you develop a strategy, you look first for trading performance, measured with parameters such as profit factor, annual return, Sharpe ratio and so on. They all are completely independent of the margin size. Only when you start adding a money management system, the margin size becomes important.
When you develop a strategy, you look first for trading performance, measured with parameters such as profit factor, annual return, Sharpe ratio and so on. They all are completely independent of the margin size. Only when you start adding a money management system, the margin size becomes important.