Code for partial close with percentage

Viewing 2 posts - 61 through 62 (of 62 total)
  • Author
    Posts
  • #168205 quote
    nonetheless
    Participant
    Master

    I’m using the following partial close with a EUR/USD mini strategy:

    ONCE partialclose = 1
    IF partialclose THEN
    ONCE PerCent     = 0.9              //%  positions to close
    ONCE PerCent2     = 0.01              //%  positions to close
    ONCE MinLotSize  = 1              //1  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 LongOnMarket and close >= (PositionPrice + 4*pipsize)  AND Flag THEN
    SELL CloseQuantity Contracts AT Market
    Flag = 0
    endif
    
    IF ShortOnMarket and close <= (PositionPrice - 8*pipsize)  AND Flag2 THEN
    exitshort CloseQuantity2 Contracts AT Market
    Flag2 = 0
    endif
    endif

    This seems to work and the result is better than without partial close, but I’m getting confused between % and pips, especially as the optimization is so different for long and short (0.9 vs 0.01) ???

    The profit target is 0.9% long and 0.5% short. If 0.9% is ~110 pips, how does 4*pipsize relate to that?

    I tried using

    IF LongOnMarket and close >= (PositionPrice * (1 + PerCentGain))

    but it definitely works better with pipsize.

    #168221 quote
    nonetheless
    Participant
    Master

    To put some detail on this, I find it hard to make sense of the partial closes in the attached order list.

    On 19 Apr it buys 10 @ 1.19606 and sells 90% after a gain of .00067

    On 29 Mar it buys 10 @ 1.17864 and sells 90% after a gain of .00109, which is a huge difference.

    Is this just a matter of slippage? in which case, what should the partial close amount be, in pips?

    Most grateful for any enlightenment…

    eurusd.jpg eurusd.jpg
Viewing 2 posts - 61 through 62 (of 62 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Code for partial close with percentage


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Fran55 @fran55 Participant
Summary

This topic contains 61 replies,
has 7 voices, and was last updated by nonetheless
5 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/11/2020
Status: Active
Attachments: 11 files
Logo Logo
Loading...