Simple Trading Strategy

Simple Trading Strategy

Zorro Trader makes implementing a trading strategy very easy. Zorro Trader has a lot of built-in functions and technical indicators, so most of the programming work is already done for you. I got a (rather simple) trading idea from Investopedia, and I will implement it in Zorro Trader in just a few lines of code. We will trade the SP500 (Yahoo: ^GSPC, or an exchange traded fund based on it) based on the Relative Strength Index technical indicator. This is how the RSI is defined by Investopedia:

The relative strength index (RSI) is a momentum indicator used in technical analysis that measures the magnitude of recent price changes to evaluate overbought or oversold conditions in the price of a stock or other asset. The RSI is displayed as an oscillator (a line graph that moves between two extremes) and can have a reading from 0 to 100. The indicator was originally developed by J. Welles Wilder Jr. and introduced in his seminal 1978 book, “New Concepts in Technical Trading Systems.”

Investopedia

…and Wikipedia thinks we should trade based on this common belief among traders:

The RSI is most typically used on a 14-day time frame, measured on a scale from 0 to 100, with high and low levels marked at 70 and 30, respectively. Short or longer time frames are used for alternately shorter or longer outlooks. High and low levels—80 and 20, or 90 and 10—occur less frequently but indicate stronger momentum.

Wikipedia

The trading signals are pretty straightforward and easy to implement in Zorro Trader. The RSI indicates an overbought condition when the RSI line is above 70. When that happens, the price is likely to go down in the short term. The oversold RSI condition happens when the RSI line is below 30. When the RSI is oversold, it implies that the price is likely to go up in the short term. Please note the keyword here: SHORT TERM. What may happen in the medium or long term is another conversation and another trading strategy. So probably the safest trading signals here could be: BUY when RSI crosses above 30, and SELL when the RSI crosses below 70. Here is the code to do it in Zorro Trader.

function run()
{
  vars Prices = series(priceClose());
  vars Rsi = series(RSI(Prices, 14));

  if (crossOver(Rsi, 30)) enterLong();
  if (crossUnder(Rsi, 70)) enterShort();
}

Now, it can’t really get any simpler than this, right? I won’t even explain what each line of code does, because I think it’s pretty self-explanatory (and read my blog if you want more details on it.) However, I want to emphasize that this is a fully functional trading system that you could run on your Zorro Trader machine connected to your brokerage account. And, believe it or not, many people do trade RSI-based strategies like this manually… Do they make money? Hm… Let’s run this strategy on historical data and see what happens. On my computer it took Zorro Trader less than one second to give me the test result.

A Zorro Trader Backtest

Obviously, this is a terrible trading strategy. During the period 2016 – 2021 we practically lost 3% per year for five years. The Sharpe ratio is negative, which means we not only lose money but also take substantial risk while doing it (in other words, there are less risky ways to lose money.) Only 18.8% of the trades are profitable, and so on and so forth. Please do not trade this strategy with real money!

But wait, are Investopedia and Wikipedia wrong? How come this does not work? Well, they are not wrong, in the sense that many traders do believe that this RSI strategy does work (and maybe it does, for them). However, trading on technical indicators is not an exact science and many people believe many weird things… And that’s when Zorro Trader comes in handy: you can test any systematic trading strategy you want quickly and efficiently, in just a few lines of code, before committing any real money to it.

Please read my blog post Hello world! This is Zorro Trader. to learn more about how this script works!