Hi all,
I've been developing my trading strategy for the past 6 months or so and have finally come up with a system I have the confidence in to trade. I found this site invaluable in developing my stategy and as such I am posting my lessons learnt to give something back.
I caveat all of these with the fact that I have only been trading this system since 1/1/2010 (I'm only up 1.5% since than) so in no way is it proven, the backtest results are good and I believe I have overcome alot of the traps of backtesting/optimization.
My strategy is a trend trading strategy (Long only at this time), I won't give away the exact system but I will give you the high points. My software of choice is Amibroker (With data from premium data) so the code I quote is for this. I also have Stock Doctor but don't realy use this in this strategy (I use it to trade fundamentally good stocks on support and resistance when the market is moving back and forth as it is now)
So here they are, in no particular order:
1. Position size - You want to be trading about 10 stocks at a time. PositionSize = -10;
A trend trading strategy will not neccessarily give you a greater than 50% win/loss ratio (Mine gives about 40-45%) so the idea of trend trading is to let your wins go and cut your losses short, 10 stocks allows you to do this.
2. Position score - Set this to random
Positionscore=random();
For those not familiar with Amibroker this makes it enter trades randomly, i.e. if on a given day you have enough funds to enter 2 trades but you get 5 buy signals it will choose these at random (If it is not set to random it enters them alphabetically). Each time you hit backtest you will get a different result. This is very important, you may have a system that 1 in 100 times gives you awesome results and the rest of the time tanks. If position score is not set to random and you don't do a few tests (3 is generally considered a good initial sample size) you may only get the good results.
Monte Carlo backtesting is obviously taking this to the next level. You can set up pseudo monte carlo backtesting in Amibroker using the following
PS = Optimize("PS",1,1,100);
Positionscore=random()*PS;
Now instead of hitting backtest hit Optimize, this will give you the results for 100 trades.
3. Trade delays - It is crucial to get this right. . I do intraday trading so I get my signals at night and enter buy/sell signals the next day. If doing Intraday trading set your trade delays as follows:
SetTradeDelays(1,1,1,1);
An simple example of setting these incorrectly is as follows:
Buy = Close>open;
Sell = Close>open;
If you trade this with no trade delays you will get amazing results but obviously this is unrealistic.
4. Don't let your backtest results be biased by suvivorism/indexes - The best way to do this is to backtest historical share/index data including delisted stocks, I haven't been able to obtain historical index data (ASX 200 etc.) So I only backtest all Fully paid ordinary shares and delisted stocks. The bottom line is don't backtest the current day ASX200 as this will bias your results (Obviously stocks have done well in the past to get into thew ASX 200).
5. Trade with the market - Let the market drive your trades (Long/Short how much money to have in at a time etc.). Nobody knows where the market is heading, for every so called expert telling you the market is about to go gangbusters there is one telling you it is about to tank. Your neighbour, relative or best friend definately does not know where the market is heading so don't listen to them either. A simple way of doing this is a moving average following the index you are trading, to do this in Amibroker use the following setup:
XAO = Foreign("XAO","CLOSE");
Now when you use MA(XAO,5)etc. it will look at the all ords.
6. Ensure the stock has enough volume for you to enter - Again this will bias your results, if you try to buy $50000 of a stock that only had $10000 of volume traded you will have to pay a premium for this. Ensure the stock has 5-10 times the average volume traded that you are looking to buy. Use the recent moving average of volume for this, for example if we are buying $10000 per trade set it as follows:
(MA(Volume,10)*Close)>100000
Also, in the setting window under the portfolio tab set limit trade size as a % of entry volume to 10.
7. Basic Trend trading strategy - This can be a number of things, trading off moving averages, hitting fresh highs/lows etc. Come up with something sensible, backtest it, if it makes you some money look at how it could make you more by examining the trades it makes. If it is giving you a bunch of signals look at how to narrow these down to mostly the good ones.
So far.... The setting for my system are as follows:
PositionSize = -10;
PS = Optimize("PS",1,1,1,10);
PositionScore = Random()*PS;
SetTradeDelays(1,1,1,1);
XAO = Foreign("XAO","CLOSE");
An overview of the system is as follows:
Buy = MA(XAO,15) > MA(XAO,40) // This keeps us trading with the market and will keep us out of the bear markets.
AND (MA(Volume,10)*Close)>100000 // This ensures there is sufficient volume
[Insert trend strategy here]
Sell = [Insert trnd strategy here] // Sell can be alot simpler than buy as you want to get out of a trade as soon as the market moves against you.
By now you should be getting reasonable results, but we can now make them better using volume:
8. Use volume in your entry - Volume drastically improved my results, you want to be buying on increased volume this shows that there is increased interest in the stock, set this as follows using the medium term moving average:
Volume > (3*MA(Volume,150)) // Volume must be 3 x greater than average
Our strategy now looks like this:
PositionSize = -10;
PS = Optimize("PS",1,1,1,10);
PositionScore = Random()*PS;
SetTradeDelays(1,1,1,1);
XAO = Foreign("XAO","CLOSE");
Buy = MA(XAO,15) > MA(XAO,40) // This keeps us trading with the market
AND (MA(Volume,10)*Close)>100000 // This ensures there is sufficient volume
AND Volume > (3*MA(Volume,150)) // Volume must be 3 x greater than average
[Insert trend strategy here]
Sell = [Insert trnd strategy here] // Sell can be alot simpler than buy as you want to get out of a trade as soon as the market moves against you.
9. Optimization - It is easy to over optimize a system. Optimization is a good thing as you have to set your paramaters to something. To prevent over optimization ensure that the value for your buy/sell paramaters can be changed to sensible values and it will still outperform the market. If your system only works with a specific set of numbers it is probably over optimized.
Also ensure that the system works in a variety of different market conditionss. Finally, to ensure your system is not over optimized........
10. Backtest against foreign markets - I forked out for the US data also for this purpose. Ensure your stategy outperforms in these markets also.
There is 10 of the lessons i've learnt whilst developing my strategy, there is a thousand more, but I'm sick of typing.
Finally, to give those new to strategy development something to aim for, the average backtested results for my system are as follows:
Testing all ASX fully paid ordinary shares since 2000:
Profit - 600% (Compared with the XAO's 47% rise), outperforms 100% of the time
Testing the NYSE since 1985:
Profit - 1400% (Compared to NYSE composite index's 594% rise), Outperforms 100% of the time (Limited sample size though)
Testing the NASDAQ since 1985:
Profit - 1500% (Compared to NASDAQ composite index's 780% rise),
Outperforms 100% of the time (Again limited sample size)
Good luck.
I've been developing my trading strategy for the past 6 months or so and have finally come up with a system I have the confidence in to trade. I found this site invaluable in developing my stategy and as such I am posting my lessons learnt to give something back.
I caveat all of these with the fact that I have only been trading this system since 1/1/2010 (I'm only up 1.5% since than) so in no way is it proven, the backtest results are good and I believe I have overcome alot of the traps of backtesting/optimization.
My strategy is a trend trading strategy (Long only at this time), I won't give away the exact system but I will give you the high points. My software of choice is Amibroker (With data from premium data) so the code I quote is for this. I also have Stock Doctor but don't realy use this in this strategy (I use it to trade fundamentally good stocks on support and resistance when the market is moving back and forth as it is now)
So here they are, in no particular order:
1. Position size - You want to be trading about 10 stocks at a time. PositionSize = -10;
A trend trading strategy will not neccessarily give you a greater than 50% win/loss ratio (Mine gives about 40-45%) so the idea of trend trading is to let your wins go and cut your losses short, 10 stocks allows you to do this.
2. Position score - Set this to random
Positionscore=random();
For those not familiar with Amibroker this makes it enter trades randomly, i.e. if on a given day you have enough funds to enter 2 trades but you get 5 buy signals it will choose these at random (If it is not set to random it enters them alphabetically). Each time you hit backtest you will get a different result. This is very important, you may have a system that 1 in 100 times gives you awesome results and the rest of the time tanks. If position score is not set to random and you don't do a few tests (3 is generally considered a good initial sample size) you may only get the good results.
Monte Carlo backtesting is obviously taking this to the next level. You can set up pseudo monte carlo backtesting in Amibroker using the following
PS = Optimize("PS",1,1,100);
Positionscore=random()*PS;
Now instead of hitting backtest hit Optimize, this will give you the results for 100 trades.
3. Trade delays - It is crucial to get this right. . I do intraday trading so I get my signals at night and enter buy/sell signals the next day. If doing Intraday trading set your trade delays as follows:
SetTradeDelays(1,1,1,1);
An simple example of setting these incorrectly is as follows:
Buy = Close>open;
Sell = Close>open;
If you trade this with no trade delays you will get amazing results but obviously this is unrealistic.
4. Don't let your backtest results be biased by suvivorism/indexes - The best way to do this is to backtest historical share/index data including delisted stocks, I haven't been able to obtain historical index data (ASX 200 etc.) So I only backtest all Fully paid ordinary shares and delisted stocks. The bottom line is don't backtest the current day ASX200 as this will bias your results (Obviously stocks have done well in the past to get into thew ASX 200).
5. Trade with the market - Let the market drive your trades (Long/Short how much money to have in at a time etc.). Nobody knows where the market is heading, for every so called expert telling you the market is about to go gangbusters there is one telling you it is about to tank. Your neighbour, relative or best friend definately does not know where the market is heading so don't listen to them either. A simple way of doing this is a moving average following the index you are trading, to do this in Amibroker use the following setup:
XAO = Foreign("XAO","CLOSE");
Now when you use MA(XAO,5)etc. it will look at the all ords.
6. Ensure the stock has enough volume for you to enter - Again this will bias your results, if you try to buy $50000 of a stock that only had $10000 of volume traded you will have to pay a premium for this. Ensure the stock has 5-10 times the average volume traded that you are looking to buy. Use the recent moving average of volume for this, for example if we are buying $10000 per trade set it as follows:
(MA(Volume,10)*Close)>100000
Also, in the setting window under the portfolio tab set limit trade size as a % of entry volume to 10.
7. Basic Trend trading strategy - This can be a number of things, trading off moving averages, hitting fresh highs/lows etc. Come up with something sensible, backtest it, if it makes you some money look at how it could make you more by examining the trades it makes. If it is giving you a bunch of signals look at how to narrow these down to mostly the good ones.
So far.... The setting for my system are as follows:
PositionSize = -10;
PS = Optimize("PS",1,1,1,10);
PositionScore = Random()*PS;
SetTradeDelays(1,1,1,1);
XAO = Foreign("XAO","CLOSE");
An overview of the system is as follows:
Buy = MA(XAO,15) > MA(XAO,40) // This keeps us trading with the market and will keep us out of the bear markets.
AND (MA(Volume,10)*Close)>100000 // This ensures there is sufficient volume
[Insert trend strategy here]
Sell = [Insert trnd strategy here] // Sell can be alot simpler than buy as you want to get out of a trade as soon as the market moves against you.
By now you should be getting reasonable results, but we can now make them better using volume:
8. Use volume in your entry - Volume drastically improved my results, you want to be buying on increased volume this shows that there is increased interest in the stock, set this as follows using the medium term moving average:
Volume > (3*MA(Volume,150)) // Volume must be 3 x greater than average
Our strategy now looks like this:
PositionSize = -10;
PS = Optimize("PS",1,1,1,10);
PositionScore = Random()*PS;
SetTradeDelays(1,1,1,1);
XAO = Foreign("XAO","CLOSE");
Buy = MA(XAO,15) > MA(XAO,40) // This keeps us trading with the market
AND (MA(Volume,10)*Close)>100000 // This ensures there is sufficient volume
AND Volume > (3*MA(Volume,150)) // Volume must be 3 x greater than average
[Insert trend strategy here]
Sell = [Insert trnd strategy here] // Sell can be alot simpler than buy as you want to get out of a trade as soon as the market moves against you.
9. Optimization - It is easy to over optimize a system. Optimization is a good thing as you have to set your paramaters to something. To prevent over optimization ensure that the value for your buy/sell paramaters can be changed to sensible values and it will still outperform the market. If your system only works with a specific set of numbers it is probably over optimized.
Also ensure that the system works in a variety of different market conditionss. Finally, to ensure your system is not over optimized........
10. Backtest against foreign markets - I forked out for the US data also for this purpose. Ensure your stategy outperforms in these markets also.
There is 10 of the lessons i've learnt whilst developing my strategy, there is a thousand more, but I'm sick of typing.
Finally, to give those new to strategy development something to aim for, the average backtested results for my system are as follows:
Testing all ASX fully paid ordinary shares since 2000:
Profit - 600% (Compared with the XAO's 47% rise), outperforms 100% of the time
Testing the NYSE since 1985:
Profit - 1400% (Compared to NYSE composite index's 594% rise), Outperforms 100% of the time (Limited sample size though)
Testing the NASDAQ since 1985:
Profit - 1500% (Compared to NASDAQ composite index's 780% rise),
Outperforms 100% of the time (Again limited sample size)
Good luck.