ok, so (nLots*(high * Margin / 100)) wouldn’t work, but it should represent the margin value of the position size shouldn’t it?
Yes, it’s the total margin requirement.
Your account could have just that little money, provided your trade always stays above entry price.
Ciao Roberto, I was thinking of a way to vary the speed of change after some profit has accrued – what do you think of this:
ONCE LotManagement = 1 //1=enable LOT size management
ONCE DD = 825 //825 DrawDown
ONCE MyMargin = 0.5 //0.5% margin required by the broker
ONCE ProfitAccrued = 0 // if strategy is stopped and restarted, insert profit or loss to date in instrument currency
DDmultiplier = 3.0 //3.0 DD multiplier
if ProfitAccrued + StrategyProfit >= DD then
DDmultiplier = 2
elsif ProfitAccrued + StrategyProfit >= DD*2 then
DDmultiplier = 1.5
endif
ONCE MyCapital = ((DD * DDmultiplier) + (high * MyMargin / 100))
IF IntraDayBarIndex = 0 THEN
MyCapital = ((DD * DDmultiplier) + (high * MyMargin / 100))
ENDIF
ONCE MinLots = 1
ONCE InitialSize = 1
ONCE nLots = InitialSize
IF LotManagement THEN
MyEquity = MyCapital + ProfitAccrued + StrategyProfit
MyInvestment = MyEquity / MyCapital
TempLot = InitialSize * MyInvestment
TempLot = round((TempLot * 10) - 0.5) / 10
nLots = max(MinLots,TempLot)
ENDIF
Does that look right to you? I wasn’t sure where the new code should be inserted.
Yes, it’s correct. It’s an interesting idea.
Another idea would be to update DrawDown at runtime. This your code with this idea embedded:
ONCE LotManagement = 1 //1=enable LOT size management
ONCE DD = 825 //825 DrawDown
ONCE MyMargin = 0.5 //0.5% margin required by the broker
ONCE ProfitAccrued = 0 // if strategy is stopped and restarted, insert profit or loss to date in instrument currency
DDmultiplier = 3.0 //3.0 DD multiplier
ONCE MyCapital = ((DD * DDmultiplier) + (high * MyMargin / 100))
// update DrawDown
ONCE MaxPoint = 0
MyEquityx = MyCapital + ProfitAccrued + StrategyProfit
MaxPoint = max(MaxPoint,MyEquityx)
DDx = MaxPoint - MyEquityx
DDPerCent = DDx / MaxPoint * 100
DD = max(DD,DDx) //compute new DD
MaxDDPerCent = DD / MaxPoint * 100 //DD percentage
// end update
if ProfitAccrued + StrategyProfit >= DD then
DDmultiplier = 2
elsif ProfitAccrued + StrategyProfit >= DD*2 then
DDmultiplier = 1.5
endif
IF IntraDayBarIndex = 0 THEN
MyCapital = ((DD * DDmultiplier) + (high * MyMargin / 100))
ENDIF
ONCE MinLots = 1
ONCE InitialSize = 1
ONCE nLots = InitialSize
IF LotManagement THEN
MyEquity = MyCapital + ProfitAccrued + StrategyProfit
MyInvestment = MyEquity / MyCapital
TempLot = InitialSize * MyInvestment
TempLot = round((TempLot * 10) - 0.5) / 10
nLots = max(MinLots,TempLot)
ENDIF
You can get rid of DD percentages, if you are planning not to use them.
So, this would continually monitor actual DD?
But as positionsize increases, obviously the DD will also increase – at least proportionally. Wouldn’t that mitigate against the objective of placing larger positions in line with performance?
Yes, and that would surely mitigate performances. It’s an idea for those with a geater risk aversion attitude.
Of course it’s contrary to your idea of speeding up change as gains accrue.
I posted it just as an idea, like many others.
Money, Risk and Lot size management snippets, as well as those to trail SL, are a great battlefield for new ideas and tests.
@robertogozzi, ciao Roberto, as discussed above, I’ve normally been doing backtests @ minimum positionsize and using the max drawdown as the basis for the Money Management.
//MONEY MANAGEMENT II
MM = 0 // = 0 for optimization
if MM = 0 then
positionsize = 0.2
ENDIF
if MM then
MinSize = 0.2 // IG minimum position size allowed
MaxSize = 550 // IG tier 2 margin limit
ProfitAccrued = 0 // when restarting strategy, enter profit or loss to date in instrument currency
DD = dd //MinSize drawdown in instrument currency
Multiplier = 3 //drawdown multiplier
Capital = DD * Multiplier
Equity = Capital + ProfitAccrued + StrategyProfit
PositionSize = Max(MinSize, Equity * (MinSize/Capital))
if positionsize > MaxSize then
positionsize = MaxSize
endif
PositionSize = Round(PositionSize*100)
PositionSize = PositionSize/100
ENDIF
I have now started doing backtests with a constant exposure value, ie positionsize = 7000/close
This gives a more accurate picture of past performance, but usually results in much higher DD
For example, a code I’m now working on gives a DD of 400 with positionsize = 0.2, but rises to 1650 with positionsize = 7000/close
Obviously when running live I would be starting at 0.2 (very close to 7000/close at present values).
But which number would you use for the MM calculation — 400 or 1650 ???
I realise that there’s no ‘right answer’ but curious to know your opinion on this, thanks.
(or anyone else’s opinion!)
The greater the number of lots, the higher the DD is, as it’s simply the exposure. If you suffer at most, say, 100 euros on Dax €1 with 1 lot, the same DD will reach 200 euros with 2 lots, etc….
You should always use the most recent DD as displayed by PRT when you have finished optimizing with MM disabled. At that point, after coding the correct DD, you can enable MM for a final backtest before starting your code into autotrading.
You only have to care for the initial number of lots, as each increase of that number at runtime will be consequent to a higher equity available on your account owing to accumulated profits.
thanks Roberto, that is more or less what i had been thinking – good to have some confirmation 😁
Thank you both for this discussion, I understood almost everything but unfortunately not really everything because my brain blocks a little bit on the 825, someone can give me a good explanation or a concrete example how do you get this number (what initial capital?, what trading instrument?, …. )
I think that when I have a concrete example I could then try to give my opinion on the variable DDmultiply