So I’m thinking of a way to use a 3 stage partial close instead of a single profit target. This is what I have in mind:
- Run the TARGET %PROFIT as usual, let’s say it returns a value of 2.5
- Disable TP
- From an initial position size of 10, use partial close to sell 3 contracts at 2%, 5 at 2.5% and 2 at 2.7 % (or something like that)
This is the code I had intended to use:
//partialclose
ONCE partialclose = 1
ONCE PerCent = pc //0.3 = 30% positions to close
ONCE PerCent2 = pc2 //0.5 = 50% positions to close
ONCE PerCent3 = pc3 //0.2 = 20% positions to close
ONCE PerCentGain = pcg //.02 = 2% increase
ONCE PerCentGain2 = pcg2 //.025 = 2.5% increase
ONCE PerCentGain3 = pcg3 //.027 = 2.7% increase
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
ExitQuantity3 = abs(CountOfPosition) * PerCent3
LeftQty3 = max(MinLotSize,abs(CountOfPosition) - ExitQuantity3)
CloseQuantity3 = abs(CountOfPosition) - LeftQty3
IF Not OnMarket THEN
Flag = 1
Flag2 = 1
Flag3 = 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 LongOnMarket and close >= (PositionPrice * (1 + PerCentGain2)) AND Flag2 THEN
sell CloseQuantity2 Contracts AT Market
Flag2 = 0
endif
IF partialclose AND LongOnMarket and close >= (PositionPrice * (1 + PerCentGain3)) AND Flag3 THEN
sell CloseQuantity3 Contracts AT Market
Flag3 = 0
endif
This is a variation of a code I have used in the past but it doesn’t work in the way I want it to; optimization of the variables shows no change.
I realise there’s a problem using abs(CountOfPosition) as it’s not going to give me the original intended disposals of 3, 5, 2 as the CountOfPosition will change with each sale.
But presumably there is some bigger problem here as well that I don’t get? Or maybe a better method entirely?
Most grateful for any help 🤔🤔🤔
Can’t you describe what your issue is (apart from it not doing what you want it to) ?
I am not saying that I will have the solution, but I do know that I attempted similar which did not work out (the reason of why could help you).
The main culprit will be the feature set of PRT which does not support this really.
You are not saying it, but I would agree with that this comes down to “an approach”; Some stupid theoretical thinking which could help. … I really attempted many of those and only after implementation (a lot of work) I could reason why the idea s*cked in the first place.
Try to graph the condition:
GRAPH partialclose AND LongOnMarket and close >= (PositionPrice * (1 + PerCentGain)) AND Flag
to know when it happens and if the partial closure is working correctly on the same candle.
Thanks Peter, I dont really have an issue as such, just an intuition that there ‘might’ be an advantage to treating profit target as a general area where it’s a good idea to start getting out … as opposed to a single price.
Maybe there’s no advantage at all, maybe it just averages out to the same result. But obviously most trades do not reach the target. Some will almost get there, then fall back all the way to the trail.
I’m hoping that this method might catch a bit more of the MFE
Then, maybe the inverse could be used in place of SL ?? gradually easing out of a position, instead of focussing your exit on one spot.
It’s just an idea I’d like to test, but the code is not cooperating and I don’t see why ???
mystery solved – aint nuthin wrong with the code, only my tired brain had a decimal in the wrong place (*groan*)
but just for the record, initial tests look as if it can actually yield a better result – worth exploring further…
This hybrid form of exit seems to yield better results
Can you help with code on how do I use the same concept to exit :
50% with 1:1 RRR
25% with 1:2 RRR
and the rest 25% wit 1:3 RRR
Thanks in advance
https://www.prorealcode.com/topic/help-please-to-code-a-one-shot-trading-system/
Notice that your 50, 25, 25 is the same as 50%, 50% of the remainder, plus the rest.
Try this one (I made a few tests on DAX, 1h TF:
/*
50% with 1:1 RRR
25% with 1:2 RRR
and the rest 25% wit 1:3 RRR
*/
ONCE SL = 200 * PipSize
ONCE LotSize = 4
ONCE TP1size = LotSize / 2
ONCE TP2size = TP1size / 2
Sma200 = average[200,0](close)
MyLongConditions = close CROSSES OVER Sma200 AND Not OnMarket
IF MyLongConditions THEN
BUY LotSize Contracts at Market
TP1 = close + SL //1:1 RRR
TP2 = close + SL*2 //1:2 RRR
TP3 = close + SL*3 //1:3 RRR
SET STOP LOSS SL
Flag = 0
ENDIF
IF LongOnMarket THEN
IF close >= TP1 AND Flag = 0 THEN
SELL TP1size Contracts at Market
Flag = 1
ENDIF
IF close >= TP2 AND Flag = 1 THEN
SELL TP2size Contracts at Market
Flag = 2
ENDIF
IF close >= TP3 AND Flag = 2 THEN
SELL TP2size Contracts at Market
ENDIF
ENDIF
graphonprice TP1 coloured(255,0,0,255) //Red
graphonprice TP2 coloured(0,128,0,155) //Green
graphonprice TP3 coloured(0,0,255,255) //Blue