An Adjustment to reduce the position can create multiple exit orders, as the potentially muliple units are exited.
However an Adjustment to increase the position size will always only create on order. You can then modify that order as desired.
In this case I set the stop price for the adjustment order to the same value as the first unit. This assumes the first unit has a stop associated with the original entry. You can also compute any value for this unit stop, or verify that the first unit still has a stop, etc.
Example:
|
' https://www.tradingblox.com/forum/viewtopic.php?f=58&t=11988
' Look for scale up orders. If the target number of lots
' is greater than the number of lots you currently have
' on by a factor of "scale percentage", resize the
' position by scaling it up or increasing the number of
' lots to the targetLotSize.
' When an Exit Order for the position is not active,...
If instrument.position <> OUT THEN
' Use the Parameter "scalePercentage" to determine the current Lot Size in the Position
If targetLotSize / (instrument.currentPositionQuantity / instrument.roundLot) > 1 + scalePercentage THEN
' and then create the order adjustment value for the broker function
broker.AdjustPositionOnClose(targetLotSize / (instrument.currentPositionQuantity / instrument.roundLot))
' When an Adjust Position Order become active,...
If system.OrderExists() THEN
' Update the Current UnitExitStop Price
order.SetStopPrice( instrument.unitExitStop[1] )
' Update the Order Log Action Information
order.SetRuleLabel( "Vol Scale Up, " )
' Update the Order Report Adjust Information
order.SetOrderReportMessage( "Vol Scale Up" )
ENDIF ' system.OrderExists()
ENDIF ' targetLotSize > 1 + scalePercentage
ENDIF ' i.position <> OUT
|
Edit Time: 10/20/2020 3:57:02 PM
|
|
Topic ID#: 671
|