Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Enabling strategy: historical executions executed live!

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

    Enabling strategy: historical executions executed live!

    After coding many strategies successfully I have just come across a really bizarre situation where the enable-strategy start-up routine doesn't fire off the historical orders properly but leaves them in limbo with the result that they execute on the first live bar.

    Obviously this sounds totally foobar'd, so I have put in loads of debugging but I am no closer to working out my problem.

    I have TraceOrders = true and this shows that I call the correct order entry EnterLong(), but then neither my OnOrderUpdate() nor OnExecution() events are fired.

    I have set the strategy parameters so that approximately 20 days of data are traded historically before the first live bar. However historically, the orders are not executed - the order instead are held until the first bar executes live, and then they go through, and then I see the OnOrderUpdate() and OnExecution() events for the historical order firing, and in fact it executes live and I get a fill and a position in my IB TWS app that I can see.

    Is there something obvious that I have forgotten or something new in NT7 v1.0?

    #2
    Thanks for the report, adamus. I'm not sure about what you're seeing. Do you have a simple strategy we can use on our side here to see this?
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Simple strategy? Hmmm. No. I've coded a lot of helper functions to make it easier to write strategies.

      What am I not describing in my first message which you are not clear about?

      Comment


        #4
        It's not clear how to reproduce what you're seeing. Please submit a simple strategy and steps needed so that I can confirm there's an issue and pass to development. Thanks.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Hi Ryan

          I appreciate you want to reproduce the issue at your end but initially my thoughts are that I have done something wrong, since I have never seen this before and I haven't loaded a new version.

          Should I assume from your reaction that there is nothing glaringly obvious which I should check?

          Comment


            #6
            Thanks for the reply, adamus. From your description it sounds like you are running into an issue where historical orders are actually submitted to an account. This is not expected and if there were any changes that caused this, it is not intentional and we're interested in knowing the details to reproduce on our end.

            To get to this goal: A strategy we can use on our end works best. Otherwise we need to break down all the pieces of the scenario. We will still need a strategy and steps, but I may be able to build one if I have all the factors down.

            EnterLong() - You're seeing this on a market order.

            How recent did the condition evaluate true historically? Is it on the same bar the strategy started on, or prior to this?

            Using if (Historical) return; technique can allow you to submit only to real time bars, but it also excludes all historical trades. What technique are you using to allow historical trades, but force an order to be submitted on the first real time bar?

            Do you have sync account position set to true?

            What are your order submission settings under tools > options > Strategies > NinjaScript tab. WaitUntilFlat or Immediately submit?
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              You are totally right that it's not expected!

              Let me send you the strategy then. However I built a new suite of helper functions for this strategy and I haven't used them in real time anywhere else, so I suspect that it is my mistake and that the mistake lies in these helper functions.

              With all the helper functions though I'm sure you will say the strategy is not simple enough for you to work with, even though I would say it is well programmed (I am a programmer by training).

              Tell me what you want to do.

              In answer to your questions:

              Originally posted by NinjaTrader_RyanM
              EnterLong() - You're seeing this on a market order.

              How recent did the condition evaluate true historically? Is it on the same bar the strategy started on, or prior to this?
              I set up the strategy to execute about 500 bars historically before going live. The market order was triggered in this instance that I am looking at now after about 125 bars.

              Originally posted by NinjaTrader_RyanM
              Using if (Historical) return; technique can allow you to submit only to real time bars, but it also excludes all historical trades. What technique are you using to allow historical trades, but force an order to be submitted on the first real time bar?
              You are right that I am forcing the order on the first real time bar, or better said, resubmitting it, but this is unintentional and I can fix it. I realise now from investigating further that this is due to my code and therefore irrelevant.

              The main problem that I cannot fix is that the market order is not executed during historical trading in the run-up to the first bar. Or at least I don't' know how to fix it.

              I'm not using "if (Historical) return;". I want allow historical trades to be transacted.

              For reasons unknown, the market order is blocked from executing in the historical run-up, despite TraceOrders showing that it "Entered internal PlaceOrder() method at.... " during historical trading.

              Immediately after seeing that TraceOrders log statement, I expect to see the OnOrderUpdate and OnExecution events logging in the output window, but I don't, it carries on relentlessly with the OnBarUpdate.

              That is the main issue.

              Originally posted by NinjaTrader_RyanM
              Do you have sync account position set to true?
              No. It is set to false.

              Originally posted by NinjaTrader_RyanM
              What are your order submission settings under tools > options > Strategies > NinjaScript tab. WaitUntilFlat or Immediately submit?
              WaitUntilFlat.

              Comment


                #8
                Hi Ryan,
                here's the ToString() output of the market order returned by EnterLong(), which should be executed at the market but seems to fall through a crack in the PlaceOrder() method. It looks completely normal to me.

                Order='eef07cd4bc5a451bb293fb414e35aa59/DU58298'
                Name='EnterLongMkt'
                State=PendingSubmit
                Instrument='$AUDUSD'
                Action=Buy
                Limit price=0
                Stop price=0
                Quantity=0.1M
                Strategy='Test'
                Type=Market
                Tif=Gtc
                Oco=''
                Filled=0
                Fill price=0
                Token='f6d3f51eebea48b5b53e91a33d12293f'
                Gtd='01/12/2099 00:00:00'

                Comment


                  #9
                  To help isolate this, it would be good to see how your strategy performs with only historical data and only real time data.

                  Run two tests:

                  if (Historical) return; //forces real time only
                  Check if you're seeing order placement.

                  if (!Historical) return; //forces on historical only

                  With this you can evaluate whether the historical run only produces orders that are actually submitted to the account.
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    I put that before the EnterLong call in the OnBarUpdate()?

                    Comment


                      #11
                      Yes, that should be the first line in OnBarUpdate().
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        Historical is always false.

                        That can't be right, can it?

                        Comment


                          #13
                          Historical should be false for every real time update.

                          If you have a statement like, if (Historical) return; then it will always be false since you're returning out any time it's true.

                          Is this what you are seeing or is it erroneously returning false on historical data?
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            I'm seeing it return false for every onbarupdate right from the start of the historical trading period and also in real time.

                            I'm just logging it with

                            Code:
                            Print("Historical==" + Historical);

                            Comment


                              #15
                              Thanks. It will be good then to identify why you are getting these results. Can you save a copy of your strategy, strip out anything unnecessary to see the issue and share this with us. The simpler the better. You can attach here or mail to [email protected] Attn: RyanM
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              630 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              364 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              566 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X