I am trying to code a partial reentry code that, in case that an open position goes near the SL, it should buy/sell a position equal to positionsize/2. I am using cumulateorders = true and Countofposition <=2, and I want the robot to perform the reentry only once. I am not sure what am I doing wrong but the robot does not perform the reentry correctly, could someone give me some light about that topic? I am attaching the code for the reentry:
Partial reentry code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ONCEpartialreentry=1
IFpartialreentryandCountofposition<=2THEN
ONCEPartialreentrypos=Positionsize/2//Position to reenter
IFNotOnMarketTHEN
Flagr=1
Flagr2=1
ENDIF
IFLongOnMarketandclose<=(PositionPrice-PositionPrice*0.022)ANDFlagrTHEN//0.22 corresponds to the point where I want to set the order, as long as my stoploss is 2,5% away from entry price
BUYPartialreentryposContractsATMarket
Set stop%loss0.3
Set target%profit2.2
Flagr=0
endif
IFShortOnMarketandclose>=(PositionPrice+PositionPrice*0.018)ANDFlagr2THEN// Same here, my stoploss is 2% away from entry price so I would like the robot to sell another position in case that the price is 0,2% away from the SL.
BUYPartialreentryposContractsATMarket
Set stop%loss0.2
Set target%profit1.8// The profit corresponds to the BE price of the first position
Thank you for your answer, one more question: In case it opens another position, if I use PositionPrice command which price will the robot take, the one corresponding to the first opened position or the second one?
Do not useQUOTEwhen unnecessary, as it makes posts more difficult to read and too long!
Thank you 🙂
PositionPrice (apart when there’s only one position open), is an average of all entry prices and SL + TP will refer to that price (see pic to see how it is calculated).