Position sizing discrepancies between calculation, backtest and realtime

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #105709 quote
    ThallyThally
    Participant
    Average

    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:

    1. PositionSizeL calculated by the above function = 3
    2. The position size implemented in the backtest = 10
    3. The position size implemented in realtime = 10
    4. 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?

    Screenshot-2019-08-28-at-09.39.20.png Screenshot-2019-08-28-at-09.39.20.png
    #105712 quote
    NicolasNicolas
    Keymaster
    Legend

    Minimal size of contracts for that specific instrument? Did you try with CONTRACTS in backtests instead of PERPOINT?

    #105714 quote
    ThallyThally
    Participant
    Average

    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?

    #105716 quote
    NicolasNicolas
    Keymaster
    Legend

    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.

    #105718 quote
    ThallyThally
    Participant
    Average

    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.

    #105719 quote
    ThallyThally
    Participant
    Average

    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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Position sizing discrepancies between calculation, backtest and realtime


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Thally @rodger_dodger Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by ThallyThally
7 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/28/2019
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...