Compounding position size with profits

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #115914 quote
    D Paul Al
    Participant
    New
    Hi There, Thank you in advance for any help you provide. What I am trying to achieve is scaling the position size based upon the increase or decrease of capital as the automated trading system runs. I trade CFD’s with IG Markets and because they are leveraged I have to use Margin. The number of contracts to purchase on any trade is calculated based upon how much margin said contracts will consume as a percentage of my capital, defined as risk. As the system trades and profits (or losses), I would like to readjust the number of contracts based upon the increase in capital, as the price will be changing. For example, $500 with 50% risk may allow me to purchase 250 contracts, and by making a trade that generates a profit where my total capital increases to $600, I would like it to calculate how many contracts I can purchase with this increase in capital.

    Your overall margin requirement is calculated as follows: Without a stop Margin = Size x price x margin factor With a non-guaranteed stop1 We calculate your margin with a non-guaranteed stop, compare it to the margin required without a stop, and charge the lower of the two figures as margin. Margin = (size x price x slippage factor x margin factor) + (size x stop distance)

    Just some FYI’s: Margin Factor, Slippage Factor, Min Size are all set manually based upon the instrument at the broker. SetLoss, Risk are what I set.
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    DEFPARAM Preloadbars = 2000
    REM Money Management
    Capital = (500 + POSITIONPERF(1))
    MarginFactor = 0.25
    SlippageFactor = 1.0
    MinSize = 1
    SetLoss = 50
    Risk = 0.5
    M1 = (MinSize * High[1] * SlippageFactor * MarginFactor)
    M2 = ((MinSize * High[1] * SlippageFactor * MarginFactor) + (MinSize * SetLoss))
    IF M1 <= M2 then
    PositionSize = (ROUND((Capital/M1)*Risk))
    ELSE
    PositionSize = ((ROUND((Capital/M2))*Risk))
    ENDIF
    
    // Conditions to enter long positions
    indicator1 = Average[10](low)
    indicator2 = ExponentialAverage[20](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    indicator3 = Average[10](low)
    indicator4 = ExponentialAverage[50](close)
    c2 = (indicator3 >= indicator4)
    c4 = (indicator2 CROSSES OVER indicator4)
    c5 = (close >= ExponentialAverage[10](close))
    c6 = (close >= ExponentialAverage[50](close))
    c8 = TRADEPRICE(1)
    
    IF (c1 AND c2) OR (C4) OR (C5 AND C6 AND C8) THEN
    BUY POSITIONSIZE CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator5 = Average[10](low)
    indicator6 = ExponentialAverage[50](close)
    c3 = (indicator5 CROSSES UNDER indicator6)
    indicator7 = low[1]-((AverageTrueRange[14]*2))
    c7 = (close <= indicator7)
    c9 = (close <= ExponentialAverage[50])
    c10 = (close <= (low[2]-(2*AverageTrueRange[14])))
    
    IF c3 OR c7 OR C9 OR C10 THEN
    SELL AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pLOSS SetLoss
    
    #116088 quote
    nonetheless
    Participant
    Master
    Check this out, could be what you want: https://www.prorealcode.com/blog/learning/money-management-prorealtime-code/ Or run a search for Money Management, you’ll find some examples that you should be able to adapt.
    #116092 quote
    Vonasi
    Moderator
    Master
    D Paul Al

    >> Please update your country flag in your profile. Thank you 🙂 <<

    #191795 quote
    BreakState
    Participant
    New
    Am working on similar, and have added the position size script. How is yours working?
    #191797 quote
    jacques34
    Participant
    Average
    bonjour,   J’ai survolé votre code , et vous indiquez dans votre condition d’achat ligne 31 la condition c8. C8 est défini ligne 29 comme TRADEPRICE(1) c’est à dire le prix de la dernière transaction est non comme une condition. N’auriez vous pas oublié une instruction… hello, I hovered over your code, and you indicate in your condition of purchase line 31 the condition c8. C8 is defined line 29 as TRADEPRICE ( 1 ) ie the price of the last transaction is not as a condition. Didn’t you forget an instruction…
    #191801 quote
    robertogozzi
    Moderator
    Master
    @jacques34 Only post in the language of the forumthat you are posting in. For example English only in the English speaking forums and French only in the French speaking forums. Thanks 🙂
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Compounding position size with profits


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
D Paul Al @d_paul_al Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by robertogozzi
3 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/05/2020
Status: Active
Attachments: No files
Logo Logo
Loading...