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
//--------------LONG:
if (LongSetups AND LFiveDayCond55 AND NOT LongNoEntry AND NOT Events AND NOT Sun AND NOT Fri AND NOT LongOnMarket) then
ISL = 10000*(close-lowest[2](low) + LBuffer)
TradeRisk = pipvalue*ISL
ContractSize = 100/TradeRisk
BUY ContractSize SHARES AT market
// Stops and targets
SET STOP LOSS (close-lowest[2](low) + LBuffer)
SET TARGET PROFIT (close-lowest[2](low) + LBuffer)*2
ENDIF
//--------------SHORT:
if (ShortSetups AND SFiveDayCond55 AND NOT ShortNoEntry AND NOT Events AND NOT Sun AND NOT ShortOnMarket) then
ISL = 10000*(highest[2](high)-close + SBuffer)
TradeRisk = pipvalue*ISL
ContractSize = 100/TradeRisk
SELLSHORT ContractSize SHARES AT market
// Stops and targets
SET STOP LOSS (highest[2](high)-close + SBuffer)
SET TARGET PROFIT (highest[2](high)-close + SBuffer)*2
ENDIF
Hi,
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.
I 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.
Thank 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?
It is not possible to hedge position with ProOrder sorry. The only possibility is to divide your strategy into 2 separated ones, 1 for buy orders and 1 for sellshort orders.
I 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
This is the code being used with accumulating order set to false
Timeframe (daily)
REM Money Management
Capital = 30000
Risk = 0.01
REM Calculate contracts
equity = Capital //+ StrategyProfit
maxrisk = round(equity*Risk)
PositionSize1 = (abs(((maxrisk/SL)/PointValue)*pipsize))
IF PositionSize1>10 then
PositionSize=Round(abs(((maxrisk/SL)/PointValue)*pipsize))
Else
Positionsize=Positionsize1
Endif