The LowPassSeven--a Zorro tested EA

Dewey McG
Trader
Posts: 435
Joined: Sat Nov 26, 2011 4:20 pm
Location: Tampa FL

The LowPassSeven--a Zorro tested EA

Post by Dewey McG »

((Edit--Fixed AGAIN. Both Long and Short orders are working now))

Pardon what might seem to be a long winded post, but if you skip straight to the EA you will miss the whole point. It does work and appears to be profitable but with some help I think there is potential to make it even better.


I think many people are too quick to try out an EA without doing proper testing. A good reason for part of this is because it takes so long to do it properly with the platform most of us are using: Empty4. That doesn't make it any less important. I have an EA that performs absolutely brilliantly in 2012, but in 2009-2010 it would have lost almost all your money. Think a few weeks forward test would tell you enough about that? There are products you can purchase to get 99% tick modeling and to be able to do walk forward analysis but it's still time consuming and costs money.


A few weeks back Steve sent out a notice about Zorro, which looks like what could be an invaluable tool that allows even a novice like myself to code a script to trade automatically then run comprehensive back-tests and walk forward analysis to see if the strategy merits further work in a fraction of the time. Best of all—it's free! It's not without drawbacks: It's not the same platform and different feeds could yield quite different results. It is a starting point however to at least let you know if your strategy is worth pursuing further.


This EA is a result of such an effort. The original concept came from a thread in forexfactory.com (
http://www.forexfactory.com/showthread.php?t=386701)
that JCL, the chief engineer at Zorro modified for their platform and made a few improvements.

George Heitman coded a lowPass indicator for Empty4, which is worth looking at as a replacement anytime a moving average is called for. According to the website at Zorro,

“A lowpass filter has a similar smoothing effect as a Moving Average function, but has the advantages of a better reproduction of the price curve, and less lag. This means the return value of a lowpass filter function isn't as delayed as the return value of a Moving Average function that is normally used for trend trading. The script can react faster on price changes, and thus generate better profit.”

By replacing the EMA's with a lowPass filter and adjusting the stop-loss, then doing some optimization and walk-forward analysis the results were quite impressive:

Annual Return: +471% 8617 pip/yr

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%

Just a caveat about that APR from JCL :

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%.

I can live with 200% if that's the worst. The strategy in Zorro is pretty simple and looks like this:

function run()
{
set(TESTNOW|PLOTNOW|PARAMETERS);
NumWFOCycles = 8;
BarPeriod = 1440;

while(asset(loop("EUR/USD","AUD/USD","USD/CAD")))
{
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();
}
}
It looked simple enough so I tried using George's lowPass indicator to see if I could code an EA. For many of you this would be pretty easy. George and Gary even made suggestions for how to do this in an EA which went over my head with my very limited experience programming in MQL:
http://www.stevehopwoodforex.com/phpBB3 ... f=27&t=933


To make the EA I used a tool which will code an EA once you plug in the trading rules. I know it's not the best way to do it but I am still learning how to program and it will be a while before I am proficient, but at least this get the ball rolling with a working EA that seems to be profitable and does work. The most relevant parts of the code are the order management part:

manageOrders();

//--------------------------------------
// Go Short
if (((Open[1] > iCustom(NULL, 0 , "lowpass", lowPassPeriod , 2 , 0, 1)) && ((Close[1] < iCustom(NULL, 0 , "lowpass", lowPassPeriod , 2 , 0, 1)) && (Low[1] > iCustom(NULL, 0 , "lowpass", lowPassPeriod , 3 , 0, 1))))) {
// Action #1
sqCloseOrder(100);

// Action #2
sqOpenOrder("NULL", OP_SELL, getOrderSize(200, OP_SELL ), getOrderPrice(200), "", 200);
}
//--------------------------------------
// Go Long
if (((Open[1] < iCustom(NULL, 0 , "lowpass", 15 , 3 , 0, 1)) && ((Close[1] > iCustom(NULL, 0 , "lowpass", 15 , 3 , 0, 1)) && (High[1] < iCustom(NULL, 0 , "lowpass", 15 , 2 , 0, 1))))) {
// Action #1
sqCloseOrder(200);

// Action #2
sqOpenOrder("NULL", OP_SELL, getOrderSize(100, OP_SELL ), getOrderPrice(100), "", 100);
}

return(0);
}


