Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order amendment while backtesting strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Order amendment while backtesting strategy

    Hi,
    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,

    #2
    Hello Joaquim Cipriano,

    Welcome to the forums!

    SetProfitTarget() and SetStopLoss() will "prep" NinjaTrader so when you enter using one of the Enter methods of the Managed Approach, OCO'd profit target and Stop Loss will be placed upon the execution of the Entry order.

    Since the Profit Target and Stop Loss are "prepped" if you use these methods in OnPositionUpdate() OnOrderUpdate() or OnExecutionUpdate(), you would not see the current target and stop, but where the previous target and stop were at. It would be advised to set the profit target and stop loss to a the desired level before the entry order methods are fired.

    Please refer to the help guide documentation for SetProfitTarget() and SetStopLoss() for syntax and notes on their intended use.

    SetProfitTarget() - https://ninjatrader.com/support/help...ofittarget.htm

    SetStopLoss() - https://ninjatrader.com/support/help...etstoploss.htm

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks, Jim. Your explanation was enough to solve my problem. I was setting the stop loss and take profit after sending the order because it made sense to me that we should create the entry order first. But it is ok for me, as long as I know how Ninja Trader framework behaves and you helped me to understand that. Kind Regards,

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by maybeimnotrader, Today, 05:46 PM
      0 responses
      6 views
      0 likes
      Last Post maybeimnotrader  
      Started by quantismo, Today, 05:13 PM
      0 responses
      6 views
      0 likes
      Last Post quantismo  
      Started by AttiM, 02-14-2024, 05:20 PM
      8 responses
      167 views
      0 likes
      Last Post jeronymite  
      Started by cre8able, Today, 04:22 PM
      0 responses
      8 views
      0 likes
      Last Post cre8able  
      Started by RichStudent, Today, 04:21 PM
      0 responses
      5 views
      0 likes
      Last Post RichStudent  
      Working...
      X