Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entering with Stop order, unmanaged

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

    #16
    In the code in Post #5, I changed both instances of StopLimit to StopMarket, compiled and ran it. I seemed to place trades ok in historical.

    So I started looking back for an example of a candle that blew through the 25 line (actually I changed it to 26, but no matter),and maybe should not have entered the trade. I see on 'NQ 12-24' M1 chart, on Nov 27th at 06:31 candle (09:31 eastern), there is a long bar going down where the buy trade was nonetheless triggered. But hard to know if that vacillated, so I changed it to a 1-second chart and ran it again. Still, there was a small candle and it could have bounced back up, so I reluctantly changed it to a tick chart, and re-ran it, which produced this error.


    Click image for larger version

Name:	image.png
Views:	75
Size:	4.6 KB
ID:	1326396

    I don't normally run on tick charts, so maybe there is something in my code that failed. I tend to use Close[0] (which should be the tick price) and GetCurrentBid() & GetCurrentAsk(). I presume those still return 'current' BId and Ask(?)

    Anyway, I guess it will take more tracking to know why the stoploss order failed. But it appears to actually be working now. I went back over a chart to find times when it crossed the 25 line and did not trade. I checked two of them by finding the cross on a tick chart and indeed, those were examples of where it did not vacillate back up/down over the 25 line.

    So I'm curious... why did it not work with the code in Post #5, using StopLimit?

    Comment


      #17
      Hello DerkWehler,

      Using Close[0] would be the Last tick used to update OnBarUpdate(). The Close[0] may be above or below the ask or bid. If you want to ensure the price is valid, compare this to the ask or bid.

      In a fast moving market, the price can change quickly. If a stop order is placed very close to the ask or bid, it's possible for the price to change before the order is accepted and working and it may move ahead of the stop price.
      We generally recommend using a stop price further above the ask if a stop, or further below the bid if a sell.

      Below is a link to a forum post where this is discussed.



      With your specific error, this was a buy order and the stop price was either equal to or below the current ask price. Use a price further above the ask.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        10-4, thanks for all your assistance! Seems to be working well with StopMarket.


        Comment


          #19
          Chelsea:

          I have been using the StopMarket method in my code and it seems to work well overall. But sometimes if does not enter where I would suspect. Here is some debug code to exemplify:

          Fifty Level Hookful - NQ 12-24 - [OnBarUpdate] - 18:54:20 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
          PLACING SHORT PENDING ORDER @ 22026, inSession = True

          Fifty Level Hookful - NQ 12-24 - [PlaceStopOrder] - 18:54:20 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
          Place stop order @ 22026: dir = Short, qty = 2, name = Entry

          Fifty Level Hookful - NQ 12-24 - [OnExecutionUpdate] - 18:54:32 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
          Name = Entry, IsEntryStrategy = True, OrderAction = SellShort, marketPosition = Short, quantity = 2, Position.Quantity = 2, price = 22024.75
          ENTRY ORDER FILLED (execution.Order.OrderState == OrderState.Filled); execution.Order.Filled = 2, Position.Quantity = 2

          So it sent the order at 22026, but OnOrderUpdate() shows it filled at 22024.75. I would think it would either place it at the right place or fail.

          I already have code in like this:

          Code:
              string log = "";
              if (pendingDir == "Long"  &&  GetCurrentAsk() >= pendingPrice)
                  log = "Current price is at/beyond requested Price for Long pending entry; PLACING MARKET ORDER";
              else if (pendingDir == "Short "  &&  GetCurrentBid() <= pendingPrice)
                  log = "Current price is at/beyond requested Price for Short pending entry; PLACING MARKET ORDER";
                                              
              if (log != "")
              {
                  Log(log);
                  PlaceMar****rder(pendingDir, qty);
              }
              else
              {
                  Log("PLACING " + pendingDir.ToUpper() + " PENDING ORDER @ " + pendingPrice + ", inSession = " + inSession);
                  PlaceStopOrder(pendingDir, pendingPrice, qty);
              }
          ​
          So it should do a market if Bid was too low.

          Any ideas why it would behave as it did?

          Comment


            #20
            Hello DerkWehler,

            Enable TraceOrders and print the order.ToString() in OnOrderUpdate().


            Print the State property in OnBarUpdate().

            Temporarily comment out all other prints.

            A stop market order fills at market price when touched which may not be the stop price.

            Also, the behavior between historical and real-time will be different unless 1-tick intra-bar granularity is implemented.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            556 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            545 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X