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

restart ninjatrader daily

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

    #16
    i connected this sample strategy to IB to trade IBKR on 1 minute chart. what i notice is that for the first time,
    1. the strategy attempts to submit order in historical data which is not send to the broker. i remove the historical conditions as you have suggested.
    how do you avoid submitting orders under historical conditions or is this normal by design to ensure that there is a order object available for step # 2 below.
    4Historical0 Current bar time: 2021-10-18 6:31:00 AM
    Strategy 'restartdailyexampleRevised/208471452': An order placed at '2021-10-18 6:32:00 AM' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.
    2021-10-18 6:32:00 AM Strategy 'restartdailyexampleRevised/208471452': Ignored SubmitOrderManaged() method at 2021-10-18 6:32:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=1.00 StopPrice=0 SignalName='dobedo' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'
    5Historical1 Current bar time: 2021-10-18 6:32:00 AM

    2. when i stop and start the strategy, the order object is still active. this is good.
    Attached Files

    Comment


      #17
      Hello junkone,

      Thank you for your reply.

      1. the strategy attempts to submit order in historical data which is not send to the broker. i remove the historical conditions as you have suggested.
      how do you avoid submitting orders under historical conditions or is this normal by design to ensure that there is a order object available for step # 2 below.
      4Historical0 Current bar time: 2021-10-18 6:31:00 AM
      Strategy 'restartdailyexampleRevised/208471452': An order placed at '2021-10-18 6:32:00 AM' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.
      2021-10-18 6:32:00 AM Strategy 'restartdailyexampleRevised/208471452': Ignored SubmitOrderManaged() method at 2021-10-18 6:32:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=1.00 StopPrice=0 SignalName='dobedo' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'
      5Historical1 Current bar time: 2021-10-18 6:32:00 AM
      That's exactly correct, it needs to have orders submitted historically in order for it to get the order object when it is restarted. The message you are seeing there simply is letting you know that some orders are being ignored that it tried to submit historically because it had not yet processed the number of bars required to satisfy the strategy's BarsRequiredToTrade setting (which is 20 by default, after 20 bars you should see historical orders being entered).

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

      Comment


        #18
        to extend this to real life situations,
        1. i would need to store the state of the orders submitted using onTerminate
        2. enter the same orders for historical bars
        3. resync the order when state transitions to realtime.
        4. what do i do when the order got filled between restarts? i experimented with filling the order using IB (convert to market) and the entryOrder object is null after sync.

        Syncing account position on starting strategy 'restartdailyexampleRevised/208471452'. Account position='1L IBKR' Strategy position='S IBKR'
        for eg. in the code below, what should i expect to be state of entryOrder when the order is filled in between restarts?
        Code:
         else if (State == State.Realtime)
        {
        // convert any old historical order object references
        // to the new live order submitted to the real-time account
        if (entryOrder != null )
        {
        Print("found historical entry order " + entryOrder.ToString());
        entryOrder = GetRealtimeOrder(entryOrder);
        if (entryOrder != null ){
        Print("found realtime entry order " + entryOrder.ToString());
        }
        
        }

        Comment


          #19
          Hello junkone,

          Thank you for your reply.

          No. You do not need to save the order state on terminating the strategy, the strategy will simply iterate over the new data and as long as the order still matches what it calculates it should be in currently when iterating over the historical bars, it will simply resume that order. If the order has filled while the strategy was off and it has calculated it would be in say, a long position and your account is also in a long position, it would simply submit any protective orders for that position it has calculated it should have. If, however, the order has filled and the strategy calculates it would now be in a different position, it will submit a market order to synchronize your account to the newly calculated position.

          Keep in mind that if the order does fill overnight and the strategy is not running you would be left in an unprotected position until the strategy is reactivated.

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

          Comment


            #20
            1. i ran a test where i placed the order and switched off the strategy to simulate restart. when the order fills during the time it was switched off and i turned on the strategy, the market position still looks flat.
            how do i prevent it?
            2, if i have a order with the same name that was filled, would ninjatrader wait for the last open order with same name or would it find a matching order and match with a filled order with same name. i do have a variation where ninjatrader finds a order with same name but prints that it was already filled. just curious on the sequence.
            Attached Files
            Last edited by junkone; 10-24-2021, 11:07 PM.

            Comment


              #21
              Hello junkone,

              Thank you for your reply.

              Was the order that filled an entry or exit order? If an exit order fills and the strategy calculates that it would be in a flat position and the account is also flat this would be expected - if the order fills and the account position does not match the strategy position I would expect that if you are using immediately submit, synchronize account a synchronization order would occur to bring the account in line with the strategy position.

              If the order was filled there would be no active order to match to.

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

              Comment


                #22
                here is an example. i am connecting to IB paper a.c using audusd.
                i have a limit order for entry. then i made the order market from IB to simulate a fill.
                the exit order is in place as planned.
                when i switch off the strategy and turn it on, the exit order does not show up again and the strategy assumes is a new one showing the limit entry order again,
                Attached Files

                Comment


                  #23
                  Hello junkone,

                  Thank you for your reply.

                  The strategy would not recognize the external order change placed from IB to simulate the fill and would still be under the assumption that it should have an unfilled limit order when restarted as the previously calculated order would not have executed at the price it was originally placed at. To properly simulate this you would need to wait until the order is filled by price movements and the exit order is placed, then stop and restart the strategy.

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

                  Comment


                    #24
                    i did exactly how you suggested. the exit order got cancelled when i restarted the strategy. attached trace for AUDUSD using a.c DU4596838
                    Attached Files
                    Last edited by NinjaTrader_Kate; 10-25-2021, 03:14 PM. Reason: removed trace file as it contains personally identifiable information

                    Comment


                      #25
                      Hello junkone,

                      Thank you for your reply.

                      I've removed the log/trace files from your latest and previous posts. We would ask that you not post those on the forums as they can contain personally identifiable information. However, I would like to look at the latest log files as trace files are not as useful for order submission issues. However, we would want you to send those into us directly through the platform so they are not posted publicly.

                      You can send these by going to the Control Center-> Help-> Email Support

                      Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default.

                      Please reference the following ticket number in the body of the email: 3190288 ATTN Kate W.

                      Thanks in advance; I look forward to assisting you further.
                      Kate W.NinjaTrader Customer Service

                      Comment


                        #26
                        thanks. sending it now. also pl let me know what to look for in these log files so i can check it myself. i appreciate all the help you are providing me.

                        Comment


                          #27
                          Hello junkone,

                          Thank you for your files.

                          The issue you are seeing is due to running the script in real time using OnEachTick whereas in the historical data the conditions in the script will be run as a backtest, meaning the script can only run OnBarClose because all that is known of historical bars is the OHLC of each bar, not in what order the ticks making up that bar originally arrived. When backtesting over the historical data then, orders would be placed on the bar after the bar whose closing triggered the order. This may cause discrepancies between what the strategy calculates for an order vs. the order that was placed in real time using OnEachTick. The advantage of using Immediately Submit, Synchronize account is that if the orders do not match they will be cancelled but new orders will be placed to bring you in line with what the strategy has calculated.

                          As mentioned in the help guide, if the historical orders do not match real-time orders made previously they are cancelled.

                          If you want to ensure that your strategy resumes the previously placed orders and positions with the 'Immediately submit' setup, you will need to ensure that the historical trades match the real time trades.

                          Adding intra-bar granularity can help with this.

                          When in historical data, only the Open, High, Low, an Close will be available and there will be no intra-bar data. Intra-bar granularity adds a second data series such as a 1 tick series so that the strategy has finer granularity in the historical data in between the OHLC of the primary series. This allows for more accurate trades.

                          If the strategy was running in real-time with Calculate set to 'On price change' or 'On each tick', it would be recommended to enable TickReplay so that any indicators that may have been updating in real-time and whom's values are used in conditions that trigger orders can also update historically for each tick or price change.

                          Below is a link to an official reference sample that demonstrates how to add intra-bar granularity.
                          http://www.ninjatrader.com/support/f...ead.php?t=6652

                          Also, here is a link to the differences on real-time vs backtest (historical).
                          http://ninjatrader.com/support/helpG...ime_vs_bac.htm

                          As well as a link to the help guide on the AddDataSeries() method.
                          http://ninjatrader.com/support/helpG...dataseries.htm

                          A link to the help guide on BarsInProgress.
                          http://ninjatrader.com/support/helpG...inprogress.htm

                          And a link to the help guide on Multi-Time Frame & Instruments. Please see the section 'How Bar Data is Referenced', and 'Accessing the Price Data in a Multi-Bars NinjaScript'.
                          http://ninjatrader.com/support/helpG...nstruments.htm

                          And a link to another forum post that describes intra-bar granularity with a 1 tick series, TickReplay, and High Order Fill resolution in more detail.
                          https://ninjatrader.com/support/foru...297#post491297

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

                          Comment


                            #28
                            I have no idea how NT will make it possbile to restart computer using managed orders. i added tick dataseries and my findings are
                            1. NT had a valid exit order pending before i restarted
                            2. NT closed my position after i restarted the strategy.

                            this makes no sense to me. i sent my logs and i tested this on audusd on IB a/c ending with 838
                            Attached Files

                            Comment


                              #29
                              Hello junkone,

                              Thank you for your reply.

                              This would indicate the same entries are not being calculated historically as are being submitted live. It is considerably harder to match orders when the strategy is running OnEachTick or OnPriceChange, and it may not be able to match those orders. I'm attaching a video demonstrating using OnBarClose as the calculation mode and Immediately Submit, Synchronize Account using the attached strategy that submits its orders to a secondary 1 tick data series to improve the accuracy of fill prices:



                              After re-enabling, historical data was processed, and since the strategy calculates OnBarClose, and uses a single tick data series for order submissions, the logic is processed historically as it would if I was trading live and the order fills have intrabar granularity so any order submitted that require accurate fill prices will be as close as possible to what had happened live.

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

                              Comment


                                #30
                                as a programmer and a trader, these rules seems to be too complicated. I am going to switched to unmanaged model. I am hoping that this signalling and order cancellation would not occur in unmanaged order management. is that a valid assumption?
                                i have enough tracking within my setup that i dont rely on NT to provide guardrails.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by GLFX005, Today, 03:23 AM
                                0 responses
                                1 view
                                0 likes
                                Last Post GLFX005
                                by GLFX005
                                 
                                Started by XXtrader, Yesterday, 11:30 PM
                                2 responses
                                11 views
                                0 likes
                                Last Post XXtrader  
                                Started by Waxavi, Today, 02:10 AM
                                0 responses
                                6 views
                                0 likes
                                Last Post Waxavi
                                by Waxavi
                                 
                                Started by TradeForge, Today, 02:09 AM
                                0 responses
                                12 views
                                0 likes
                                Last Post TradeForge  
                                Started by Waxavi, Today, 02:00 AM
                                0 responses
                                2 views
                                0 likes
                                Last Post Waxavi
                                by Waxavi
                                 
                                Working...
                                X