Calculate Position Size based on fixed risk (ie. $100)
Forums › ProRealTime English forum › ProOrder support › Calculate Position Size based on fixed risk (ie. $100)
- This topic has 6 replies, 3 voices, and was last updated 3 years ago by s00071609.
-
-
09/20/2020 at 11:10 PM #144839
Hi,
In the attached code I tried to calculate the position size based on a fixed risk of $100 with a profit target of $200. But for some reason it sometimes does it correctly and sometimes it doubles the position size which then for a losing trade causes twice as the defined loss (-$200) and also gets twice the profit (+$400) in case of a winning trade. This happens for long and short trades. I tested it on AUDUSD.
I thought the code is correct (see line 105-132 and line 216-254) but there must be a mistake that I can’t see it.
The second problem is, that when there is a long position and then a new short position is triggered, the long position will be closed. How can I avoid that?
Thank you.
Sascha
09/21/2020 at 12:44 PM #144884Position Size Calculation1234567891011121314151617181920212223242526//--------------LONG:if (LongSetups AND LFiveDayCond55 AND NOT LongNoEntry AND NOT Events AND NOT Sun AND NOT Fri AND NOT LongOnMarket) thenISL = 10000*(close-lowest[2](low) + LBuffer)TradeRisk = pipvalue*ISLContractSize = 100/TradeRiskBUY ContractSize SHARES AT market// Stops and targetsSET STOP LOSS (close-lowest[2](low) + LBuffer)SET TARGET PROFIT (close-lowest[2](low) + LBuffer)*2ENDIF//--------------SHORT:if (ShortSetups AND SFiveDayCond55 AND NOT ShortNoEntry AND NOT Events AND NOT Sun AND NOT ShortOnMarket) thenISL = 10000*(highest[2](high)-close + SBuffer)TradeRisk = pipvalue*ISLContractSize = 100/TradeRiskSELLSHORT ContractSize SHARES AT market// Stops and targetsSET STOP LOSS (highest[2](high)-close + SBuffer)SET TARGET PROFIT (highest[2](high)-close + SBuffer)*2ENDIFHi,
This is the part of the code that should calculate the position size.
If anyone can find the mistake, I would be very grateful.
What it should do, is simply use the current close and the lowest low of the last two days as the initial stop loss (for a long trade) and use twice that risk as a profit target.
Thanks.
09/21/2020 at 12:55 PM #144886I don’t see any reason why it doubles the contract size. Are you sure you have set the cumulating orders to false?
In order to not order a contrarian order while you are already at market, just add “AND NOT ONMARKET” in your conditions lines 3 and 16.
1 user thanked author for this post.
09/21/2020 at 1:12 PM #144888Thank you Nicolas for your quick reply. You’re a genius. I indeed still had set the cumulating orders to True. It’s now not doubling anymore the position size.
Regarding a contrarian order: How can I allow a contrarian order to be placed without closing the existing order?
09/21/2020 at 2:00 PM #14489302/26/2021 at 5:25 AM #162650I have max risk set to $300, but this is giving me position size of 61 contract on NASDAQ. The order list shows 1 position with 2100$ loss. It has correct size in other orders. Why would it do this?
I have attached the image. The risk graph is flat meaning the risk is always $300, position size has spiked around the area. The largest spike in the image on 4th bar from where my cursor is 189 contracts size
02/26/2021 at 5:30 AM #162651This is the code being used with accumulating order set to false
1234567891011121314Timeframe (daily)REM Money ManagementCapital = 30000Risk = 0.01REM Calculate contractsequity = Capital //+ StrategyProfitmaxrisk = round(equity*Risk)PositionSize1 = (abs(((maxrisk/SL)/PointValue)*pipsize))IF PositionSize1>10 thenPositionSize=Round(abs(((maxrisk/SL)/PointValue)*pipsize))ElsePositionsize=Positionsize1Endif -
AuthorPosts
Find exclusive trading pro-tools on