Money managment

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #106518 quote
    kalleklovn
    Participant
    Junior

    Hi i was wondering how to create a code for money managment.

     

    Eksample: you start with 500$ with one lot size. When money doubles it will double the lot size to 2 and then when you double again it will add 4 lot sizes.

    It would be nice to have on the autotrading so i dont need to stop it to adjust my position.

     

    Thanks for the help 🙂 Stay green

    #106521 quote
    Vonasi
    Moderator
    Master
    capital = 500
    equity = capital + strategyprofit
    once lastchange = capital
    once positionsize = 1
    
    if equity > lastchange * 2 then
    positionsize = positionsize * 2
    lastchange = lastchange * 2
    else
    if equity < lastchange / 2 then
    positionsize = max(1,positionsize / 2)
    lastchange = lastchange / 2
    endif
    endif
    
    if (your conditions) then
    buy positionsize contracts at market
    endif

    Not tested. This code also reduces the size if you lose. Delete lines 9 to 13 if you don’t want to do that.

    kalleklovn thanked this post
    #106527 quote
    kalleklovn
    Participant
    Junior

    Thanks i will try it out. Just one quick question. If im adding this to a strategy what do i den add in the  (your conditions)?

    Im not a good programer 🙁

    #106528 quote
    Vonasi
    Moderator
    Master

    A slightly better way to do it in my mind is like this:

    capital = 500
    positionsize = max(1,1 +(round((strategyprofit/capital)-0.5)))

    This does not double the position size but increments or decrements it by 1 for every 500 won or lost by a strategy down to a minimum stake size of 1.

    kalleklovn thanked this post
    #106558 quote
    Vonasi
    Moderator
    Master

    If im adding this to a strategy what do i den add in the  (your conditions)?

    Where ever you like above or below the money management code as long as it is below any DEFPARAM line.

    I had a chance to test my first example and there is a minor issue that if your strategy profit jumps from 500 to 1500 then you will have to wait for two bars before the position size is doubled twice. This might not be an issue on a strategy that makes small wins but on a long term buy and hold strategy that takes big profits or big losses then it might be.

    kalleklovn thanked this post
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Money managment


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
kalleklovn @kalleklovn Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Vonasi
6 years, 5 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/04/2019
Status: Active
Attachments: No files
Logo Logo
Loading...