Position sizing discrepancies between calculation, backtest and realtime
Forums › ProRealTime English forum › ProOrder support › Position sizing discrepancies between calculation, backtest and realtime
- This topic has 5 replies, 2 voices, and was last updated 5 years ago by Thally.
-
-
08/28/2019 at 9:40 AM #105709
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
123456789101112// money managementONCE Capital = 5000ONCE Risk = 0.01equity = Capital + StrategyProfitmaxrisk = round(equity*Risk)PositionSizeL = abs(round((maxrisk/StopLossL)/PointValue)*pipsize)PositionSizeS = abs(round((maxrisk/StopLossS)/PointValue)*pipsize)// open a long position and implement stop lossBUY PositionSizeL PERPOINT AT MARKETStopLossL = abs(close - LOWEST[10](low)) + spSET STOP LOSS StopLossLIn 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?
08/28/2019 at 10:40 AM #10571208/28/2019 at 10:59 AM #105714Hi 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?
08/28/2019 at 11:14 AM #10571608/28/2019 at 11:21 AM #105718I 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.
08/28/2019 at 11:25 AM #105719 -
AuthorPosts
Find exclusive trading pro-tools on