and the stoploss:


double getOrderStopLoss(int orderMagicNumber, int orderType, double price) {
double value = 0;

if(orderMagicNumber == 200) {
value = (Stopfactor*(sqHighest("NULL", 0, 2 , 1) - sqLowest("NULL", 0, 2 , 1)));
if(value > 0) {
if(orderType == OP_BUY || orderType == OP_BUYSTOP || orderType == OP_BUYLIMIT) {
value = price - value;
} else {
value = price + value;
}
}

}

if(orderMagicNumber == 100) {
value = (Stopfactor*(sqHighest("NULL", 0, 2 , 1) - sqLowest("NULL", 0, 2 , 1)));
if(value > 0) {
if(orderType == OP_BUY || orderType == OP_BUYSTOP || orderType == OP_BUYLIMIT) {
value = price - value;
} else {
value = price + value;
}
}

}

Hopefully a better and more experienced programmer can use Steve's template and provide a better code.

Now I was ready to do more testing.

I first started doing some initial backtests in Empty4 to see if the results held up as well. The first broker I used was a bear to test with because it's harder with them to import history, but the last couple years looked good. Then I realized I might be comparing apples with oranges since this works on the daily charts. With different GMT offsets you will get different daily bars and likely get different results. Data feeds would be different as well, so I opened a demo with the same broker Zorro uses FXCM, hoping that at least the comparisons would be closer. I still can't get the results to match up exactly with Zorro's. But was able to show decent results. I attached the top of the strategy tester for more deaailed information, but at a 2% risk the profit factor was 1.62 and a maximum drawdown of 12.59%


I also attached the optimization graph for those who use them. Green squares indicate the settings would be profitable. Anything with a Stoploss factor of 2 looks good but either 12 or 16 would be best for Period.

Here is what I am hoping for going forward:

1. Would someone like to take a stab at redoing the EA using Steve's template?
2. I just got the Zorro code for their lowPass filter this morning from JCL om their website:


var LowPass(var *data,int period)
{
var* LP = series(*data,3);
var a = 2./(period+1);
var a2 = a*a;
return LP[0] = (a-a2/4)*data[0]
+ 0.5*a2*data[1]
- (a-0.75*a2)*data[2]
+ 2*(1.-a)*LP[1]
- (1.-a)*(1.-a)*LP[2];
}





I don't know if this does the exact same thing that George's LowPass indicator does. Can one of our coding experts here compare the two and if they are different write a new version of the LowPass filter to use so we can compare apples with apples for testing purposes.


I will continue to try to find best settings for other pairs. For EUR/USD LowPassPeriod = 12, Stopfactor = 2 gives the best results.

Let me know if there are any questions.
You do not have the required permissions to view the files attached to this post.
Last edited by Dewey McG on Sun Nov 25, 2012 2:53 pm, edited 3 times in total.
Dewey McG
Trader
Posts: 435
Joined: Sat Nov 26, 2011 4:20 pm
Location: Tampa FL

Re: The LowPassSeven--a Zorro tested EA

Post by Dewey McG »

It's buried in the post, but this is for the DAILY charts
bshoe24
Trader
Posts: 84
Joined: Sat Feb 11, 2012 5:53 pm

Re: The LowPassSeven--a Zorro tested EA

Post by bshoe24 »

Thanks for your efforts. It's nice to see Zorro getting some love :)
garyfritz

Re: The LowPassSeven--a Zorro tested EA

Post by garyfritz »

Dewey McG wrote:I think many people are too quick to try out an EA without doing proper testing. A good reason for part of this is because it takes so long to do it properly with the platform most of us are using: Empty4. That doesn't make it any less important.
I agree 1000% percent with this. In my experience, extensive backtesting is crucial. I think the lack of proper backtesting is why so many of the promising EAs we create here end up falling apart.

So, let me make sure I understand your Zorro code...

* The WFO trains this on 142 weeks of in-sample (IS) data, then runs it OOS (out of sample) for 153 days. Roughly a 5:1 IS:OOS ratio, which is OK. Longer IS is usually better. I use 8:1 on my WFOs.
* The WFO optimizes on the lookback period of the lowpass, and the stop size (multiplier times H-L).
* I believe the WFO runs a separate optimization on each of your three symbols.
* The strategy is always in the market:
When today's daily candle opens above the EMA (lowpass) of the daily High, and closes below the lowpass of the High, and today's low is lower than the lowpass of the Low, go short.
When today opens below lowpass of Low, closes above lowpass of Low, and today's high is higher than lowpass of the High, go long.

That's pretty simple and I'm surprised it works as well as Zorro says. It uses MAs (lowpass) to trigger entries, but in its favor it doesn't "tune" the MAs to the market. Things like MA-crossover systems are "tuned" to the current frequency of the market's up/down moves. Works beautifully when the market matches your tuned frequency, but it blows up when the market changes. Which it does, constantly. So this strategy just uses the lowpass MAs as a proxy for the price, which doesn't tune to market frequency. I suspect the lookback period parameter is fairly insensitive.

The SL might be a problem. Daily H-L is very volatile. It might work well, or you might do better if you use a SL that's a multiple of the current ATR. You'd have to test it to see what works best.

I don't understand the optimization graph. Your parameters go from 3 to 15 (Period) and 0.5 to 5 (Stop). (BTW without a Step parameter, won't the stop param go 0.5, 1.5, 2.5, etc?) But the opto graph shows parameter ranges of 10-20 and 1-6 ?? It looks like the vertical param (I'm guessing the stop?) has a clear peak at 2. But the horizontal param (length?) has THREE independent peaks. You'd prefer a single peak but you don't always get it.

Next step I'd suggest is to add more pairs, and use Zorro's Optimal-F weighting so it only trades the pairs that work well. That might help your results more than anything.
Dewey McG
Trader
Posts: 435
Joined: Sat Nov 26, 2011 4:20 pm
Location: Tampa FL

Re: The LowPassSeven--a Zorro tested EA

Post by Dewey McG »

garyfritz wrote: So, let me make sure I understand your Zorro code...

The WFO trains this on 142 weeks of in-sample (IS) data, then runs it OOS (out of sample) for 153 days. Roughly a 5:1 IS:OOS ratio, which is OK. Longer IS is usually better. I use 8:1 on my WFOs.
124 weeks but yes (I assume that was a typo)
garyfritz wrote:
* The WFO optimizes on the lookback period of the lowpass, and the stop size (multiplier times H-L).
I believe the WFO runs a separate optimization on each of your three symbols.
Correct
garyfritz wrote:
* The strategy is always in the market:
When today's daily candle opens above the EMA (lowpass) of the daily High, and closes below the lowpass of the High, and today's low is lower than the lowpass of the Low, go short.
When today opens below lowpass of Low, closes above lowpass of Low, and today's high is higher than lowpass of the High, go long.
Not quite always in the market. Look at the chart attached and you will see a few gaps with no trade taking place.
garyfritz wrote:


The SL might be a problem. Daily H-L is very volatile. It might work well, or you might do better if you use a SL that's a multiple of the current ATR. You'd have to test it to see what works best.
Glad you mentioned it. I tried replacing the SL with a multiple of ATR. I tried optimization of both ATR(50) and ATR(100). The best result was with ATR(100) but that was just +56% 2303 pip/yr which pales in comparison. One of the things that is so cool about Zorro is a test like that takes just a few minutes.
garyfritz wrote:

I don't understand the optimization graph. Your parameters go from 3 to 15 (Period) and 0.5 to 5 (Stop). (BTW without a Step parameter, won't the stop param go 0.5, 1.5, 2.5, etc?) But the opto graph shows parameter ranges of 10-20 and 1-6 ?? It looks like the vertical param (I'm guessing the stop?) has a clear peak at 2. But the horizontal param (length?) has THREE independent peaks. You'd prefer a single peak but you don't always get it.
I didn't do the EA exactly like the Zorro code. Instead of 3x the period, I just put in period. The best results for each pair was close to 15 so I ran 10-20 for the EA. If you don't put in a step parameter in Zorro it increases by 10%. When I did the EA, I was having a problem making it work when I tried using steps of .5. I put in steps of 1 to make it work but planned on looking back on it later then forgot until now. I will have to go back and fix this and run the optimization again. To see if we can get an even better value.

I am not sure what you mean exactly by the three independent peaks. Maybe I had too much turkey and am tired.
garyfritz wrote:

Next step I'd suggest is to add more pairs, and use Zorro's Optimal-F weighting so it only trades the pairs that work well. That might help your results more than anything.
I did try other pairs but these are the three that had the best results. I still need to do optimization for the other two, but I suspect we can make a LowPass indicator that matches what Zorro uses and can get better results and would like to see that first.


Thanks for your input!
You do not have the required permissions to view the files attached to this post.
garyfritz

Re: The LowPassSeven--a Zorro tested EA

Post by garyfritz »

Dewey McG wrote:Not quite always in the market. Look at the chart attached and you will see a few gaps with no trade taking place.
Ah right -- I forgot about the Stop variable.
I am not sure what you mean exactly by the three independent peaks. Maybe I had too much turkey and am tired.
I haven't seen that optimization chart before so I'm guessing about how to interpret it. I assume the darker areas are "more gooder" -- higher profits, better Sharpe, whatever the measure is. Ideally you'd like to see a broad flat area with good results. That way you can choose parameters in the center of that plateau and even if (when) the system behavior shifts in the future, you're still somewhere on that broad plateau.

If you have a sharp peak, the OOS behavior is unlikely to match your IS behavior because the peak will probably shift in the future and you'll fall to a lower-performing area.

That chart seems to have THREE peaks -- three dark areas on the chart. So you have to decide which of those parameter sets to use.
Dewey McG
Trader
Posts: 435
Joined: Sat Nov 26, 2011 4:20 pm
Location: Tampa FL

Re: The LowPassSeven--a Zorro tested EA

Post by Dewey McG »

You are correct--the darker the box the better. ideally you want a cluster of green boxes around an area
User avatar
TallCoolOne
Trader
Posts: 43
Joined: Sun Jan 29, 2012 3:05 pm

Re: The LowPassSeven--a Zorro tested EA

Post by TallCoolOne »

Hi.

Thanks for sharing your EA. I noticed in the backtesting that I performed. It was only taking sells, no buys. I think you are sending sell orders for both conditions. Thanks! TCO
User avatar
Sgt.Forex
Trader
Posts: 55
Joined: Wed Nov 16, 2011 11:03 am
Location: Germany

Re: The LowPassSeven--a Zorro tested EA

Post by Sgt.Forex »

TallCoolOne wrote:Hi.

Thanks for sharing your EA. I noticed in the backtesting that I performed. It was only taking sells, no buys. I think you are sending sell orders for both conditions. Thanks! TCO
Absolutely correct.
I changed

Code: Select all

// Go Long 
   if (((Open[1] < iCustom(NULL, 0 , "lowpass", 15 , 3 , 0, 1)) && ((Close[1] > iCustom(NULL, 0 , "lowpass", 15 , 3 , 0, 1)) && (High[1] < iCustom(NULL, 0 , "lowpass", 15 , 2 , 0, 1))))) {
      // Action #1
       sqCloseOrder(200);

      // Action #2
      sqOpenOrder("NULL", OP_SELL, getOrderSize(100, OP_SELL ), getOrderPrice(100), "", 100);
   }
to

Code: Select all

// Go Long 
   if (((Open[1] < iCustom(NULL, 0 , "lowpass", 15 , 3 , 0, 1)) && ((Close[1] > iCustom(NULL, 0 , "lowpass", 15 , 3 , 0, 1)) && (High[1] < iCustom(NULL, 0 , "lowpass", 15 , 2 , 0, 1))))) {
      // Action #1
       sqCloseOrder(200);

      // Action #2
      sqOpenOrder("NULL", OP_BUY, getOrderSize(100, OP_BUY ), getOrderPrice(100), "", 100);
   }
Please find the mod attached.
Cheers
You do not have the required permissions to view the files attached to this post.
Money makes the world go round! ;)
Dewey McG
Trader
Posts: 435
Joined: Sat Nov 26, 2011 4:20 pm
Location: Tampa FL

Re: The LowPassSeven--a Zorro tested EA

Post by Dewey McG »

Thanks! I feel like a real idiot for missing that. I put the correct one in post one and redid the backtests. I will redo the optimization as well but that will take all day before it is finished.
Post Reply

Return to “Automated trading systems”