Position Sizing Based on Current Account Size

Hi NT Community

I am recently writing a backtesting script. I would like to compound the position size based on a percentage risk r% of the account size. However, I couldn’t find any reference code or existing scripts like that. Can someone help me out or point me to the right direction? Thank you

NVM, I have figured out. It turns out I have to calculate the account balance on historical data.

Sweet, glad you figured it out and shared the answer. Appreciated.

could you not just do the calculation on IsFirstTickOfBar?