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

Submit Simulated Stop Limit Order in NinjaScript

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

    Submit Simulated Stop Limit Order in NinjaScript

    From BasicEntry its possible to enter a Buy Stop Limit order where the Limit Price is below the Stop price. Once submitted it has a Status of Trigger Pending until the Stop price is hit and the the Limit order below is summited and working. Example in documentation is Stop of 1000 is hit and Limit order to buy at 995 is Submitted.

    When I attempt to do this with NinjaScript the Error that Limit Price can not be below Stop price pops up.

    How can this order be submitted using NinjaScript?

    #2
    Hello ctrent, thanks for writing in.

    The basic entry window attempts to be as user-friendly as possible by converting the order to a limit order through custom orders. This is part of the NinjaTrader core and is not available in NinjaScript, so any NinjaScript strategy will need to follow the rules that Chart Trader follows and only submit buy stop limit orders above the current market price. When an order is trigger pending, it is simply waiting for the order to become valid before its submitted, so your strategy must watch the market price before submitting the order and prevent the order from being submitted at an illegal price level.

    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi NinjaTrader_ChrisL
      I think what some of us would like to know though is how to code this SS order (negative limit order for example) in NinjaScript - could you give an example please?

      Comment


        #4
        Hi Mindset,

        I was able to get this working in NinjaScript This is a snippet of code where it does this in an Indicator that adds functionality to the ChartTrader panel. If used in a strategy some change may be necessary.

        This example submits a Buy StopLimit above current price by EntryOffsetTicks if the. The order goes in TriggerPending until the StopPrice is hit then submits the Limit Order.

        Myself and a couple of user have been using this for several with no issues.

        Hope this helps.
        Chris (aka ctrent)

        if ( BuyOnBarClose )
        {
        if ( this.EntryOffsetTicks > 0 )
        { // submit StopLimit order above
        double stopPrice = Close[0] + (this.EntryOffsetTicks*ticksize);
        double limitPrice = stopPrice + (this.StopLimitOffsetTicks*ticksize);
        // 2
        buyOrder = account.CreateOrder(Instrument, OrderAction.Buy, OrderType.StopLimit, OrderEntry.Manual, TimeInForce.Day, quantity, limitPrice, stopPrice, OCO_String, "Entry", Core.Globals.MaxDate, null);
        buyTriggerPrice = 0;
        buyOrderStart = CurrentBar;

        //Attach the AtmStrategy
        buyStrategy = NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(buyStrategy, buyOrder);
        }
        else
        { // submit Limit order below
        double stopPrice = 0;
        double limitPrice = Close[0] + (this.EntryOffsetTicks*ticksize);
        // 2
        buyOrder = account.CreateOrder(Instrument, OrderAction.Buy, OrderType.Limit, OrderEntry.Manual, TimeInForce.Day, quantity, limitPrice, stopPrice, OCO_String, "Entry", Core.Globals.MaxDate, null);
        buyTriggerPrice = 0;
        buyOrderStart = CurrentBar;

        //Attach the AtmStrategy
        buyStrategy = NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(buyStrategy, buyOrder);
        }



        }

        Comment


          #5
          To implement improved pricing for Stop Limit orders (i.e. Limit Price < Stop Price for Buy or Limit Price > Stop Price for Sell) then have a look at the solution I have found:

          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


          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, 04-17-2024, 06:40 PM
          6 responses
          49 views
          0 likes
          Last Post algospoke  
          Started by arvidvanstaey, Today, 02:19 PM
          4 responses
          11 views
          0 likes
          Last Post arvidvanstaey  
          Started by samish18, 04-17-2024, 08:57 AM
          16 responses
          61 views
          0 likes
          Last Post samish18  
          Started by jordanq2, Today, 03:10 PM
          2 responses
          9 views
          0 likes
          Last Post jordanq2  
          Started by traderqz, Today, 12:06 AM
          10 responses
          21 views
          0 likes
          Last Post traderqz  
          Working...
          X