Assemble two money management codes

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #45133 quote
    Jessar
    Participant
    Senior

    Hello could help me these two MM codes to build that they function with each other

     

    1.

    once multiplier=1
    once fraction=1000
    once newlevel=1000
    once oldlevel=1000
    once startpositionsize= 10
    once positionsize=startpositionsize
    if sp>newlevel then
    multiplier=multiplier+1
    oldlevel=newlevel
    newlevel=sp+multiplier*fraction
    positionsize=multiplier*startpositionsize
    elsif sp<oldlevel and multiplier>=2 then
    newlevel=sp
    oldlevel=sp-multiplier*fraction
    multiplier=multiplier-1
    positionsize=multiplier*startpositionsize
    endif

     

    2.

    once os=positionsize //3 // ordersize – can be any number depending on account size;

    once osa=os

    once teilung=1// 1.5 //1.5 reducing the ordersize after winning trade

    once ff=3 //increasing ordersize after losing trade;

    once maxcon=ff*os //ff*ff*os+os// defining the maximum ordersize;

     

    if strategyprofit<strategyprofit[1] then // increasing ordersize when losing
    os=os*ff
    if os>maxcon then
    os=maxcon
    endif
    start=1
    endif

    if strategyprofit>strategyprofit[1] then // decreasing ordersize when winning
    start=1
    os=os/teilung
    if os<osa then
    os=osa
    endif

    #45163 quote
    Jessar
    Participant
    Senior

    he second code is to double after a loss the position size until the capital has reached the last highest level before the loss.

    an example

    start 1000

    trade profit with 10 positions1100
    trade profit with 10 positions 1200
    trade profit with 10 positions 1300
    trade loss with 10 positions 1100
    trade loss with 20 positions 700
    trade profit with 20 positions 900
    trade profit with 20 positions 1100
    trade profit with 20 positions 1300 (> 1300) = last highest score
    next trade again with 10 positions

    #45217 quote
    Despair
    Blocked
    Master

    The first looks like an old version of my fixed fraction MM. I raised it since then to calculate correctly also when start equity is <>0. Now you ask for the code for a martingale. I code this long ago. Haven’t looked at the code for a long time so there might be an error inside (but maybe not). Here you go:

    //-------------------Martingale------------------------
    if martingale then
       inccounter=1
       if strategyprofit[1]>=saldo then
         positionsize=startpositionsize
         alreadyinc=0
         saldo=strategyprofit[1]
       endif
       if not onmarket and not alreadyinc then
         while positionperf(inccounter)<0 do
           inccounter=inccounter+1
           if positionsize<maxpositionsize then
           positionsize=positionsize*2
           endif
         wend
       alreadyinc=1
       saldobar=barindex-tradeindex(inccounter)
       saldo=strategyprofit[saldobar]
     endif
     if alreadyinc and saldo>strategyprofit[1] and tradeindex=barindex and posit ionperf(1)<0 then
       if positionsize<maxpositionsize then
         positionsize=positionsize*2
       endif
     endif
     if onmarket then
       positionsize=abs(countofposition)
     endif
    endif
    #45256 quote
    Jessar
    Participant
    Senior

    I thank you you really does a very good work here in the forum, I hope I can help you synonymous times

    #45258 quote
    Jessar
    Participant
    Senior

    I still have problems with the code,

    my first question is what do I do with the variable martingale?

    with maxpositionsize I could set it that the code me doubled only once the old capital is reached, then I can use in however no longer with the first code

    the last is the still works but still not with the first code it no positions increased after the adjusted capital gain (eg 1000 as adjusted)

    #45261 quote
    Jessar
    Participant
    Senior

    so simply said I would have the increase of the position size after a loss only once to reach the old peak level is synonymous if several losses come in series, and I just do not understand why it no longer with the here first code to increase the positions after reach the Capital gains.

     

    I would also have an idea, I believe it would be better positions to increase point gains not for money gains, which would somehow look like strategyprofit divided by position size?

    #45262 quote
    Despair
    Blocked
    Master

    The two codes are not thought to work together. The martingale is reseting the position size to startpostionsize. You will have to change this to make it work. Then I haven’t thought through if this two codes work together or if there are other problems.

    The martingale variable is only a switch turn it on/off.

    For the money management better use this revised code:

    //------------ Fixed fraction money management ----------
    once multiplier=1
    once startpositionsize=1
    once positionsize=startpositionsize
    once delta=100
    once fraction=delta*pipvalue
    once newlevel=delta*pipvalue
    once oldlevel=delta*pipvalue
    if strategyprofit+startequity>newlevel then
      i=0
      oldlevel=newlevel
      newlevel=0
      while newlevel<=strategyprofit+startequity do
       i=i+1
       newlevel=newlevel+i*fraction
      wend
      multiplier=i
      positionsize=multiplier*startpositionsize
    elsif strategyprofit+startequity<oldlevel and multiplier>=2 then
      newlevel=strategyprofit+startequity
      oldlevel=strategyprofit+startequity-multiplier*fraction
      multiplier=multiplier-1
      positionsize=multiplier*startpositionsize
    Endif
    #45294 quote
    Jessar
    Participant
    Senior

    thank you but it is not really what I was looking for

    #45311 quote
    Despair
    Blocked
    Master

    I’m aware of that. This is a revised version of one of the two codes you want to combine and I recommended you to take this version for your affords.

    Then I don’t see an advantage of using points instead of profit. points*pointvalue=strategyprofit and since pointvalue is a constant it doesn’t really make a difference if you use points or profit.

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

Assemble two money management codes


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Jessar @jessar Participant
Summary

This topic contains 8 replies,
has 2 voices, and was last updated by Despair
8 years, 5 months ago.

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