Could anyone back test this code for me?

D

Dowser

I've just discovered automated trading and have been trying to put a system together on IG's Prorealtime. This one is for US30 on M30 T/F and is simplicity itself.

// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
x=45
y=54
a=40
b=48
// Conditions to enter long positions
indicator1 = ExponentialAverage[x](close)
indicator2 = ExponentialAverage[y](close)
c1 = (indicator1 CROSSES OVER indicator2)

IF c1 THEN
BUY 1 PERPOINT AT MARKET
ENDIF

// Conditions to exit long positions
indicator3 = ExponentialAverage[x](close)
indicator4 = ExponentialAverage[y](close)
c2 = (indicator3 CROSSES UNDER indicator4)

IF c2 THEN
SELL AT MARKET
ENDIF

// Conditions to enter short positions
indicator5 = ExponentialAverage[a](close)
indicator6 = ExponentialAverage(close)
c3 = (indicator5 CROSSES UNDER indicator6)

IF c3 THEN
SELLSHORT 1 PERPOINT AT MARKET
ENDIF

// Conditions to exit short positions
indicator7 = ExponentialAverage[a](close)
indicator8 = ExponentialAverage(close)
c4 = (indicator7 CROSSES OVER indicator8)

IF c4 THEN
EXITSHORT AT MARKET
ENDIF

// Stops and targets
SET STOP pLOSS 75
SET TARGET pPROFIT 150


I can back test to August last year but no further. If anybody could test this going back 5 years or so I would be very grateful. The results so far are pretty good. Any suggestions for improvement are most welcome.(y)
 
...I can back test to August last year but no further. If anybody could test this going back 5 years or so I would be very grateful. The results so far are pretty good. Any suggestions for improvement are most welcome.(y)

Why can't you backtest prior to August? When you say "US30" do you mean the Dow 30? You could download years of historical data on that quite easily (such as Yahoo Finance, for example).

Your algorithm appears to use an (exponential) moving average crossovers to generate buy/sell signals. Yes, that is "simplicity itself." Maybe too simple. If you're going to do algorithmic trading, I suggest reading Ernie Chan's book, "Algorithmic Trading - Winning Strategies and Their Rationale".
 
I can't back test prior to August because that's as far back as the data goes on my spread bet platform on the 30 minute time frame. Yes I'm referring to the Dow. I think the years of historical data on Yahoo is Daily OHLC, but I will double check. It maybe too simple and that's why I'm trying to back test for a longer period of time.
 
I can't back test prior to August because that's as far back as the data goes on my spread bet platform on the 30 minute time frame. Yes I'm referring to the Dow. I think the years of historical data on Yahoo is Daily OHLC, but I will double check. It maybe too simple and that's why I'm trying to back test for a longer period of time.

Ten months of 30-minute data should be about 2000 data points, by my calculation. That should be sufficient to back test. If you're not seeing a decent return with backtesting that data set, then it might be best to drop the strategy.
 
The point is I am seeing a very decent return. I just worried it's too good to be true!
 
I set my risk per trade to 2% so,working backwards, at £1/pt and with 75pt stops my initial capital is £3750. The return is £3319 or 88.5%. Total number of trades: 130. Winning trades: 57 (44%). Max Drawdown: 11.6%. Max runup: 95%. Average gains of winners £145. Average loss of losers: £68. All without compounding.
 
88.5% return (without compounding) in 10 months, with an average of less than one trade per day? Yes, that does sound "too good to be true". If you're confident you've done the backtesting correctly then I suppose you are right to want to test with more data. It could be a statistical fluke. I don't trade intraday so I don't have 30-minute data. Sorry.

One question. Your code lines for calculating the indicators has "(close)" at the end of the lines. What does this mean? It can't mean market close because that wouldn't make sense if you're trading 30-minute data.

Also, I assume the numbers for x=45, y=54, etc. are the periods for calculating the exponential averages. Did you arrive at them by trial and error?
 
88.5% return (without compounding) in 10 months, with an average of less than one trade per day? Yes, that does sound "too good to be true". If you're confident you've done the backtesting correctly then I suppose you are right to want to test with more data. It could be a statistical fluke. I don't trade intraday so I don't have 30-minute data. Sorry.

One question. Your code lines for calculating the indicators has "(close)" at the end of the lines. What does this mean? It can't mean market close because that wouldn't make sense if you're trading 30-minute data.

Also, I assume the numbers for x=45, y=54, etc. are the periods for calculating the exponential averages. Did you arrive at them by trial and error?
The 'close' just means that the EMA was calculated on the closes of the 30 minute bars. 'x=45, y=54' are indeed the EMA periods. I have a method to optimize results from a data set so it's a bit more than trial and error. It's certainly a bit quicker than plugging random numbers into the computer!
 
I can't back test prior to August because that's as far back as the data goes on my spread bet platform on the 30 minute time frame. Yes I'm referring to the Dow. I think the years of historical data on Yahoo is Daily OHLC, but I will double check. It maybe too simple and that's why I'm trying to back test for a longer period of time.

try (x) periods 100 000
 
What is (x) periods 100 000? A shorter time period?

No, we're still on 30 mins. 100000 is the maximum number the platform will accept. It doesn't give me 100000 x 30min bars, its just extends the data set back as far as is available. Alas, the returns generated from this larger sample are less impressive.
 
Top