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?”
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.
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
I realized that the above snippet closes ALL the positions, you might prefer this line 9:
EXITSHORT 1 Contract at Market
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