PositionSize and SetPositionSize functions causing different backtest results

Hi Guys

I'm getting significantly different backtest results between two backtests where the only difference is how I'm coding amount invested per trade. For both tests I'm saying to invest $50,000 per trade. The only difference are the functions I'm using to specify amount per trade.

The first test uses the PositionSize function:

PositionSize = 50000;

The second test uses the SetPositionSize function:

SetPositionSize( 50000, spsValue );

or alternatively:

EntryQty = 50000 / Close;
SetPositionSize( EntryQty, spsShares );

Here are the results for the first test:

Here are the results for the second test:

The trades lists are significantly different. Both trades lists contain trades that follow the system's rules. I don't know why this one difference is causing completely different (yet correct) trades to be taken.

This is a very simple strategy that only has two parameters for entry and exit. All backtest settings are exactly the same between the two tests. Beginning equity is $100,000. Even if I only trade $1,000 per trade, allowing many open trades at once, results are different, albeit not as significantly different as the tests that invest $50,000 per trade.

Results should be the same but they are not. Something between these two methods of specifying trade size is causing very different results as that's the only difference. Does anyone know why the results are different?

Which method should be used and why?

Thank you,

You should be getting exactly the same results if you use

PositionSize = 50000;


SetPositionSize( 50000, spsValue ); // this is the same as PositionSize = 50000;

because both methods actually set PositionSize variable to exact same value.

If you are not getting same results, the reason is elsewhere http://www.amibroker.com/kb/2014/05/07/why-do-backtest-results-change/

Third method is completely different. It is unclear what method you actually used because you wrote about 3 methods, yet there are only two screenshots.

EntryQty = 50000 / Close;
SetPositionSize( EntryQty, spsShares );

Doing so you would be getting different results because: a) you may be using different price than close for entries, b) you are not applying proper FX rate, c) roundlotsize and other things differ, d) you are calculating shares out of "gross" value (not after commissions) and more... Generally do NOT use this kind of code.

I am the same problem as parisk described it. I am using the 6.35 version.

When I use 'PositionSize = 5000', I would expect to see 'Initial capital' to be 5000 in the report?
The backtest is done with 5000 position size (see red marker on the right) but in the report the it shows 20000 as set in the settings (blue).
The problem is that the values in the report are therefore incorrect because the report takes the correct netprofit of 4187.00 (black) but divides this by 20000 instead of 5000.

Any idea what I am doing wrong? Thanks!

@Thoz, Welcome to the Forum.

Please read the "How to use this site" and get yourself the "Verified Badge".

You can use the Search to find the details.

Verification completed

"Position size" and "Initial capital" are two different concepts:

  • Initial capital represents the money you have to invert initially. As buy and sell operations are generated this quantity changes: It grows up when operations ends with profit, and gets lower when you have losses.

  • Position size is the quantity you want to invert when the system generates a new Buy signal. If you don't set the "Position size" value, the system will use all of the avaliable capital in every operation.

BTW, to set the "Initial Capital" value to 5.000 you can use:

SetOption("InitialEquity", 5000);

Thank you, LeoCV.

Good point. I then need to be careful that the first trade isn't a loss otherwise the next trades wont continue.

I need to play around with the report especially for the individual backtest and perhaps define additional metric if needed.