Code for partial closures by percentage.
- This topic has 5 replies, 3 voices, and was last updated 3 years ago by .
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
Similar topics:
Forums › ProRealTime English forum › ProOrder support › Code for partial closures by percentage.
Good.
I needed code for multiple partial closures within one operation.
If the operation is positive and earns equal to or more than 0.25%, close 1/5 of the position.
If the operation is positive and earns equal to or more than 0.5%, close 1/5 of the position.
It’s an example, thanks.
There you go (not tested):
1 2 3 4 5 6 7 8 9 10 11 12 |
If not OnMarket then Tally = 0 Endif ProfitPC = PositionPrice * PositionPerf * 100 If ProfitPC >= 0.25 and Tally = 0 then Close PositionSize/5 contracts at Market Tally = Tally + 1 Endif If ProfitPC >= 0.50 and Tally = 1 then Close PositionSize/5 contracts at Market Tally = Tally + 1 Endif |
Here’s another version (also coded by Roberto👍)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
ONCE partialclose = 1 ONCE PerCent = pc //0.2 = 20% positions to close ONCE PerCent2 = pc2 //0.2 = 20% positions to close ONCE PerCentGain = pcg //.0025 = 0.25% gain ONCE PerCentGain2 = pcg2 //.005 = 0.5% gain ONCE MinLotSize = 0.5 //0.5 lots minimum ExitQuantity = abs(CountOfPosition) * PerCent LeftQty = max(MinLotSize,abs(CountOfPosition) - ExitQuantity) CloseQuantity = abs(CountOfPosition) - LeftQty ExitQuantity2 = abs(CountOfPosition) * PerCent2 LeftQty2 = max(MinLotSize,abs(CountOfPosition) - ExitQuantity2) CloseQuantity2 = abs(CountOfPosition) - LeftQty2 IF Not OnMarket THEN Flag = 1 Flag2 = 1 ENDIF IF partialclose AND LongOnMarket and close >= (PositionPrice * (1 + PerCentGain)) AND Flag THEN SELL CloseQuantity Contracts AT Market Flag = 0 endif IF partialclose AND shortOnMarket and close <= (PositionPrice * (1 - PerCentGain2)) AND Flag2 THEN exitshort CloseQuantity2 Contracts AT Market Flag2 = 0 endif |
Sorry, there are two mistakes:
1 |
ProfitPC = PositionPerf * 100 |
Find exclusive trading pro-tools on