Capital curve as an indicator?
Forums › ProRealTime English forum › ProOrder support › Capital curve as an indicator?
- This topic has 9 replies, 3 voices, and was last updated 11 months ago by JohnScher.
-
-
10/15/2023 at 3:41 PM #222475
Capital curve as an indicator?
I have an old problem that I am still struggling with.
I want to change my long conditions if after a trade my capital is smaller than the highest capital ever reached with this strategy.
(current capital of the strategy is smaller than the all-time high of the capital of the strategy).My starting capital was 10,000 euros.
My all-time high in capital was 14,700 euros with this strategy.
After a losing trade, the current capital is 14,100 euros. After another losing trade 13.800, after a third losing trade 13.500 and so on.HowI can use the all-time-high in capital as a condition in this way?
As long as my current capital is less than the all-time-high of my capital, then Longcondition 1
alternatively
if my current capital is greater than the all-time-high of my capital then Longcondition 2For the all-time-high you could also use the highest capital level of the last 100 trades, so that quite simplified, analogous to an indicator, the code would be (the code is not correct, it should serve to understand my question)
12345678910111213141516171819once capital = 10000equitity = capital + strategyprofitIF equitity < all-time-high (equitity) thencondition1Elsif equitity > all-time-high (equitity) thencondition2Endifin case the high of 100 TradesIF equitity < highest [100] (equitity) thencondition1Elsif equitity > highest [100] (equitity) thencondition2Endif10/15/2023 at 4:56 PM #222482This version is for the highest Equity in ALL trades:
1234567891011once capital = 10000once maxcapital = capitalequity = capital + strategyprofitmaxcapital = max(maxcapital,equity) //max CAPITAL in ALL tradesIF equity < maxcapital thencondition1 = xElsif equity > maxcapital thencondition2 = yEndifThis version is for the highest Equity in the last 100 (or less, if not yet 100) trades:
123456789101112131415161718192021222324once capital = 10000once maxcapital = capitalonce equity = capitalonce Trades = 100IF StrategyProfit <> StrategyProfit[1] THENTradeCount = lastset($myEquity) + 1equity = capital + strategyprofit$myEquity[TradeCount] = equityN = 1IF TradeCount >= Trades THENN = TradeCount - (Trades - 1)ENDIFmaxcapital = capitalFOR i = TradeCount downto Nmaxcapital = max(maxcapital,$myEquity[i])NEXTENDIFIF equity < maxcapital thencondition1 = xElsif equity > maxcapital thencondition2 = yEndif3 users thanked author for this post.
10/31/2023 at 5:10 PM #223092Hello Roberto.
Thank you for the coding, that really helps me, if I understood it correctly at all.
From the 2 offered codes above, I took the first simpler one right away and the Cross EMA 20 over EMA 50 as entry condition.
As a result, from my understanding, it looks like the following, but no trades are triggered.
Can you correct my errors?
123456789101112131415161718192021222324252627282930//---------------------------------------------------------// moneymanagement maxcapital// using the example Average Cross// created by JohnScher coded with the help of friends//---------------------------------------------------------defparam cumulateorders = falseonce capital = 10000once maxcapital = capitalequitity = capital + strategyprofitmaxcapital = max(maxcapital,equitity)If equitity < maxcapital thenordersize = 2Elsif equitity > maxcapital thenordersize = 1Endiftradebuy = average [20] (close) crosses over average [50] (close)If tradebuy thenbuy ordersize contracts at marketendifset stop %loss 2set target %profit 110/31/2023 at 7:19 PM #22309511/04/2023 at 10:06 AM #223196Yes, thanks, that works now.
The code as below now does what it should.1234567891011121314151617181920212223242526272829303132333435//---------------------------------------------------------// moneymanagement maxcapital// using the example Average Cross// created by JohnScher coded with the help of friends//---------------------------------------------------------defparam cumulateorders = falsedefparam flatbefore = 080000defparam flatafter = 210000once capital = 10000once maxcapital = capitalequitity = capital + strategyprofitmaxcapital = max(maxcapital,equitity)If equitity >= maxcapital thenordersize = 1Elsif equitity < maxcapital thenordersize = 2Endiftradebuy = average [20] (close) crosses over average [50] (close)If tradebuy thenbuy ordersize contracts at marketendifset stop %loss 1set target %profit 1graph maxcapital11/05/2023 at 5:57 PM #223221Hello 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 EuroThe 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.
https://www.prorealcode.com/topic/again-moneymanagement-calculate/
https://www.prorealcode.com/topic/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 getSo 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.1234567891011121314151617181920212223242526272829303132333435363738394041424344454647//---------------------------------------------------------// moneymanagement maxcapital// using the example Average Cross// created by JohnScher coded with the help of friends//---------------------------------------------------------// Basic settingsdefparam cumulateorders = falsedefparam flatbefore = 080000defparam flatafter = 210000 // timestop// moneymanagementonce capital = 10000 // set capital to 10,000 as an once-only basisonce 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 profitmaxcapital = 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 thenordersize = 1 // in the case that the available capital is greater than the highest capital ever reached, the position size is set to 1Elsif equitity < maxcapital thenordersize = lotsize // in the case that the available capital is lower than the highest capital ever reached, the position size is calculated as in line 20EndifIf ordersize < 1 thenordersize = 1 // for any reason the position size falls below 1, the position size is set to 1endif// tradingsystemtradebuy = average [20] (close) crosses over average [50] (close)If tradebuy thenbuy ordersize contracts at marketendifset stop %loss 10set target profit tpTrade//give-awaygraph maxcapital1 user thanked author for this post.
11/08/2023 at 11:31 AM #223357I think you should:
- make the calculations about money management and lot size ONLY when Not OnMarket, to prevent data from being changed while a trade is open
- calculate the Capital increase only when STRATEGYPROFIT > STRATEGYPROFIT[1], which means a profit was reached, but only if TIME < the time used with FLATAFTER, or it will not be the real TP that has been reached.
1 user thanked author for this post.
11/09/2023 at 10:18 PM #22346211/11/2023 at 1:48 PM #223534Hello Roberto.
Thankyou very much again! So many times you still helped me and you do it again and again and again… with heartpiece.
But here I would like to contradict you – it doesn’t seem correct to me. Or I have misunderstood you again, so please excuse my mistakes.To point 1
that I am in the market with several positions is excluded by cumulateorders = false
Inserting this condition in the following way does not change anything. (line24, line34)+
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748//---------------------------------------------------------// moneymanagement maxcapital// using the example Average Cross// created by JohnScher coded with the help of friends//---------------------------------------------------------// Basic settingsdefparam cumulateorders = falsedefparam flatbefore = 080000defparam flatafter = 210000 // timestop// moneymanagementonce capital = 10000 // set capital to 10,000 as an once-only basisonce 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 profitmaxcapital = 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 not onmarket thenIf equitity >= maxcapital thenordersize = 1 // in the case that the available capital is greater than the highest capital ever reached, the position size is set to 1Elsif equitity < maxcapital thenordersize = lotsize // in the case that the available capital is lower than the highest capital ever reached, the position size is calculated as in line 20EndifIf ordersize < 1 thenordersize = 1 // for any reason the position size falls below 1, the position size is set to 1endifEndif// tradingsystemtradebuy = average [20] (close) crosses over average [50] (close)If tradebuy thenbuy ordersize contracts at marketendifset stop %loss 10set target profit tpTrade//give-awaygraph maxcapitalTo point 2
I do not see that the condition “Strategyprofit > Strategyprofit[1]” is useful. The additional strategy profit can also consist of 1 euro and does not change the calculation basis. The basis of calculation is the highest capital ever achieved. I would like to increase this highest capital ever reached by 1% via the position adjustment*, provided that the take profit is reached before the flattener.The adjustment can consist of an increase after a losing trade or a decrease after a winning trade that does not reach the take profit of 2% in the trade.
Attached is another picture showing the Maxcapital graph.
You can see that after the first trade, a new highest ever capital (=maxcapital) was reached. This highest value is now the calculation basis for the next trade. As long as there is no new highest capital, the position size is adjusted to this highest capital ever reached.
Here in the picture a new highest capital cannot be seen and maxcapital is still a horizontal line, because the take profit in the trade of 2% has never been reached since then. See also the other screenshot.Dear readers, please note that this is not about the strategy (crossover 20 over 50) per se, but about money management.
If there are difficulties in solving this problem, I see that it has not yet been dealt with (conclusively) here on Prorealtime. In this respect, it could make a contribution to the entire community.11/12/2023 at 9:01 AM #223568 -
AuthorPosts
Find exclusive trading pro-tools on