Hello Roberto, hello Grahal, hello et al
I went back here to pick up the idea that when the take profit of the trade (2%) is reached, the highest capital ever reached increases by 1% at the same time.
In other words
In a trading system, we increase the position size so that when the trade reaches its target profit, the highest capital ever achieved grows by 1%.
This is especially interesting for systems with a time stop (e.g. defparam flatafter = 210000). Here the target profit is not always reached and therefore the highest capital ever reached does not grow by 1% despite a won trade, or a new highest capital ever reached is not even formed.
Ex.
maxcapital = 10.000 Euro
available capital = 8,600 euros
Position size = 10.56
Profit in trade = 20 Euro
The task now is to calculate for the next trade what position size must be traded if the next trade (exceptionally) reaches its profit target and thus the highest capital ever reached grows by 1%.
target profit trade = 2%
target profit capital = 1% (12.100 auf 12.221)
The question of this type of calculation has already been raised here and there and also by me.
Again Moneymanagement calculate
Strategyprofit on fixed tp
I have worked through all the links above again and I have come to the following coding.
But somehow I have the feeling that my coding cannot be correct.
That’s why I’ve added the code below, including comments.
The comment should show what exactly I want to get with the lines of code
With comments marked with “**” I am unsure whether the intended result is get
So please take my thoughts on board and confirm the code as correct or, more likely, correct it.
Many thanks in advance.
For this is no rush.
//---------------------------------------------------------
// moneymanagement maxcapital
// using the example Average Cross
// created by JohnScher coded with the help of friends
//---------------------------------------------------------
// Basic settings
defparam cumulateorders = false
defparam flatbefore = 080000
defparam flatafter = 210000 // timestop
// moneymanagement
once capital = 10000 // set capital to 10,000 as an once-only basis
once maxcapital = capital // set the highest capital ever achieved the an once-only basis **
equitity = capital + strategyprofit // the available capital is calculated from the capital plus the strategy profit
maxcapital = max(maxcapital,equitity) // the highest capital ever achieved is fixed as highest capital ever achieved **
tpTrade = close/100*2 // calculates the target profit of the trade, here 2% of the price, this corresponds to the instruction "set target %profit 2" **
tpCapital = (maxcapital + maxcapital/100*1) - equitity // calculates the target profit in the capital, here 1% **
lotsize = round(tpCapital/tpTrade,2) // calculates the position size in the way that when the target profit of the trade is reached, the target profit in the capital too **
If equitity >= maxcapital then
ordersize = 1 // in the case that the available capital is greater than the highest capital ever reached, the position size is set to 1
Elsif equitity < maxcapital then
ordersize = lotsize // in the case that the available capital is lower than the highest capital ever reached, the position size is calculated as in line 20
Endif
If ordersize < 1 then
ordersize = 1 // for any reason the position size falls below 1, the position size is set to 1
endif
// tradingsystem
tradebuy = average [20] (close) crosses over average [50] (close)
If tradebuy then
buy ordersize contracts at market
endif
set stop %loss 10
set target profit tpTrade
//give-away
graph maxcapital