Help understanding/translating into code "Core Equity"

Hello Amibroker community.
I am a beginner in both Amibroker afl and coding in general. I understand some basic AFL and I am learning a lot from the Knowledge Base and the forum. The area i am having difficulty learning is the Custom Backtest procedure. The reason i bring CBT in discussion is because i suspect it is required for what i am trying to accomplish.

The idea i am working on is a concept called "Core Equity" developed by Ed Seykota.

Where "Core Equity = Total Equity - Equity at Risk" or Trading base remaining if all open positions Exit/Stop.

The idea is that you would reference the core equity for position sizing instead of total equity.
So for example I have 10000 inital equity. I size the position size as 1 % of equity at risk / into the stop size determined from the HHV - stop level. This i can understand and accomplish using:

riskpershare = HHV(H,20) - LLV(L,20);
percentofEquity = 10;
positionsize = percentofEquity * C/ riskpershare;
SetPositionSize(positionsize,spsPercentOfEquity);

Equity at risk would be 10%. So far so good. If i were to open an additional position my equity at risk would be 10%. Lets assume that the trade has not moved up or down and my Total Equity would be the same as before entering the first trade.
If I size the next trade in relation with Total Equity if would fail to take into account the 10% at risk and it would size the next position from the Total Equity(100%) where Core Equity would size it from 90% of Equity. This would seem to bring some benefits to smooth the equity swings in the portfolio.

This is at the moment beyond my understanding of translating into code, so I am asking the forum for help. Thank you for taking the time to read and appreciate any feedback.

Yes, I believe you would need to use a CBT to size your positions as you've described.

Don't forget to verify your license as described here: License Verified badge

Thread re-opened. User has verified his license now.