Hello Roberto-
A big thank you for being on the road for me again and doing work.
It looks quite excellent, but it seems to me to be a bug that I can’t program away. But we are already very close to the solution.
With lines 28-33 we at myProfit set > 0 the equity to 100%. Clear.
But we also need to check whether myProfit >0 and the new capital exceeds 100%. We must not set the capital to 100% after each trade won, but only when we have won the trade and the last reached 100% are exceeded!
I think I have caught all imaginable combinations with the following example.
Example
Capital = 100%
1st trade ordersize = 1
Trade won, capital = 100.2%
set capital 100.2% to newCapital 100%
newCapital = 100%
2nd Trade Ordersize = 1
2.trade won, capital = 100.7%
set capital 100.7% to newCapital 100%
newCapital = 100%
3rd Trade Ordersize = 1
3. trade lost, capital = 99.2%
// do not set to 100%
newCapital 99.2%
4th trade calculate order size for the 4th trade so that when the take profit of the trade (1.5%) is reached, the capital rises to 101%.
4th trade lost, capital = 88.9%
// do not set to 100%
newCapital 88.9%
5th trade calculate order size for the 5th trade so that when the TakeProfit of the trade (1.5%) is reached, the capital rises to 101%.
5th trade won, but capital only 99.1%
// do not set to 100%
newCapital 99.1%
6th trade calculate order size for the 6th trade so that when the TakeProfit of the trade (1.5%) is reached, the capital rises to 101%.
6th trade won, capital 100.4%
set capital 100.4% to newCapital = 100%
newCapital = 100%
7th Trade Ordersize = 1
7th trade lost, capital = 99.5%
newCapital 99.5%
8th trade calculate order size for the 8th trade so that when the TakeProfit of the trade (1.5%) is reached, the capital rises to 101%.
8th trade won, TakeProfit is reached, capital now 101%
set capital 101% to newCapital = 100%
newCapital = 100%
9th Trade Ordersize = 1
….