Compounding interest – increase position size automatically

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #69891 quote
    AlgoAlexAlgoAlex
    Participant
    Master

    Everyone sooner or later everyone get in touch with the “holy grail” of trading, the compound interest.

    Far from a philosophical discussion, I would like to share and discuss available codes in PRT to develope it in automatic trading.

    At the moment I only know this:

    n= 1+(ROUND((strategyprofit)/2500))  //every 2500 add a contract
    
    //where
    buy n contracts at market

    Is it possible to make a percentage version? When equity reaches 3% profit it adds n contracts? Do you know other alternatives?

    #69892 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    First you have to set up your initial equity and number of lots, later, when NOT OnMarket check if strategyprofit is > 3% of your equity and act accordingly:

    ONCE MyEquity = 10000
    ONCE nLots    = 1
    IF Not OnMarket THEN
       IF Strategyprofit >= (MyEquiti * 1.03) THEN
          MyEquity = Strategyprofit
          nLots = nLots + 1
       ENDIF
    ENDIF

    You must be aware that after increasing 3%, your equity could fall by 5% and you might want to decrease  the number of lots you are trading.

    AlgoAlex thanked this post
    #69901 quote
    AlgoAlexAlgoAlex
    Participant
    Master

    Thanks a lot Roberto.

    You must be aware that after increasing 3%, your equity could fall by 5% and you might want to decrease  the number of lots you are trading.

    Is it possible to code?

    #69905 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There you go

    ONCE MyEquity = 10000
    ONCE nLots    = 1
    IF Not OnMarket THEN
       IF Strategyprofit >= (MyEquity * 1.03) THEN
          MyEquity = Strategyprofit
          nLots = nLots + 1
       ELSIF Strategyprofit <= (MyEquity * 0.97) THEN
          MyEquity = Strategyprofit
          nLots = nLots - 1
          nLots = max(1, nLots)    //do not allow nLots to fall below 1
       ENDIF
    ENDIF
    AlgoAlex thanked this post
    #69913 quote
    GraHalGraHal
    Participant
    Master

    Above added to

    Snippet Link Library

    Thank You Roberto

    robertogozzi thanked this post
    #69954 quote
    LeoLeo
    Participant
    Veteran

    I use this

    // RISK CONTROL IF THINGS ARE GOING WONDERFULL
    n = 1 + (strategyprofit / (17*pipvalue))
    n=SQRT(n)
    n = round(n * 100)
    n = n / 100
    n = max(1,n)

    When the code wins 17*4=68 pips then it duplicate the size of lot.

    robertogozzi thanked this post
    #69963 quote
    GraHalGraHal
    Participant
    Master

    Above added to Snippet Link Library.

    I can’t see where the *4 comes from, but maybe I need to think about it more do I? 🙂

    #69968 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    I tried to figure out what 4 stands for, as well, since I’m not a fan of maths.

    I guess it has to do with the square root. If you are trading 4 contracts and want to double that number, if you take the square root if, which is two, then you’ll have to multiply it by 4 to get the correct number. Maybe GRAPH (or Leo) could help!

    GraHal thanked this post
    #69981 quote
    LeoLeo
    Participant
    Veteran

    Hi all,

    welll actually is not a 4, haha sorry.

    Look, the code is based in the strategy profit. Therefore I do not want something linear because when it wins the next trade is quite high. Which I choose and works well is the root fuction. Normally a trade quite small amount and very short period of times.

    Lets say, in this example (with strategyprift/17), when the code wins 17 pips then the next trade is 1+17/7=2 then root of 2 is 1.41… the next trade opens 1.41 lots

    next trade win another 17 pips, then 1+34/17=3, root of 3 equal 1.73. Next trade will open with 1.73 lots

    next trade win another 17 pips, it means that the strategy profit is 3 times 17 so, 1+51/17=4, root of 4 is 2 then

    when the strategy is 3 times the 17 then it opens 2 lots.

    in summary if the initial n=1 and you want to duplicate the number of lot after certain number of pips winning, then take the number of pips you desire divided by 3 and remplace the 17 in the code. For example. My initial lot is 1, after 100 winning pips I want to duplicate the number of lot by 2 then, the fist line of the code will be

    N=1+(strategyprofit/(33*pipvalue))

    hope I clarify the code.

    GraHal and robertogozzi thanked this post
Viewing 9 posts - 1 through 9 (of 9 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

Compounding interest – increase position size automatically


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
AlgoAlex @alexf Participant
Summary

This topic contains 8 replies,
has 4 voices, and was last updated by LeoLeo
8 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/06/2018
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...