Position Sizing

I am watching Dave McLachlan's video series and I have a basic question regarding position sizing when creating these trading algorithms. If I create a MaxPositionSize of 20, and I backtest it against the S&P 500, how does the algorithm determine which stocks to buy? If 40 meet the criteria, or 15? How do the positions determine how to fill?

If the model is actually run and set to trade, again, how does it determine what issues to buy if more than 20 are acceptable to purchase based on the rules of the algorithm?

@Floridafan you need to learn how to use PositionScore.

More details in the Portfolio-level backtesting documentation.


In addition to @beppe's advice, you need to distinguish between Max Positions (how many trades can be open simultaneously) and Position Size (how large is each position). For the latter, see the documentation for SetPositionSize(): https://www.amibroker.com/guide/afl/setpositionsize.html.