I am trying to code a simple logic for position sizing using 100% of the equity, rounded to the nearest thousand. For example, if the starting balance is $10,000 and the current equity after a few trades is $11,235, I want to use $11,000 divided by the share price for the next position size instead of using $11,235. I came up with the solution below using the Equity() function, but it doesn't seem to provide the correct position size. Could someone provide me with some insights on how to improve this solution? Thank you in advance.

the exact dollar equity amount is only available phase 2 of the backtester.
For what you want to achieve, I would recommend using SetPositionSize( 100, spsPercentOfEquity ) in the first phase of the backtest and then do the rest of the calculations in phase 2, using CBT Mid-level approach. (this link is very helpful, especially example 2 mid-level : [http://www.amibroker.com/docs/Houston2.pdf] )
The docs in Knowledge base are also very helpful.

Hi beppe, thanks for the response. I used floor as well in my previous testing but doesn't seem to work. Probably it's related to the Equity() function

Please note that Equity is a SUM of all open positions value and cash. You won't be able to open position equal to portfolio equity if you have any open positions already.

You should rather use bo.Cash which is the currently available cash for purchases.