Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

SetStopLoss on OnPositionUpdate

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

    SetStopLoss on OnPositionUpdate

    Hello,

    I am running a strategy where I set a stoploss at the moment of entry. This all works fine.

    Then at some point I take a partial profit (lets say 50%). I notice that the stoploss still holds the original quantity. So I need to adjust it to the remaining quantity.

    I put the SetStopLoss(CalculationMode.Price, dblEntry) code into the OnPositionUpdate method, but this doesnt seems to work. The order is not submitted.

    How can I best call a SetStopLoss method so that the remaining amount of shares left in the position is adjusted?

    Thanks.

    #2
    I think the problem is two fold:

    1- the stoploss is always bound to the original position quantity. You cannot adjust this
    2- if the stoploss price remains the same, the order will not get passed on (despite the wish for #1)
    Last edited by siroki; 10-13-2020, 12:57 AM.

    Comment


      #3
      Hello siroki,

      Thank you for your post.

      We have been able to reproduce this and have opened an internal ticket for it. We will follow up as more information becomes available.

      Let us know if we may assist further.
      Brandon H.NinjaTrader Customer Service

      Comment


        #4
        Hello siroki,

        Thank you for your patience.

        After further investigation, we have determined that this behavior is expected. To scale out of positions when using the managed approach, you should break entry calls into two and uniquely name both. For example, rather than EnterShort(2, “entrySignal”), you should use EnterShort(1,”EntrySig1”) and EnterShort(1,”EntrySig2”).

        Please see the SampleScaleOut example in the forum post linked below which demonstrates this approach being used.

        SampleScaleOut - https://ninjatrader.com/support/foru...osition?t=3751

        Please note that mixing Managed Exit and Set methods could create in-flight executions and could leave an open position. If you are using the Strategy Builder, do not use Stops and Targets when using Exit methods. Use Exit methods ONLY if you use them at all. If you are working with an unlocked strategy, you should use Unmanaged Approach and OCO tied exits.

        This type of occurrence involving a manual exit and in-flight executions with the target and stop can be best avoided by taking the following steps:
        1. Use Advanced Order Handling to manage Orders with Order Objects
        2. Use Exit methods for your Profit Target and Stop Loss instead of Set methods so you can manage an Order object for those orders
        3. When you want to submit your manual exit, send a CancelOrder() to cancel your profit target and stop loss Order objects.
        4. Check for OrderState.Canceled for the profit target and stop-loss orders in OnOrderUpdate().
        5. When you see that your protective orders are canceled, then submit your ExitLong()/ExitShort() market orders to exit your position
        Following the order of operations above will assure that you will not encounter an inflight execution with the target and stop filling while the manual exit fills, and the strategy will not attempt to update orders that have been already updated or canceled by the exchange.

        For further direction on using Advanced Order Handling concepts, I have included links to the Advanced Order Handling section of the help guide and our SampleOnOrderUpdate sample strategy. These resources are publicly available.

        Advanced Order Handling — https://ninjatrader.com/support/help...er_methods.htm

        SampleOnOrderUpdate — https://ninjatrader.com/support/help...and_onexec.htm

        SampleCancelOrder — https://ninjatrader.com/support/help...lOrder_NT8.zip

        Additionally, I have submitted a feature request to the Development Team. I will follow up with an internal tracking number for your reference as soon as it is created.

        If you have any additional questions, please don't hesitate to ask.

        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by FrancisMorro, Today, 03:24 AM
        0 responses
        1 view
        0 likes
        Last Post FrancisMorro  
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,769 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        30 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        943 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        10 views
        0 likes
        Last Post Max238
        by Max238
         
        Working...
        X