Hello world! This is Zorro Trader.

Hello world! This is Zorro Trader.

Here is a quick analysis of the Zorro Trader Lite-C code for the RSI algorithmic trading strategy we got from Investopedia (and Wikipedia). There is only one function in this trading script, and it is called run():

function run()
{

...

}

This is a standard Zorro Trader function, which is being called (meaning, executed) every time a new bar “comes in” from the broker (or from history, in case of a back-test). In Zorro Trader, a bar can be anything you like. But a bar is usually a fixed time period, like one minute, one hour or one day, etc. It is user-defined, although we did not define it in this script. The point is, however, that every time a new bar (OHLC) is generated by your broker, Zorro Trader runs the… run() function.

The first thing the run() function does in this script is to create and store ALL the values for a variable called Prices:

vars Prices = series(priceClose());

The TYPE of Prices is vars, which is the Zorro Trader equivalent of an array. An array is a string of numbers, like a time series. The Zorro Trader built-in function priceClose() reads the closing prices of the underlying asset and the series() function “stitches” them together in a vars type of variable, building a time series of closing prices.

vars Rsi = series(RSI(Prices, 14));

The Rsi variable (of the same type, vars) stores another important array of numbers: the 14 days RSI of the closing prices for the same time period. The RSI(Prices, 14) generates one RSI value at a time, sliding through the values stored in the Prices variable, and computing the individual RSI values. The series() function stitches them together in the Rsi variable.

And then we got our Zorro Trader trading logic. When do we buy (go long) and when do we sell (go short)? Well, it’s fairly easy. Zorro Trader has two built-in function you will use a lot! crossOver() and crossUnder().

if (crossOver(Rsi, 30)) enterLong();

This simply means: if Rsi crosses above (over) the 30 level, run the enterLong() function. Which is also built-in, and… enters a long position.

if (crossUnder(Rsi, 70)) enterShort();

This means just the opposite. If Rsi crosses below (under) the 70 level, run the enterShort() function. Another very useful Zorro Trader built-in function, which send the broker an order for a short (or sell) position.

Please note that the variable that stores ALL the values of the RSI indicator is named Rsi, and NOT RSI. This is because we do not want to confuse a variable name with a function name. RSI() is a function that generates ONE value: the Relative Strength Index for the current bar. The Rsi variable is an array built from all the output values of the RSI() function for the current and the past bars available.

In other words, these may be:

RSI(Prices, 14) = 69

While the last five values of vars Rsi variable may be:

Rsi =  65, 66, 67, 68, 69

These are obviously very different things, and confusing variable and function names is bad programming practice. Please don’t try it at home 🙂

One thought on “Hello world! This is Zorro Trader.

Comments are closed.

Comments are closed.