Partial closure of positions when price is retracing – A complete function

Now that multi-timeframe support is available for ProOrder, there are many new possibilities for us, including position management in a more refined and faster way than before.

Indeed, it is now possible to trade a strategy that makes trading decisions in a timeframe different from the one we will use to manage its positions.

In this article, I’m going to expose a rather simple function of partial closure of position when the price retraces to your disadvantage.

To close or not to close? That is the question!

Entering position is easy! But how to get out? It is often much more difficult to manage a position exit than to find the best way to enter it.

Should we close on a contrary signal? On a support or a resistance? Or through a thousand other arithmetic tests based on empirical statistics? Hard to say. In fact there would be only one good way, it is based on the behavior of the price, it is the purpose of the function below.

Partially close your position when the price is continuously retracing

The idea of the function is simple:

If the price was in profit of X points, then one starts the function of partial closure. At this point, if the price retrace Y points from the highest price (for a long order), then we close Z percent of the remaining position. The highest price reached is then reset to the current price. And so on until exhaustion of the position (its total closure).

That’s the function code, which incorporates a simple SuperTrend indicator-based strategy on a 15-minutes timeframe:

The parameters are as follows:

  • size = 10

Size of the initial position opened by the strategy.

  • mincontracts = 1

Minimum contract size to close (corresponds to the minimum size possible for the instrument), so to set according to the instrument on which you will perform this function.

  • trigger = 20

From how many points of profit the function will start

  • pointback = 5

Step to close a position, in points, since the highest price (BUY) or lowest (SELLSHORT) ever reached

  • closepercent = 20

Closure size at each level, in this example, 20% of “size” = 10*0.2 = 2 contracts

Buy position – partial closure:

Extend the function with many other ideas!

Many ideas could be added to this way of managing closures, for example:

  • allow closures only if the price is above / below a moving average or any other indicator,
  • no longer allow partial closure if the order is already at breakeven,
  • change the closing size at each step,
  • achieve a dynamic closure stage based on other analyzes,
  • etc.


Share this

  1. gone_mexico • 116 days ago #

    I’m a little confused on whether ProOrder supports partial closures or not. The article above suggests that this is now supported. However, every other post I’ve seen suggests it’s not supported. And indeed when I click ‘Prepare for automatic trading’, I get told explicitly that partial closures are not supported. Can you please confirm whether the code above is in fact supported by ProOrder (as suggested) or whether in fact this is only supported in back testing mode.

  2. Diego Franchino • 107 days ago #

    I’ve just tried the code with ProOrder, but partial closures are still not allowed!

    • Nicolas • 107 days ago #

      Still not released officially for live account, but you can ask your broker to activate it for your personal account now.

  3. Diego Franchino • 104 days ago #

    I’ve asked IG to activate the multiframe feature yet, I’ll try also for partial closures. Thank you!

  4. gone_mexico • 100 days ago #

    I have multi time frame enabled from IG on my account. But this still doesn’t work…

    There’s no restriction to partial closures in back testing mode (doesn’t require a new timeframe). However, I have put my partial closures in another timeframe with a view to uploading to ProOrder. But as soon as I click on the ‘Automatic Trading’ tab to prepare my code for uploading to ProOrder, I get the usual message about ‘Trading systems with orders that partially close cannot be sent to ProOrder’.

    I therefore don’t see how to make this work with ProOrder. (even when IG have enabled the timeframe support).

    Is there something else that I’m missing?

  5. gone_mexico • 100 days ago #

    IG confirmed that partial closures is still not supported on ProOrder. (not even available in beta).

  6. Diego Franchino • 92 days ago #

    ProRealTime confirmed that partial closures is still not supported on ProOrder, just on manual mode for now.

    • Nicolas • 92 days ago #

      Yes, amongst other things, it will be activated in October.

  7. Jeje • 26 days ago #

    Hello Nicolas,
    I have phoned to IG yesterday. They confirm that partial closures are not yet allowed by ProOrder. Perhaps in the next version… but when ? IG doesn’t know when.
    A great thank you Nicolas for your code.

    • Nicolas • 26 days ago #

      If IG doesn’t know, I can’t help 🙂

Register or