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

Simulated Stop Limit order error

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

    Simulated Stop Limit order error

    I'm having an issue with the execution of a simulated stop limit order from my indicator. For example, if I submit a sell stop limit order from the DOM with a negative offset of -10, if the stop price is hit, a limit order is placed 10 ticks above. When I do this from my indicator and the stop price is hit I get an error stating: "Limit price can't bre greater than stop price....".

    I have verified that IsSimulatedStopEnabled and IsSimulatedStopConfigured is set on the order. The order properties look identical if I compare it to an order submitted through the DOM.

    Example:

    Submitted through DOM:
    OnOrderUpdate=orderId='0fdfde77c9284836a63a8701cc3 882f8' account='Sim101' name='' orderState=TriggerPending instrument='RTY 09-19' orderAction=Sell limitPrice=1564 stopPrice=1563 quantity=1 orderType='Stop Limit' filled=0 averageFillPrice=0 time='2019-08-05 21:30:56' statementDate='2019-08-05' error=NoError comment='' nr=-1

    Submitted through indicator:
    OnOrderUpdate=orderId='150f103a31c2458891207cae88b 02e01' account='Sim101' name='' orderState=TriggerPending instrument='RTY 09-19' orderAction=Sell limitPrice=1564 stopPrice=1563 quantity=1 orderType='Stop Limit' filled=0 averageFillPrice=0 time='2019-08-05 21:31:46' statementDate='2019-08-05' error=NoError comment='' nr=-1

    What am I missing?

    #2
    Hello martyn73, thanks for your post.

    It's hard to say what's going on without the code. Could you post it here or send it to me at platformsupport at ninjatrader.com? If you decide to email it, please reference "Attn ChrisL 2234164" in the subject or body of your email.

    Thanks in advance.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      For the thread's reference this would involve using CustomOrder in a specific way. However, since we do not have documentation or support using CustomOrder, we will be tracking interest behind documenting in the feature request ticket ID SFT-3180.

      If any community members would like to share their interest as well, please let us know.
      JimNinjaTrader Customer Service

      Comment


        #4
        NinjaTrader_Jim I am interested in this topic as well, since I am trying to programmatically create a stop limit buy order where the limit price is below the stop price.

        Comment


          #5
          Thanks for your reply Zombie, I have added your vote.
          JimNinjaTrader Customer Service

          Comment


            #6
            did this ever get done? NT8 talks about simulated stop orders but programatically it appears you can't do that?

            Comment


              #7
              Hello Mindset,

              Simulated Stop Limit orders are not yet supported with NinjaScript. Simulated Stop Market orders are possible with NinjaScript strategies when setting the IsSimulatedStop parameter of SetStopLoss to true.

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

              I have tracked a vote on your behalf to support simulated Stop Limit orders with NinjaScript. You may check the Release Notes page of the Help Guide to see a list of new features that get implemented with each new release to see if the feature/enhancement has been implemented.

              Release Notes - https://ninjatrader.com/support/help...ease_notes.htm
              JimNinjaTrader Customer Service

              Comment


                #8
                I too would like to add my vote for the ability to use simulated stop limit orders within a NinjaScript. Has the issue been resolved?

                Comment


                  #9
                  Hello trader3000a,

                  Thanks for your note.

                  Your vote has been added.

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

                  Comment


                    #10
                    Hello trader-ap,

                    Thank you for your note.

                    I have added a vote for you to SFT-3180 as well. I would not have any supported code snippets that would give this functionality, unfortunately.

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

                    Comment


                      #11
                      I have implemented stop limit orders with price improvement (i.e. Limit Price < Stop Price for a Buy or Limit Price > Stop Price for a Sell ) through a NinjaScript Indicator.

                      Interactive Brokers
                      Submit these types of orders using Account.CreateOrder() (Add On) with the desired Limit Price and Stop Price and the broker will hold the order on their platform until the Stop Price is triggered before submitting the Limit Price part of the order to the exchange. Leave the customOrder parameter to Account.CreateOrder() as null. Remember to review the "Trigger Method" settings on the TWS side as per this documentation.

                      I have tested this for Equities and it works as I expected.

                      Sim101 Account
                      For the Sim101 account you will need to pass a CustomOrder type object to the Account.CreateOrder() call with the member IsSimulatedStopEnabled = true as per the example. Also remember to create a new CustomOrder for every order you submit that requires simulated stop limit with price improvement.

                      Code:
                      // Create a new CustomOrder type object for [B]every[/B] order that requires simulated stop with limit price improvement
                      CustomOrder myCustomOrder = new CustomOrder();
                      
                      // Set IsSimulatedStopEnabled bool flag for myCustomOrder to true so that NT8 knows to process as simulated stop order
                      myCustomOrder.IsSimulatedStopEnabled = true;
                      
                      // Submit the order where you define your own quantity, limitPrice, stopPrice for this example
                      stopLimitOrder = myAccount.CreateOrder(myInstrument, OrderAction.Sell, OrderType.StopLimit, OrderEntry.Automated, TimeInForce.Day, quantity, limitPrice, stopPrice, "myOCO", "stopLimitOrder", Core.Globals.MaxDate, [B]myCustomOrder[/B]);
                      Unfortunately this only partially works for the Sim101 Account. The order is submitted and goes through the following orderStates:

                      - orderState=TriggerPending as soon as order is submitted
                      -.orderState=Submitted when the Stop Price is triggered
                      - orderState=Rejected immediately after the Submitted state

                      This is very annoying and has something to do with the order submission for Sim101 account.

                      As a workaround for now, I have an OnOrderUpdate event handler for Sim101 rejected orders which submits the limit order.

                      Other Brokers
                      I don't have access to any other brokers to test this against. So if this works with your broker then leave a comment so others will know.
                      Last edited by trader-ap; 08-28-2022, 01:12 PM.

                      Comment


                        #12
                        Finally got this to work without requiring reject order workaround for Sim101. So the coding if you want the broker to execute the simulated stop limit order still holds true. But the Stop Limit order for Sim101 needs to be done as Limit order (counter intuitive) with both the desired Stop and Limit prices supplied. So this is how I have coded a Buy Stop Limit order that works on the broker platform and Sim101 for testing.

                        Code:
                        // Let NT8 do Simulated Stop Limit order for Sim101 Account
                        if (myAccount.Name == "Sim101")
                        {[INDENT]CustomOrder myCustomOrder = new CustomOrder();
                        myCustomOrder.IsSimulatedStopEnabled = true;
                        
                        myEntryOrder = myAccount.CreateOrder(Instrument, OrderAction.Buy, OrderType.Limit, OrderEntry.Manual, TimeInForce.Gtc, quantity, limitPrice, stopPrice, "", "Entry", DateTime.MaxValue, myCustomOrder);[/INDENT]
                         
                         }
                        
                        // Let Broker do Simulated Stop Limit order
                        else
                        {[INDENT]myEntryOrder = myAccount.CreateOrder(Instrument, OrderAction.Buy, OrderType.StopLimit, OrderEntry.Manual, TimeInForce.Gtc, quantity, limitPrice, stopPrice, "", "Entry", DateTime.MaxValue, null);[/INDENT]
                         
                         }
                        I would say that SFT-3180 is now not needed for simulated stop limit orders as this code fragment above shows that the functionality already exists. However it would be beneficial to the developer community if SFT-3180 could be used to document all the options when using CustomOrder as a parameter to CreateOder()
                        Last edited by trader-ap; 08-28-2022, 01:17 PM.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by RookieTrader, Today, 09:37 AM
                        3 responses
                        15 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by kulwinder73, Today, 10:31 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post kulwinder73  
                        Started by terofs, Yesterday, 04:18 PM
                        1 response
                        24 views
                        0 likes
                        Last Post terofs
                        by terofs
                         
                        Started by CommonWhale, Today, 09:55 AM
                        1 response
                        4 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Started by Gerik, Today, 09:40 AM
                        2 responses
                        7 views
                        0 likes
                        Last Post Gerik
                        by Gerik
                         
                        Working...
                        X