Could you explain the behaviour of the SetProfitTarget/SetStopLoss Commands?
On method OnPositionUpdate(), I try to set the Stop Loss and Profit Target one Tick Size above and bellow the entry price depending on the fact that the position is Long or Short.
For instance, for a Long Position with Entry Price at 3,00$, we are setting the stop loss at 2,99$ and the take profit at 3,01$.
However, the platform is amending the orders to 3,03$ (stop loss) and 3,05$(take profit) and then the stop loss order is being executed at 3,02$, since the new stop loss order is at 3,03$.
Why this amendement of stop loss and take profit orders happens? Which is the rule?
Bellow you can see the logs of the execution related to the corresponding example.
05/01/2018 19:12:34 CurrentBar: 75829 Opening Long Position --> Close: 3,04 Previous Bar Close: 3,02 Entry Price: 3,02 Quantity: 331 Stop Loss: 3,01 Profit Target: 3,03
05/01/2018 19:12:34 CurrentBar: 75829 Order executed --> Quantity: 333 Filled: 333 Average Fill Price: 3 Action: Buy
05/01/2018 19:12:34 CurrentBar: 75829 Position --> Direction: Long Average Price: 3 Quantity: 333
05/01/2018 19:12:34 CurrentBar: 75829 Setting Stop Loss: 2,99
05/01/2018 19:12:34 Strategy 'TickPreviewStrategyV2/-1': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Price Value=2,99 IsSimulatedStop=False IsMarketIfTouched=False
05/01/2018 19:12:34 Strategy 'TickPreviewStrategyV2/-1': Amended stop order orderId='NT-25745-170' account='Backtest' name='Stop loss' orderState=Working instrument='DELT' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=3.03 quantity=333 tif=Gtc oco='NT-05610-170' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-01-05 19:12:34' gtd='2099-12-01' statementDate='2018-01-15'
05/01/2018 19:12:34 CurrentBar: 75829 Setting Profit Target: 3,01
05/01/2018 19:12:34 Strategy 'TickPreviewStrategyV2/-1': Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Price Value=3,01 IsSimulatedStop=False IsMarketIfTouched=False
05/01/2018 19:12:34 Strategy 'TickPreviewStrategyV2/-1': Amended target order orderId='NT-25746-170' account='Backtest' name='Profit target' orderState=Working instrument='DELT' orderAction=Sell orderType='Limit' limitPrice=3.05 stopPrice=0 quantity=333 tif=Gtc oco='NT-05610-170' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-01-05 19:12:34' gtd='2099-12-01' statementDate='2018-01-15'
05/01/2018 19:12:34 CurrentBar: 75830 Closing Long Position without stop loss nor take profit! Exit Price: 3
05/01/2018 19:12:34 CurrentBar: 75831 Closing Long Position without stop loss nor take profit! Exit Price: 3
05/01/2018 19:12:34 Strategy 'TickPreviewStrategyV2/-1: Cancelled pending exit order, since associated position is closed, orderId='NT-25745-170' account='Backtest' name='Stop loss' orderState=Working instrument='DELT' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=2.99 quantity=333 tif=Gtc oco='NT-05610-170' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-01-05 19:12:34' gtd='2099-12-01' statementDate='2018-01-15'
05/01/2018 19:12:34 CurrentBar: 75831 Order executed --> Quantity: 333 Filled: 333 Average Fill Price: 3,02 Action: Sell
05/01/2018 19:12:34 CurrentBar: 75831 Account: account='Backtest' accountItem=CashValue currency=UsDollar value=*****
05/01/2018 19:12:34 CurrentBar: 75831 Position --> Direction: Flat Average Price: 0 Quantity: 0
05/01/2018 19:12:34 Strategy 'TickPreviewStrategyV2/-1': Cancelled OCO paired order: BarsInProgress=0, orderId='NT-25745-170' account='Backtest' name='Stop loss' orderState=Cancelled instrument='DELT' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=2.99 quantity=333 tif=Gtc oco='NT-05610-170' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-01-05 19:12:34' gtd='2099-12-01' statementDate='2018-01-15'
Kind Regards,
Comment