replacing TP with partial close

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #189457 quote
    nonetheless
    Participant
    Master

    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:

    1. Run the TARGET %PROFIT as usual, let’s say it returns a value of 2.5
    2. Disable TP
    3. 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 🤔🤔🤔

    #189459 quote
    PeterSt
    Participant
    Master

    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.

    #189472 quote
    Nicolas
    Keymaster
    Master

    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.

    nonetheless thanked this post
    #189479 quote
    nonetheless
    Participant
    Master

    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  ???

    #189503 quote
    nonetheless
    Participant
    Master

    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…

    Midlanddave thanked this post
    #194648 quote
    livefully56
    Participant
    New

    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

    #194657 quote
    PeterSt
    Participant
    Master

    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.

    #194694 quote
    robertogozzi
    Moderator
    Master

    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
    livefully56, nonetheless and ZeroCafeine thanked this post
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

replacing TP with partial close


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 7 replies,
has 5 voices, and was last updated by robertogozzi
3 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/06/2022
Status: Active
Attachments: No files
Logo Logo
Loading...