Money management type automated switching

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #116482 quote
    Vonasi
    Moderator
    Master

    Following on from an idea that I had in a discussion elsewhere I have coded this modification of one of my (I think it was mine!) money management systems. This version now automates the switch from one money management type to another after a certain number of trades has occurred and the strategy has reached a certain level of profit. This means for example that you can start trading without money management and then once 100 trades has happened and the strategy has reached 5% profit then money management can be turned on and position size increased based on your equity.

    If you don’t want to switch then set both money management types to the same value.

    I have just written this and have not tested it as time is short today. I think it should work but if someone else wants to test it for me that would be great as I rarely code anything correct first time! I just had to get this idea started while I ate my breakfast!

    Once MoneyManagement = 0    //Set to 0 for level stakes. Set to 1 for increasing stake size as profits increase and decreasing stake size as profits decrease. Set to 2 for increasing stake size as profits increase with stake size never being decreased.
    Capital = 10000
    MinSize = 1                 //The minimum position size allowed for the instrument.
    MM2ndType = 1               //Type of money management to switch to after TradesQtyForSwitch number of trades has occurred
    TradesQtyForSwitch = 100    //Quantity of trades required before switching to second money management choice.
    ProfitNeededForSwitch = 5   //% profit needed before allowing a money management type change.
    
    Equity = Capital + StrategyProfit
    
    if not EnoughTrades then
    if abs(countofposition) > abs(countofposition[1]) then
    tradecount = tradecount + 1
    endif
    if tradecount > TradesQtyForSwitch and Equity >= Capital * (1 + (ProfitNeededForSwitch/100)) then
    EnoughTrades = 1
    MoneyManagement = MM2ndType
    endif
    endif
     
    IF MoneyManagement = 1 THEN
    PositionSize = Max(MinSize, Equity * (MinSize/Capital))
    ENDIF
     
    IF MoneyManagement = 2 THEN
    PositionSize = Max(LastSize, Equity * (MinSize/Capital))
    LastSize = PositionSize
    ENDIF
    
    IF MoneyManagement <> 1 and MoneyManagement <> 2 THEN
    PositionSize = MinSize
    ENDIF
     
    PositionSize = Round(PositionSize*100)
    PositionSize = PositionSize/100
    GraHal and Kovit thanked this post
    #116487 quote
    GraHal
    Participant
    Master

    How about a further mod … turn the MM back off if the last * Trades made * per cent Loss?

    #116510 quote
    GraHal
    Participant
    Master

    See here for a > £3k difference due to your code above Vonasi!

    Nice one, thank you!

    https://www.prorealcode.com/topic/dow-2h-trend-chaser-v4-mm/#post-116508

    #116526 quote
    Vonasi
    Moderator
    Master

    How about a further mod … turn the MM back off if the last * Trades made * per cent Loss?

    Keeping a track of the last x trades would really require arrays to store the trade data. Without them we would really only be able to code for a very limited number of trades and it would all be a bit clunky as coding goes!

    Another option is to record the highest equity and switch off money management if equity then falls x% below this. So if draw down is higher than expected then we can return to minimum stake size. What do you think?

    GraHal thanked this post
    #116527 quote
    Vonasi
    Moderator
    Master

    Here is the idea in my last post.

    It works the same as the first version for switching money management types after x trades and x% profit has been reached. It also records the highest equity and if draw down reaches a set level then it switched the money management back to your chosen type 1. At this point the trade count is reset to zero. Then if the strategy starts performing well again then once there has been enough trades and profit has risen the desired level above the highest equity then the money management type is changed back to your chosen type 2.

    I also added a function to stop the strategy if a maximum draw down level has occurred. This is draw down from the maximum equity achieved. Only closed positions are considered.

    (not tested much!)

    Capital = 10000
    MinSize = 1                 //The minimum position size allowed for the instrument.
    MM1stType = 0               //Starting type of moneymanagement. Set to 0 for level stakes. Set to 1 for increasing stake size as profits increase and decreasing stake size as profits decrease. Set to 2 for increasing stake size as profits increase with stake size never being decreased.
    MM2ndType = 1               //Type of money management to switch to after TradesQtyForSwitch number of trades and ProfitNeededForSwitch profit has occurred
    TradesQtyForSwitch = 100    //Quantity of trades required before switching to second money management choice.
    ProfitNeededForSwitch = 5   //% profit needed before allowing a money management type change to MM2ndType.
    DrawdownNeededToSwitch = 10 //% draw down from max equity needed before money management type is changed back to MM1stType.
    DrawdownNeededToQuit = 50   //% draw down from max equity needed to stop strategy
    
    Once MoneyManagement = MM1stType
    
    Equity = Capital + StrategyProfit
    maxequity = max(equity,maxequity)
    
    if equity < maxequity * (1 - (DrawdownNeededToSwitch/100)) then
    enoughtrades = 0
    tradecount = 0
    moneymanagement = MM1stType
    endif
    
    if equity < maxequity * (1 - (DrawdownNeededToQuit/100)) then
    quit
    endif
    
    if not EnoughTrades then
    if abs(countofposition) > abs(countofposition[1]) then
    tradecount = tradecount + 1
    endif
    if tradecount > TradesQtyForSwitch and maxequity >= Capital * (1 + (ProfitNeededForSwitch/100)) then
    EnoughTrades = 1
    MoneyManagement = MM2ndType
    endif
    endif
     
    IF MoneyManagement = 1 THEN
    PositionSize = Max(MinSize, Equity * (MinSize/Capital))
    ENDIF
     
    IF MoneyManagement = 2 THEN
    PositionSize = Max(LastSize, Equity * (MinSize/Capital))
    LastSize = PositionSize
    ENDIF
    
    IF MoneyManagement <> 1 and MoneyManagement <> 2 THEN
    PositionSize = MinSize
    ENDIF
     
    PositionSize = Round(PositionSize*100)
    PositionSize = PositionSize/100
    GraHal thanked this post
    #116555 quote
    GraHal
    Participant
    Master

    Above added as Log 194 here …

    Snippet Link Library

    Vonasi thanked this post
    #116577 quote
    Vonasi
    Moderator
    Master

    After a little testing I spotted a cut and paste error that stopped the money management working with position sizes less than 1. I’ve corrected the code in the previous posts.

    #116579 quote
    Vonasi
    Moderator
    Master

    I’ve had the idea that switching the money management on or back on would be best done after a rise from a lowest equity. So for example we have a 5% draw down and so money management is switched off and we trade just level stakes at minimum position size but the strategy continues to perform badly and equity continues to drop. Eventually it rises from a low point by 10% and so we switch money management back on.

    It’s too late now to code it so I’ll try to find some time tomorrow or add it to my list!

    #121484 quote
    Fran55
    Participant
    Veteran

    In the first code.

     

    As i do so that the máximum position Is 10€ pip And continúe trading with the figure.

     

    And if someOne can explain The “switches”, or i dont know, ir they dont work.

    Thanks!!!

    #121581 quote
    Fran55
    Participant
    Veteran

    Si.

    I have solution.

     

    Thanks???

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

Money management type automated switching


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 9 replies,
has 3 voices, and was last updated by Fran55
5 years, 11 months ago.

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