Money management type automated switching
Forums › ProRealTime English forum › ProOrder support › Money management type automated switching
- This topic has 9 replies, 3 voices, and was last updated 4 years ago by Fran55.
-
-
01/12/2020 at 9:03 AM #116482
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!
12345678910111213141516171819202122232425262728293031323334Once 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 = 10000MinSize = 1 //The minimum position size allowed for the instrument.MM2ndType = 1 //Type of money management to switch to after TradesQtyForSwitch number of trades has occurredTradesQtyForSwitch = 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 + StrategyProfitif not EnoughTrades thenif abs(countofposition) > abs(countofposition[1]) thentradecount = tradecount + 1endifif tradecount > TradesQtyForSwitch and Equity >= Capital * (1 + (ProfitNeededForSwitch/100)) thenEnoughTrades = 1MoneyManagement = MM2ndTypeendifendifIF MoneyManagement = 1 THENPositionSize = Max(MinSize, Equity * (MinSize/Capital))ENDIFIF MoneyManagement = 2 THENPositionSize = Max(LastSize, Equity * (MinSize/Capital))LastSize = PositionSizeENDIFIF MoneyManagement <> 1 and MoneyManagement <> 2 THENPositionSize = MinSizeENDIFPositionSize = Round(PositionSize*100)PositionSize = PositionSize/10001/12/2020 at 11:16 AM #11648701/12/2020 at 2:05 PM #116510See 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
01/12/2020 at 4:39 PM #116526How 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?
1 user thanked author for this post.
01/12/2020 at 5:31 PM #116527Here 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!)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849Capital = 10000MinSize = 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 occurredTradesQtyForSwitch = 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 strategyOnce MoneyManagement = MM1stTypeEquity = Capital + StrategyProfitmaxequity = max(equity,maxequity)if equity < maxequity * (1 - (DrawdownNeededToSwitch/100)) thenenoughtrades = 0tradecount = 0moneymanagement = MM1stTypeendifif equity < maxequity * (1 - (DrawdownNeededToQuit/100)) thenquitendifif not EnoughTrades thenif abs(countofposition) > abs(countofposition[1]) thentradecount = tradecount + 1endifif tradecount > TradesQtyForSwitch and maxequity >= Capital * (1 + (ProfitNeededForSwitch/100)) thenEnoughTrades = 1MoneyManagement = MM2ndTypeendifendifIF MoneyManagement = 1 THENPositionSize = Max(MinSize, Equity * (MinSize/Capital))ENDIFIF MoneyManagement = 2 THENPositionSize = Max(LastSize, Equity * (MinSize/Capital))LastSize = PositionSizeENDIFIF MoneyManagement <> 1 and MoneyManagement <> 2 THENPositionSize = MinSizeENDIFPositionSize = Round(PositionSize*100)PositionSize = PositionSize/1001 user thanked author for this post.
01/12/2020 at 10:10 PM #11655501/13/2020 at 12:06 AM #11657701/13/2020 at 12:13 AM #116579I’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!
03/08/2020 at 2:33 PM #12148403/09/2020 at 4:05 PM #121581 -
AuthorPosts
Find exclusive trading pro-tools on