Is it possible to scale in and scale out of trades

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #252227 quote
    Mellstock
    Participant
    New

    I want to write a program where I build up a number of short positions say 5. (Sellshort)

    When CountOfPosition = say 5 start buying them back.
    Boolean variable BuybackMode = False during build up of short position
    BuybackMode = True once CountOfPosition = 5 and stays True whilst positions bought back.

    The issue I am having is that I can build up the sellshort positions according to criteria 1 through 5 ok.

    The issue I am having although I specify Buy 1 Contract back at a time the first time the first buy criteria is met the whole
    position, all 5 contracts are bought back.

    So trades entered using Sellshort singlely 1 through 5
    Plan to exit them singlely using Buy.

    My question is of concept in the first instance.

    “Is it possible to scale in and scale out of trades in PRT?”

    #252231 quote
    PeterSt
    Participant
    Master

    Sure, but in your example you must ExitShort (or Sell when your position is Long).
    This works only with Market Orders. But beware, Backtesting allows it with Pending Orders as well – hence don’t use them accidentally.

    Iván González thanked this post
    #252240 quote
    robertogozzi
    Moderator
    Master

    Try this one (not tested):

    ONCE MaxPositions = 5
    IF Not OnMarket THEN
       BuyBack = 0
    ENDIF
    IF MyShortConditions AND abs(CountOfPosition) < MaxPositions AND Not BuyBack THEN
       SELLSHORT 1 Contract at Market
    ENDIF
    IF MyBuyBackConditions AND ShortOnMarket THEN
       EXITSHORT at Market
       BuyBack = 1
    ENDIF
    #252328 quote
    robertogozzi
    Moderator
    Master

    I realized that the above snippet closes ALL the positions, you might prefer this line 9:

    EXITSHORT 1 Contract at Market
    Mellstock thanked this post
    #252337 quote
    Mellstock
    Participant
    New

    Thank you.

    I have my code working now in Demo.

    I worked out, having been given the heads up about ExitShort, the correct syntax.

    Thanks again

    robertogozzi thanked this post
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Is it possible to scale in and scale out of trades


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mellstock @mellstock Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by Mellstock
4 months, 3 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/07/2025
Status: Active
Attachments: No files
Logo Logo
Loading...