Australian (ASX) Stock Market Forum

Amibroker Simple Backtests

Joined
14 December 2010
Posts
3,472
Reactions
248
I am trying to use the backtesting for the first time.

I am entering simple codes just to see how it works. Everytime I enter something it says -100% and every single trade is a loser. For example I said buy if close is HHV of last 20 days, sell is close is LLV for last 20 days.

The following is coming up.
backtest.png

1. How does it work with position sizes? As you can see above the red highlighted trade opens a trade with 10 shares. The next one opens a trade with 1983.14 shares (and why is it using decimal points)
a.)Why are position sizes different?
b.) Why does it use decimal points?

2. Can someone give me a basic code that produces some winners and losers and not 100% losers so I can a) have a play around with it and b) maybe see where I've gone wrong?

Thanks
Matt:)
 
I'm struggling with backtesting.
See the code I entered in the picture below. I can see that the maximum position size is $1000. My questions are as follows.

backtest.jpg

1. Why do some positions take ridiculously small sizes e.g. $1.68 (3 shares) which I highlighted in red?

2. How can I make all position sizes equal (or have a minimum position size of say $500 in this case)

3. Why does it trade fractions of shares e.g. 7.234?

4. If I was to buy on the highest high (close) of the previous 10 days, how do I ensure that it doesn't buy more of the same company the next day if it goes higher (so that price is also a highest high of the previous 10 days)?
 
1. no idea, fix the other stuff first and it might change
2. settings > min positon value = 500 (also check settings>portfolio>limit trade size as % of previous...)
3. settings > round lot size = 1
4. help > exrem
 
1. no idea, fix the other stuff first and it might change
2. settings > min positon value = 500 (also check settings>portfolio>limit trade size as % of previous...)
3. settings > round lot size = 1
4. help > exrem

backtest.jpg

Those points were helpful. Fixed up some of the issues. I have no idea why buy the underlying issue is that once again EVERY SINGLE trade is a loser (out of 1070 trades).

1. I don't know what the issue is that makes EVERY SINGLE trade a loser no matter what I put in. Even with the system you gave me.
 
You haven't allowed the system time to sell (+10% or T+3), so you're still holding everything at the price you bought it. The "loss" is just brokerage.
 
Did you add the stops I recommended?

Change "activate stops immediately" - uncheck it on the main page.

Also uncheck "allow same bar exits"

Your commission looks to be very high too. Change that on the main page.
 
You haven't allowed the system time to sell (+10% or T+3), so you're still holding everything at the price you bought it. The "loss" is just brokerage.

backtest.jpg

The trade I've highlighted in red is a loss of 22%, so it can't just be brokerage.

See the settings I highlighted in blue. Is this what you meant to change it to? It is with these settings that is produces the 269 losers.
 
Yes, but also nbars = 3, otherwise if the stock falls after you buy, you'll never sell! See my previous post also.
 
Did you add the stops I recommended?

Change "activate stops immediately" - uncheck it on the main page.

Also uncheck "allow same bar exits"

Your commission looks to be very high too. Change that on the main page.

Ok I unchecked "allow same bar exits" It now returns 39 winners and 205 losers out of 244 trades.
Commission is $9.90 per trade of 0.01%

backtest.jpg
 
Now uncheck those two stops under settings, and learn how to code them. That will then allow you to optimize stops if you want.

Read: applystop in help section.


EDIT: the same place you did the profit stop of 10%, same page down the bottom.
 
Now uncheck those two stops under settings, and learn how to code them. That will then allow you to optimize stops if you want.

Read: applystop in help section.


EDIT: the same place you did the profit stop of 10%, same page down the bottom.

I think there is still something wrong. No matter what I do I always come out with a slightly negative figure.

I even used the formula:
buy = cross( close, ema( close, 45 ) );
sell = cross( ema( close, 45 ), close );

Which was used in an example and got a negative return of -0.91, then changed settings and -0.44. Whatever i changed it came out negative, whereas in the example online it had a positive +16% return.

I cannot get a positive return on ANYTHING. If I could just put something in that would give me a positive return I'd know my program was working alrite and then I could play around with it.
 
Nothing wrong with your software.

If you code 1000 systems, expect the first 999 to give you a negative return. That's pretty normal. And the 1 that is positive will have a ****house equity curve!!

You've only just started. You'll need play around a lot (months to years) to get a system that satisfies you, ie. is positive and has a nice equity curve.

Things to look at in the early stages:

1. optimizing signals and stops
2. applystop
3. position sizing (including portfolio testing)
4. equity curve

When you get to more advanced stuff, there's Marcin or Thomazs, or the dudes in here, or AB online library or yahoo AB users group.
 
Nothing wrong with your software.

If you code 1000 systems, expect the first 999 to give you a negative return. That's pretty normal. And the 1 that is positive will have a ****house equity curve!!

You've only just started. You'll need play around a lot (months to years) to get a system that satisfies you, ie. is positive and has a nice equity curve.

Ok. I appreciate the help. I'll have a play around with it a bit more and try to get my head around it.

How long did it take you to become proficient at using the backtesting feature?
 
A long time, but I had no background in coding at all. Self taught.

I'm not an expert. I just know how to do what I want to do most of the time.

Your initial interest is in looking at breakouts, as a function of HHV. Go with that. It should be easy to code for.

Hint:

a = HHV(H,25);
aa = ref(a,-1);
aaa = c>=aa;
 
A long time, but I had no background in coding at all. Self taught.

I'm not an expert. I just know how to do what I want to do most of the time.

Your initial interest is in looking at breakouts, as a function of HHV. Go with that. It should be easy to code for.

Hint:

a = HHV(H,25);
aa = ref(a,-1);
aaa = c>=aa;

So the first one is the highest high value of the last 25 days.

What do the other 2 lines of code represent?
 
Top