Compounding position size with profits
Forums › ProRealTime English forum › ProOrder support › Compounding position size with profits
- This topic has 5 replies, 3 voices, and was last updated 3 years ago by
robertogozzi.
-
-
01/05/2020 at 11:33 AM #115914
Hi There,
Thank you in advance for any help you provide.
What I am trying to achieve is scaling the position size based upon the increase or decrease of capital as the automated trading system runs.
I trade CFD’s with IG Markets and because they are leveraged I have to use Margin.The number of contracts to purchase on any trade is calculated based upon how much margin said contracts will consume as a percentage of my capital, defined as risk.
As the system trades and profits (or losses), I would like to readjust the number of contracts based upon the increase in capital, as the price will be changing.For example, $500 with 50% risk may allow me to purchase 250 contracts, and by making a trade that generates a profit where my total capital increases to $600, I would like it to calculate how many contracts I can purchase with this increase in capital.
Your overall margin requirement is calculated as follows:
Without a stop
Margin = Size x price x margin factor
With a non-guaranteed stop1
We calculate your margin with a non-guaranteed stop, compare it to the margin required without a stop, and charge the lower of the two figures as margin.
Margin = (size x price x slippage factor x margin factor) + (size x stop distance)Just some FYI’s:
Margin Factor, Slippage Factor, Min Size are all set manually based upon the instrument at the broker.
SetLoss, Risk are what I set.ETF EMA 10 x 20 Automated12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedDEFPARAM Preloadbars = 2000REM Money ManagementCapital = (500 + POSITIONPERF(1))MarginFactor = 0.25SlippageFactor = 1.0MinSize = 1SetLoss = 50Risk = 0.5M1 = (MinSize * High[1] * SlippageFactor * MarginFactor)M2 = ((MinSize * High[1] * SlippageFactor * MarginFactor) + (MinSize * SetLoss))IF M1 <= M2 thenPositionSize = (ROUND((Capital/M1)*Risk))ELSEPositionSize = ((ROUND((Capital/M2))*Risk))ENDIF// Conditions to enter long positionsindicator1 = Average[10](low)indicator2 = ExponentialAverage[20](close)c1 = (indicator1 CROSSES OVER indicator2)indicator3 = Average[10](low)indicator4 = ExponentialAverage[50](close)c2 = (indicator3 >= indicator4)c4 = (indicator2 CROSSES OVER indicator4)c5 = (close >= ExponentialAverage[10](close))c6 = (close >= ExponentialAverage[50](close))c8 = TRADEPRICE(1)IF (c1 AND c2) OR (C4) OR (C5 AND C6 AND C8) THENBUY POSITIONSIZE CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator5 = Average[10](low)indicator6 = ExponentialAverage[50](close)c3 = (indicator5 CROSSES UNDER indicator6)indicator7 = low[1]-((AverageTrueRange[14]*2))c7 = (close <= indicator7)c9 = (close <= ExponentialAverage[50])c10 = (close <= (low[2]-(2*AverageTrueRange[14])))IF c3 OR c7 OR C9 OR C10 THENSELL AT MARKETENDIF// Stops and targetsSET STOP pLOSS SetLoss01/06/2020 at 9:54 PM #116088Check this out, could be what you want:
https://www.prorealcode.com/blog/learning/money-management-prorealtime-code/
Or run a search for Money Management, you’ll find some examples that you should be able to adapt.
01/06/2020 at 10:17 PM #11609204/15/2022 at 1:33 PM #191795Am working on similar, and have added the position size script.
How is yours working?
04/15/2022 at 2:54 PM #191797bonjour,J’ai survolé votre code , et vous indiquez dans votre condition d’achat ligne 31 la condition c8.C8 est défini ligne 29 comme TRADEPRICE(1) c’est à dire le prix de la dernière transaction est non comme une condition. N’auriez vous pas oublié une instruction…hello, I hovered over your code, and you indicate in your condition of purchase line 31 the condition c8. C8 is defined line 29 as TRADEPRICE ( 1 ) ie the price of the last transaction is not as a condition. Didn’t you forget an instruction…
04/15/2022 at 3:59 PM #191801Only post in the language of the forumthat you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.
Thanks 🙂
-
AuthorPosts
Find exclusive trading pro-tools on