Hi all,
I wonder if anyone can help me understand how PRT deals with position size calculation and execution. I recently posted a strategy (https://www.prorealcode.com/topic/is-this-system-too-good-to-be-true/) that uses Nicolas’ dynamic position sizing function to calculate the position size based on the distance to the stop loss and the percent of equity at risk.
Here’s a snippet of the position size function
// money management
ONCE Capital = 5000
ONCE Risk = 0.01
equity = Capital + StrategyProfit
maxrisk = round(equity*Risk)
PositionSizeL = abs(round((maxrisk/StopLossL)/PointValue)*pipsize)
PositionSizeS = abs(round((maxrisk/StopLossS)/PointValue)*pipsize)
// open a long position and implement stop loss
BUY PositionSizeL PERPOINT AT MARKET
StopLossL = abs(close - LOWEST[10](low)) + sp
SET STOP LOSS StopLossL
In the attachment you find a screenshot of the strategy implemented in realtime trading and also the backtest overlaid with the PositionSizeL variable graphed. You can see that:
- PositionSizeL calculated by the above function = 3
- The position size implemented in the backtest = 10
- The position size implemented in realtime = 10
- The initial equity was £5000 and the PositionSizeL function only permits positions to be opened with a max risk of 1% of the account equity, which in this example is £50. You can see from the screenshot that the amount that would be lost of the stop is hit is £176, more than double the max risk.
Can anyone explain the discrepancy between the graphed value of PositionSizeL = 3 and the position size implemented in the backtest and realtime trading? Does it have something to do with the ‘BUY … PERPOINT’ command? How does PRT pass the PositionSizeL number to the engine that actually implements the executed position size?
Minimal size of contracts for that specific instrument? Did you try with CONTRACTS in backtests instead of PERPOINT?
Hi Nicolas, thank you for the quick response. The minimum position size with IG for USDJPY is 0.5 per point. I have not tried with contracts in the backtest because IG operate CFDs and spread bets (which is what I trade) on a per point basis. Would this work in realtime if I had a code to buy say 2 contracts but IG execute in per point?
StopLossL is calculated after the position size calculation, you should invert it otherwise you are still using a previous StopLoss size when you compute the position size.
I think that’s it you can see from the attached screenshot that if I iterate 1 bar back the graphed PositionSizeL = 10 which is the same as the executed value – i.e. as you say the calculation is using the previous value. I am going to adjust the positions of the Stoploss and position size calculations and see if that solves this issue. Thank you for your help Nicolas.
That solved the issue. I am very grateful for your help here Nicolas. I have posted variants fo this issue here and to the PRT and IG help desk on several occasions with no success. Thanks and all the best.