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

How to see exact bar with timestamp for fills of a Unmanaged Stop Order

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

    How to see exact bar with timestamp for fills of a Unmanaged Stop Order

    Dear Team,

    I have downloaded minute data using the Historical Data Download option from eSignal for ES ##-##.

    I have a strategy that works with the 420 Minutes bar set through 'Data Series' options in Strategy Analyzer. I submit the orders using:
    Code:
    SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopMarket, Position.Quantity, 0, stopPrice, "", signalName);
    Now, for some investigation, I need to see the exact 1-minute bar with the timestamp which triggered the execution. I need to see the exact time when the fill is received and OHLC for the minute bar. At present, all timestamps are rounded to 420 minutes and I am unable to see the exact fill time. Where can I find that particular information?

    #2
    Hello snakereptile,

    Thanks for your post.

    If you use Standard Order Fill Resolution, the OHLC of data series will be used for submitting orders. Using High Order Fill Resolution or submitting orders to a single tick data series fills orders with more granular data. See the help guide documentation below for more information about standard order fill vs high order fill resolution.

    Understanding Order Fill Resolution: https://ninjatrader.com/support/help...FillResolution
    OrderFillResolution: https://ninjatrader.com/support/help...igh+order+fill

    SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' -https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm
    TickReplay — https://ninjatrader.com/support/help...ick_replay.htm
    Developing for Tick Replay - https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay

    Something you could do is try using OnExecutionUpdate() and prints to print out the bar when an order fills. See the help guide documentation below for information on OnExecutionUpdate() and a sample script using OnExecutionUpdate().

    OnExecutionUpdate(): https://ninjatrader.com/support/help...tionupdate.htm
    SampleOnOrderUpdate: https://ninjatrader.com/support/help...and_onexec.htm

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

    Comment


      #3
      Thanks NinjaTrader_BrandonH

      I have the Order fill resolution set to Standard. I tried by adding prints statements in OnBarUpdate and OnExecutionUpdate. I like to understand how the fill price is decided for the StopMarket order. I am running my strategy with the below settings:

      Click image for larger version

