Validate Position Sizing Code

I am trying to code Van Tharp Position Sizing to backtest one of my strategy, here is the code:

RiskPct = 1;
EntrySignal = HHV(H,_HHVOpt);
ExitSignal = LLV(L,_LLVOpt);
Stopsize = EntrySignal - ExitSignal;
SetPositionSize((RiskPct/Stopsize) * C, spsPercentOfEquity);
RoundLotSize = 1;

Is this correct approach?

Check out this page
https://www.amibroker.com/kb/2014/10/12/position-sizing-based-on-risk/

1 Like

Thanks @codejunkie was very helpful