Changing only sell condition - increases number of trades. How is this possible?

Performed two backtests both using the same formula file, same stock group, same buy conditions, same settings. The only difference is sell conditions between the tests. Test 1 had 5 trades, all 5 are open. Test 2 had 386 trades, 2 remain open.

Is it possible to get different number of trades if the buy conditions are fixed? Shouldn't the buy conditions control the number of trades?

Any insights would be highly appreciated.

The bold text parts are contradiction.
If you change content of formula then it is not the same file as before.
It is different formula (file) than before (even if it is same formula name and same disk location).

Yes, it is.

//Test1
Buy = True;// every bar signal
Sell = False;// no exit
//Test2
Buy = True;// every bar signal
Sell = True;// every bar signal

Same Buy rules in Test1 and Test2 but different Sell rule -> different number of trades.

"How is this possible?"

Test1: does not exit.
Test2: Buy (entry) and Sell (exit) on every bar.

So obviously and unsurprisingly you will get different number of trades for test1 and test2 despite of same Buy rule.

No, entry rules alone do not control number of trades. Buy (entry) and Sell (exit) rules and other conditions such as whether portfolio of symbols or single security, backtest mode, ranking (also see symbol selection without positionscore), available capital, positions size, commissions, max. open positions,... etc. (also see SetOption) decide how many trades you will have at the end.

http://www.amibroker.com/guide/h_portfolio.html

Additional information on "...different results..." despite of same formula
http://www.amibroker.com/kb/2014/05/07/why-do-backtest-results-change/

5 Likes

Thank you so much for the helpful info. I will read on all the topics listed and appreciate this knowledge as I still have lots to learn.

The one issue i am still confused about is that, there was a different number of buy orders despite all other variables remaining constant except sell conditions including all the mentioned factors. It would make sense if the missing trades were "still open" but this is not the case.

it would make sense if the buys were the same number and the sells were different due to some remaining open.

thanks again and appreciate your time

Once again...

See "Backtest Modes" there. Default backtest mode is backtestRegular. For other modes you have to use SetBackTestMode() function. Link to that function is mentioned in previous post as well

So going back to the two test examples...
We modify codes for Test1 and Test2 as follows.

//Test1
SetPositionSize(1, spsShares);
SetBacktestMode(backtestRegularRawMulti);
SetOption("MaxOpenPositions", LastValue(Cum(Status("BarInRange"))));

Buy = True;// every bar signal
Sell = False;// no exit
//Test2
SetPositionSize(1, spsShares);

Buy = True;// every bar signal
Sell = True;// every bar signal

We apply to "Current" (symbol).
And we get same number of trades for that symbol.

12

13

1 Like

Thank you fxshrat, the explanation is very helpful and much appreciated