Name:	Capture.JPG
Views:	28
Size:	8.0 KB
ID:	1179507

      A portion of the logs look like below:
      Code:
      onbar | idx: 0, time: 2007-03-23 05:00:00 | 1444.5, 1445, 1443.75, 1444
      onbar | idx: 0, time: 2007-03-23 12:00:00 | 1444.25, 1447.75, 1443.5, 1447.5
      exec | orderId: NT-00006-787, time: 2007-03-23 19:00:00, price: 1450.5
      onbar | idx: 0, time: 2007-03-23 19:00:00 | 1447.5, 1451, 1444.5, 1448.25
      onbar | idx: 0, time: 2007-03-23 21:00:00 | 1448.25, 1449.75, 1446.75, 1447
      onbar | idx: 1, time: 2007-03-23 21:00:00 | 1444.75, 1451, 1443.5, 1447
      exec | orderId: NT-00010-787, time: 2007-03-23 21:00:00, price: 1447
      onbar | idx: 0, time: 2007-03-26 05:00:00 | 1446.25, 1447, 1444.5, 1446.25
      onbar | idx: 0, time: 2007-03-26 12:00:00 | 1446, 1448.25, 1444.25, 1447
      exec | orderId: NT-00012-787, time: 2007-03-26 19:00:00, price: 1443
      onbar | idx: 0, time: 2007-03-26 19:00:00 | 1446.75, 1448, 1433.75, 1444.25
      exec | orderId: NT-00013-787, time: 2007-03-26 21:00:00, price: 1446
      onbar | idx: 0, time: 2007-03-26 21:00:00 | 1444.25, 1449.25, 1443.25, 1445.75
      onbar | idx: 1, time: 2007-03-26 21:00:00 | 1446.25, 1449.25, 1433.75, 1445.25
      onbar | idx: 0, time: 2007-03-27 05:00:00 | 1444.75, 1446, 1444.5, 1445.25
      onbar | idx: 0, time: 2007-03-27 12:00:00 | 1445.25, 1446, 1442.5, 1445.5
      onbar | idx: 0, time: 2007-03-27 19:00:00 | 1445.5, 1445.5, 1436, 1440.75
      exec | orderId: NT-00015-787, time: 2007-03-27 21:00:00, price: 1435.25
      onbar | idx: 0, time: 2007-03-27 21:00:00 | 1440.5, 1442.25, 1430.5, 1436.5
      onbar | idx: 1, time: 2007-03-27 21:00:00 | 1445, 1446, 1436, 1440.5
      exec | orderId: NT-00018-787, time: 2007-03-27 21:00:00, price: 1436.5
      onbar | idx: 0, time: 2007-03-28 05:00:00 | 1436.75, 1437.25, 1433.25, 1434
      onbar | idx: 0, time: 2007-03-28 12:00:00 | 1434, 1437.25, 1433, 1434.75
      exec | orderId: NT-00020-787, time: 2007-03-28 19:00:00, price: 1430.25
      onbar | idx: 0, time: 2007-03-28 19:00:00 | 1434.75, 1436.5, 1424.25, 1428.5
      onbar | idx: 0, time: 2007-03-28 21:00:00 | 1428.25, 1432.25, 1426.75, 1429.5
      onbar | idx: 1, time: 2007-03-28 21:00:00 | 1440.5, 1440.75, 1424.25, 1429.5
      exec | orderId: NT-00023-787, time: 2007-03-28 21:00:00, price: 1429.5
      onbar | idx: 0, time: 2007-03-29 05:00:00 | 1429.25, 1433.25, 1428.5, 1432.75
      onbar | idx: 0, time: 2007-03-29 12:00:00 | 1433, 1434.5, 1432, 1433.5
      idx is in the index of data series where 0 is the default 420-minute bar and 1 is a daily bar added using AddDataSeries call.

      As you can see, times are rounded to 420 minutes in exec (OnExecutionUpdate) call. Is there any possibility that fill price of a stop market order is something other than Open, High, Low, Close and the stop price itself?

      Comment


        #4
        Hello snakereptile,

        Thanks for your note.

        Please review the help guide document on the differences on real-time vs backtest (historical).
        http://ninjatrader.com/support/helpG...ime_vs_bac.htm

        When in historical data (backtesting), only the Open, High, Low, and Close will be available and there will be no intra-bar data available. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.

        Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.

        Since all actions happen when the bar closes, this is why you will see times rounded to the 420-minute bar.

        Below is a link to the help guide on Calculate.
        https://ninjatrader.com/support/help.../calculate.htm

        That said, you could use High Order Fill Resolution which allows for intra-bar order fills with historical processing.

        To improve the accuracy of a backtest, you may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar.

        Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.

        High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

        Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

        SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm

        TickReplay — https://ninjatrader.com/support/help...ick_replay.htm

        Developing for Tick Replay -
        https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay

        Additional information may be found in this NinjaTrader Forum post —
        https://ninjatrader.com/support/foru...mance?t=102504

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

        Comment


          #5
          Hi NinjaTrader_BrandonH

          Thanks for providing all these resources to help me understand some of the crucial functionality.

          For some reason, I like to stick with Standard resolution settings meaning not allowing the strategy to see less than a 420-minute bar. I also observe that the fill price is always equal to the stop price of the order.

          I would like to understand what triggers the execution of the stop market order. I mean what are the conditions NT simulator is checking to determine whether to execute the stop order or leave it to the next bar.

          Comment


            #6
            Hello snakereptile,

            Thanks for your note.

            I would like to understand what triggers the execution of the stop market order.

            The stop market order would submit if the order entry conditions you have set to submit the order become true during that bar and the order would be submitted to the stopPrice property that is set when calling SubmitOrderUnmanaged().

            SubmitOrderUnmanaged(): https://ninjatrader.com/support/help...runmanaged.htm

            Note that if you are using Standard Order Fill Resolution when backtesting, actions will occur only at the close of the bar since OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.

            If you would like to accurately fill orders at an exact price and time when backtesting a strategy, you would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay. See the help guide documentation, forum thread, and SampleIntrabarBacktest example script linked in post#4 for more information.

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

            Comment


              #7
              Hi NinjaTrader_BrandonH


              The stop market order would submit if the order entry conditions you have set to submit the order become true during that bar and the order would be submitted to the stopPrice property that is set when calling SubmitOrderUnmanaged().
              What are these order entry conditions? For example, is my order executed when the stop price is between high and low, or between open and close. I am trying to understand these conditions for stop market orders for both Buy and Sell order actions.

              Comment


                #8
                Hello snakereptile,

                Thanks for your note.

                I would not be able to determine the order entry conditions that are set in the strategy without seeing the strategy's code.

                Did you create the strategy in question? Or was the strategy created by a third-party developer?

                If the strategy was created by a third-party developer, please reach out to the developer of the strategy for information about the order entry conditions that the strategy uses to place orders.

                If you created the strategy, the order entry conditions would be whatever condition(s) you have created for submitting the order.

                For example, if we wanted to submit an order when the current Close price is greater than the Open, the order entry condition code would look something like this.

                Code:
                if (Close[0] > Open[0])
                {
                    //call your entry order method, such as SubmitOrderUnmanaged().
                }
                In this case, the order would be submitted when the Close price is greater than the Open price at the close of the bar when running a strategy with Calculate.OnBarClose or when backtesting.

                See this help guide for more information about working with Unmanaged Order Methods: https://ninjatrader.com/support/help...edOrderMethods

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

                Comment


                  #9
                  Sorry, NinjaTrader_BrandonH. I think I wasn't clear in my last post. I used some wrong terminology.

                  Strategy is not developed by me but I understand the order entry conditions by looking at the code.

                  I would like to understand what triggers the execution of the stop market order. I mean how NT simulator determines (on each bar) whether to fill the stop order or leave it to the next bar. There has to be some standard internal logic to make that decision, probably based on the pricing of the bar.

                  Comment


                    #10
                    Hello,

                    Thanks for your reply.

                    The fill of an order would depend on the price going through the order (or touching it in the case of MIT or StopMarket type).

                    Please see this link for clarity on historical order fill processing: https://ninjatrader.com/support/help...lFillAlgorithm
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi NinjaTrader_PaulH NinjaTrader_BrandonH

                      That's I believe so as well, I place an unmanaged buy StopMarket order with stop price and the stop price
                      1451.75 is between High/Low of the next bar coming in with OHLC `1456.75, 1458.25, 1444.5, 1447. But still, the order is not executed. My strategy is running on 420-minute bars with Order Fill Resolution set to Standard (Fastest). Fill limit orders on touch is set to false but I don't think this is applicable for StopMarket orders.

                      Code:
                      11-04-2007 12:00:00 Strategy 'sRev20211106no1pc/-1': Entered internal SubmitOrderUnmanaged() method at 11-04-2007 12:00:00: BarsInProgress=0 Action=Buy OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=1451.75 SignalName='shrt_sl_20_SXVol'
                      onbar | idx: 0, time: 2007-04-11 19:00:00 | 1456.75, 1458.25, 1444.5, 1447
                      11-04-2007 19:00:00 Strategy 'sRev20211106no1pc/-1': Changed custom managed order: orderId='NT-00063-3516' account='Backtest' name='shrt_sl_20_SXVol' orderState=Working instrument='ES ##-##' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=1451.75 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2007-04-11 12:00:00' gtd='2099-12-01' statementDate='2021-11-26' limitPriceChanged=0 quantityChanged=1 stopPriceChanged=1451.5
                      onbar | idx: 0, time: 2007-04-11 21:00:00 | 1446.75, 1449.5, 1445.75, 1449
                      11-04-2007 21:00:00 Strategy 'sRev20211106no1pc/-1': Changed custom managed order: orderId='NT-00063-3516' account='Backtest' name='shrt_sl_20_SXVol' orderState=Working instrument='ES ##-##' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=1451.5 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2007-04-11 12:00:00' gtd='2099-12-01' statementDate='2021-11-26' limitPriceChanged=0 quantityChanged=1 stopPriceChanged=1452.5
                      Can you please provide an explanation why this stop order didn't fill?

                      Thanks,
                      Harsh
                      Last edited by snakereptile; 11-26-2021, 06:45 AM.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by KirkHammett, Today, 03:23 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post KirkHammett  
                      Started by eleven, Yesterday, 10:06 PM
                      0 responses
                      35 views
                      0 likes
                      Last Post eleven
                      by eleven
                       
                      Started by ezrollin, Yesterday, 08:12 PM
                      7 responses
                      72 views
                      0 likes
                      Last Post bltdavid  
                      Started by kyamato, 11-23-2021, 10:51 PM
                      6 responses
                      91 views
                      0 likes
                      Last Post jeronymite  
                      Started by fscabrera03, Yesterday, 07:14 PM
                      0 responses
                      49 views
                      0 likes
                      Last Post fscabrera03  
                      Working...
                      X