Zorro

Post Reply
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Zorro

Post by SteveHopwood »

I reproduce here a pm from bshoe24 last week:
Hi Steve,

Have you seen this "Zorro" project?

http://www.zorro-trader.com/
http://www.opserver.de/ubb7/ubbthreads.php?ubb=cfrm&c=1
http://forums.babypips.com/expert-advis ... nture.html

It's basically an autotrading app that has a "lite-C" dev. environment where you can write trading strategies easily. The awesome thing is you can backtest years in usually less than 1-minute. Right now its early in its development and it only supports connecting to FXCM for autotrading and data but, it will support more criminals in the future.

One of the drawbacks i often see with the strategies shared in your and the FF forums is that they are really hard to backtest in Empty4 to get an idea if the trading strategy might have any edge and how profitable it may be. It might be worthwhile to develop a process where forum ideas are tested in Zorro and then if they show promise results-wise code them in Empty4. I think Zorro may even be extensible to support Empty4 via an API.

Anyway it's a really interesting project that you and your coding wizard friends might be able to really take advantage of. I'm only a very limited aspiring coder so i am trying to learn via Zorro.

By the way interestingly Hugh Briss from the FF forums (also http://www.hughbrissforex.com/) is active with Zorro right now. He has about half a dozen scripts he's written that he has been playing with and shared on his forum. You might check it out if you have any interest.

The three big advantages i see with Zorro is the rapid development capability, the backtesting facility which only takes seconds to do 4 years of FXCM data, and the native optimization capabilities. Check it out if you haven't. By the way i attached an example script from Hugh Briss forum to show you how easy it is to code a strat to backtest.

I hope this email hasn't been a complete waste of your time. :)
I leave it up to you guys to see if you can make anyrhing of it.

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
bshoe24
Trader
Posts: 84
Joined: Sat Feb 11, 2012 5:53 pm

Re: Zorro

Post by bshoe24 »

Thanks Steve. I wish i had more to say about this but, i've pretty much said all i know in the PM Steve posted. I am running Zorro on FXCM demo (Z2fx script) but, no trades closed yet (2 open). Maybe more experienced folks around here can take a look at it and give some input if it looks worth anything.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Zorro

Post by SteveHopwood »

My limited memory of a pm Gary sent me said that users need to be able to code scripts a la Zorro in order to be able to backtest, so I am probably mis-remembering. Or misunderstanding - Gary talks Geek, after all. :lol:

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
garyfritz

Re: Zorro

Post by garyfritz »

Here's what I told Steve:
garyfritz wrote:I've been giving Zorro a cursory glance for the last week or two.

It appears to have some really incredibly powerful features: multi-symbol multi-system backtesting, walk-forward optimizer, other nice things.

It also has what you might call a "quirky" interface. The programming language is fairly dense and cryptic, but still quite powerful. The GUI is almost non-existent. No charts, almost nothing but a couple of buttons and sliders and a window that can (I think) print messages. That's it. Everything is controlled by your scripts.

I don't think it would be that much help for backtesting EA strategies. Typically EAs are doing all kinds of intense detailed manipulations, and I'm not convinced Zorro is that flexible. I'm not sure how well a strategy would translate from Zorro to MQL. It might be good for a proof-of-concept.

And Zorro is only good for running "EAs." As far as I can see, there is no interface or other provision for entering or managing orders manually. You write your script and it does what it does. You have very little visibility or control over what it's doing.

I'm sure I'm prejudiced, but I think Tradestation is a helluva lot better development platform than Zorro. It can't do some of the important things Zorro can do (like multi-strategy multi-symbol testing) but Zorro can't do a lot of the things TS can do. And TS is a whole lot more complete with a whole lot more support for the kinds of things we tend to want to do. If TS could do proper multi-symbol strategies, it would be the bee's knees.

Gary
And AmiBroker or NinjaTrader might be a better answer than Tradestation, but I haven't dug into them.
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Post by babalu4u »

Example script with explanation

Code: Select all

function run() 
{ var *Price = series(price()); 
var *Trend = series(LowPass(Price,1000)); 
Stop = 2*ATR(100); 
if(valley(Trend)) enterLong(); 
else if(peak(Trend)) enterShort(); }
We're now going to analyze the code. At first, we can see that the function is now named "run" and not "main". "run" is also a special function name, but while a main function runs only once, a run function is called after every bar with the period and asset selected with the scrollbars. By default, the bar period is 60 minutes. So this function runs once per hour when Zorro trades.

At the begin we notice two strange lines that look similar to var definitions:

var *Price = series(price());
var *Trend = series(LowPass(Price,1000));

However unlike var definitions, they have an asterisk '*' before the name, and are set to the return value of a series() function call. We define not a single variable here, but a whole series. (C++ programmers might notice that we in fact define a pointer, but that needs not bother us now). A series is a variable with a history - the series begins with the current variable value, then comes the value the variable had one bar before, then the value from two bars before and so on. This is mostly used for price curves and their derivatives. For instance, we could use a series to take the current price of an asset, compare it with the price from 1 bar before, and do some other things dependent on past prices. The series is the ideal construct for such price calculations.

The current value of a series can be used by adding a [0] to the series name; for the value from one bar before add a [1], for two bars before add a [2] and so on. So, in Alice's code Price[0] would be the current value of the Price series, and Price[1] the value from 1 hour ago. Many trade platform languages - for instance, EasyLanguage - support series this way; usually indicator, statistics, and financial functions all use series instead of single variables. We'll encounter series very often in trade scripts and will become familiar with them.

The series() function can be used to convert a single variable to a series. The variable or value for filling the series is normally passed to that function. However, we're not using a variable here, but the return value of a function call. var *Price = series(price()); means: define a var series with the name "Price" and fill it with the return value of the price() function. We've learned in the last programming lesson how to 'nest' function calls this way, passing the return values of functions as parameters to other functions.

The price() function returns the mean price of the selected asset at the current bar. There are also priceOpen(), priceClose(), priceHigh() and priceLow() functions that return the open, close, maximum and minimum price of the bar; however, the mean price is usually the best for trend trading strategies. It's averaged over all prices inside the bar and thus generates a smoother price curve.

var *Trend = series(LowPass(Price,1000));

The next line defines a series named "Trend" and fills it with the return value from the LowPass function. As you probably guessed, this function is the second order lowpass filter. Its parameters are the previously defined Price series and a cutoff value, which Alice has set to 1000 bars. 1000 bars are about 2 months (1 week = 24*5 = 120 hours). Thus the lowpass filter attenuates all the wiggles and jaggies of the Price series that are shorter than 2 months, but it does not affect the trend or long-term cycles above two months. It 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.

The next line places a stop loss limit:

Stop = 2*ATR(100);

Stop is a predefined variable that Zorro knows already, so we don't have to define it. It's the maximum allowed loss of the trade; the position is sold immediately when it lost more than the given value. The limit here is given by 2*ATR(100). The ATR function is a standard indicator. It returns the Average Price Range - meaning the average height of a candle - within a certain number of bars, here the last 100 bars. So the position is sold when the loss exceeds two times the average candle height of the last 100 bars. By setting Stop not at a fixed value, but at a value dependent on the fluctuation of the price, Alice adapts the stop loss to the market situation. When the price fluctuates a lot, higher losses are allowed. Otherwise trades would be stopped out too early when the price jumps down just for a moment.

A stop loss should be used in all trade strategies. It not only limits losses, it also allows Zorro's trade engine to better calculate the risk per trade and generate a more accurate performance analysis.

The next lines are the core of Alice's strategy:

Code: Select all

if(valley(Trend))
  enterLong(); 
else if(peak(Trend)) 
  enterShort();
The valley function is a boolean function; it returns either true or false. It returns true when the series just had a downwards peak. The peak function returns true when it just had an upwards peak. When the if(..) condition becomes true, a long or short trade with the selected asset is entered with a enterLong or enterShort command. If a trade was already open in the opposite direction, it is automatically closed. Note how we combined the else of the first if with a second if; the second if() statement is only executed when the first one was not.

C source code of the LowPass, peak, and valley functions:

Code: Select all

var smoothF(int period) { return 2./(period+1); }
var LowPass(var *Data,int Period)
{
	var* LP = series(*Data,3);
	var a = smoothF(Period);
	var a2 = a*a;
	return LP[0] = (a-0.25*a2)*Data[0]
		+ 0.5*a2*Data[1]
		- (a-0.75*a2)*Data[2]
		+ 2*(1.-a)*LP[1]
		- (1.-a)*(1.-a)*LP[2];
}
BOOL peak(var* a) { 
	return a[2] < a[1] && a[1] > a[0];
}
BOOL valley(var* a) {
	return a[2] > a[1] && a[1] < a[0];
}
Let's have a look into an example trade triggered by this command:

Read more: http://forums.babypips.com/expert-advis ... z2AwnVc4AJ
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

Post by jcl »

Thanks for leading me to this thread, and congrats for the quality of this forum. I'm the documentation guy for Zorro, so I can look in this forum from time to time and answer questions about it.

What was said so far about Zorro is correct, except for the opinion that "EAs are doing all kinds of intense detailed manipulations". The limitations of EAs are just the reason for the need of more serious platforms, such as Ninja, Amibroker, and of course Zorro. But when you run into any problems scripting an EA in Zorro, just ask and I'll try to help.
Last edited by jcl on Thu Nov 01, 2012 6:18 pm, edited 1 time in total.
garyfritz

Re: Zorro

Post by garyfritz »

Thanks, jcl. (Guys, jcl is a huge help on the Zorro forum!)

What I meant by the "intense detailed" comment was that EAs are triggered on every tick, and quite frequently EAs are written to do all kinds of calculations (open/close positions, move stops, calculate open equity, etc) on a tick-by-tick basis. I don't believe Zorro is designed to do that kind of low-level calculation?
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Re: Zorro

Post by jcl »

I believe all platforms can trigger functions on every tick and do tick based calculations; otherwise handling open trades would be sort of difficult. Zorro can certainly do it.
garyfritz

Re: Zorro

Post by garyfritz »

I thought Zorro handled the open trades itself -- receiving every tick if necessary, etc -- but I didn't think it brought those ticks up to the script level. Can you do script operations on every tick? E.g. can a Zorro script say "on this tick the price is X and the Y is Z, so I will open a trade NOW" ? Zorro could open a trade at X with a stop, but an EA can look at the Y on every tick to see if the Z condition is met. The EA could also calculate a different X entry price on every tick. Can Zorro do that?

(Tradestation can't, BTW, at least in its default mode. It's possible to run it in tick-by-tick mode but usually systems act at the end of a bar, and you set stops for the duration of the next bar.)
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Re: Zorro

Post by jcl »

Yes, sure. Systems normally do not use a tick triggered function for opening trades, but they need such a function for closing trades - otherwise you could not define individual exit algorithms. Zorro can do it and I should know - I had to write the tick triggered exit script for the included Z1 and Z2 systems. ;)
Post Reply

Return to “Coders Hangout”