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

Unmanaged Simultaneous Stop Orders Sample

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

    Unmanaged Simultaneous Stop Orders Sample

    Hi,
    I have tried to do a simple daily breakout strategy where I place 2 stop orders above and below the previous daily candle. I noticed while using the managed stop orders that each time a new candle is begins in the console the orders are placed, however when testing on 1h candles I noticed that only 1 of the orders will be activated even if the first one will be stopped out the second will not be triggered and be cancelled. I have read on the forums that the unmanaged orders is the best approach to achieve this, but im unable to find a good example or tutorial of how to get these working, do you have a sample file somewhere for me to learn how to do this and ensure it works on backtest before putting live?

    Thanks in advanced for your help.

    #2
    Hello mr_trade,

    Thank you for your post.

    You're correct, this would require switching to the unmanaged order approach to get access to manually setting the OCO ID.

    Here is a link to our help guide section on the Unmanaged approach:


    Here's a link to an example strategy you can look at and modify to your liking:


    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate,

      Thankyou for your reply I have had some success with the above samples, however how do I cancel the orders if the long or short stop orders are not filled within the bar? So lets say im using 1 hour bars, I place an order above and below and if they are not filled within the hour I want to cancel the orders, then at the start of next bar re-submit the orders?

      Thanks in advanced for your help.

      Comment


        #4
        Hello mr_trade,

        Thank you for your reply.

        Instead of cancelling and resubmitting, you could simply modify the order on the next bar. I added the following to the UnmanagedOCOBracketExample script and set it to calculate OnBarUpdate:

        protected override void OnBarUpdate()
        {

        // modify unfilled orders to new prices if not filled on previous bar

        if (shortStopEntry != null && !Order.IsTerminalState(shortStopEntry.OrderState))
        ChangeOrder(shortStopEntry, shortStopEntry.Quantity, 0, (Low[0] - 10 * TickSize));
        if (longStopEntry != null && !Order.IsTerminalState(longStopEntry.OrderState))
        ChangeOrder(longStopEntry, longStopEntry.Quantity, 0, (High[0] + 20 * TickSize));

        }

        Here's a link to our help guide on ChangeOrder():



        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thank you Kate, this makes a lot more sense than what I was proposing thankyou will give this a go now.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by inanazsocial, Today, 01:15 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by rocketman7, Today, 02:12 AM
          0 responses
          10 views
          0 likes
          Last Post rocketman7  
          Started by dustydbayer, Today, 01:59 AM
          0 responses
          1 view
          0 likes
          Last Post dustydbayer  
          Started by trilliantrader, 04-18-2024, 08:16 AM
          5 responses
          23 views
          0 likes
          Last Post trilliantrader  
          Started by Davidtowleii, Today, 12:15 AM
          0 responses
          3 views
          0 likes
          Last Post Davidtowleii  
          Working...
          X