Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

sometimes no trades on new day's session, need to restart every day

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

    sometimes no trades on new day's session, need to restart every day

    At this point of investigating my issue , I just want to know if this is something other people encounter / experience.

    The issue:
    Today I no longer leave the strategies working live overnight, but rather stop and restart them every start of trading day. I completely remove them and define from scratch.
    There were no data loss overnight. Its not a weekend of maintenance. I dont see any missing chart data periods. If I restart the strategy is shows historical trades that it should have executed, but didnt.

    Background:
    over the last several years I have written a dozen of strategies with 3-4 thousand lines of code each sometimes. Some make money some dont .
    Most working with futures markets.
    some more complex than others. some with managed and some non manages order entry. most of them are with multi data series timeframes (same instrument)
    ALL my strategies are session bound and go flat in the end of session.
    I work with NINJA broker account via Continuum data connection.
    the platform is on a VPS so its 24/7 .

    Happy to hear what's the experience is.

    I tried to work with the Sample programs that come with NinjaTrader., I can fairly confidently say they work all the time. They dont have the above issue.
    And that means that the above issue is " something of my doing "
    Nevertheless, I have couple of thoughts :
    - the SAMPLE code is fairly simple in comparison to mine
    - I realize that I am not an expert coder
    - I do notice that ninjatrader is a memory hog if not restarted. and although I like NinjaTrader very much, I know it has its problems.

    So currently I am not doing anything to solve this , I just work hard every day and accept my fate.
    But it occupies my mind once in awhile ....


    #2
    Hi dadarara, thanks for posting. There are several reasons why you would see differences between real time and a backtest. Our colleague Chelsea made a guide linked below on these differences and what you can do to the strategy to improve the differences:

    Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics.


    If the strategy runs OnEachTick and calculates intrabar values, turning on Tick Replay and/or adding intrabar granularity can help with this.

    Kind regards,
    -ChrisL

    Comment


      #3
      thanks for the answer but it has nothing to do with my concern ...
      just read it again if you can

      Comment


        #4
        Hi dadarara, thanks for the follow up. Please also make sure you are monitoring the Trace Orders in real time. This will tell you if an order was ignored.



        Reasons for ignored orders can include these order entry rules:


        Kind regards,
        -ChrisL

        Comment


          #5
          thank you for the advice
          Though again it has little to do with my concern.

          ALL my strategies WORK. its just that they work only if I restart them every new session. though sometimes they work even if I dont restart. there is no pattern
          When the strategy is working , it DOES send all orders like it should .
          SO .... it is not a permanent issue that happens all the time and every time.

          it "feels" like sometimes the the DATA stream is not working and data is not flowing to the strategy and the OnBarUpdate() is not triggered for example. thus I dont see any PRINT messages in the output window.
          I have for example this code.
          Code:
          if (BarsInProgress == 0 ) Print("new 5min bar!!");
          So consider my following actions:
          1) I define a strategy for a given chart and I activate it.
          2) over the period of a day it makes all the trades as planned
          3) I leave the strategy active overnight.
          4) next day begins and I see a message following this code:
          Code:
          bool isNewSession = sessionIterator.IsNewSession(Time[0],true);
          if (isNewSession)
          {
          Print("New Session started");
          sessionIterator.CalculateTradingDay(Time[0], true);
          }​
          5) after that message , no trades are done. and I don't see anything.
          6) I stop and remove the strategy in the middle of the sessions.
          7) I define the strategy from scratch with all parameters and activate it
          8) I get all the history messages and all the historical trades like it was supposed to execute in real time.

          during the "non activity window" the CHARTs work ok, and I see the price changes and all the other activities like Indicators are working.

          my code for defining a session is :
          Code:
          private SessionIterator sessionIterator;
          ​....
          else if (State == State.DataLoaded)
          {
              //stores the sessions once bars are ready, but before OnBarUpdate is called
              if (sessionIterator == null)  sessionIterator = new SessionIterator(Bars);
          }
          ....
          ​protected override void OnBarUpdate()
          {
          bool isNewSession = sessionIterator.IsNewSession(Time[0],true);
          // calculate the new trading day
          if (isNewSession)
          {
          Print("New Session started");
          sessionIterator.CalculateTradingDay(Time[0], true);
          }
          ....
          
          }
          
          ​



          Comment


            #6

            Do you see any error messages in the "Log" tab when your strategy is not performing as expected?

            Does the name of the strategy show the (D) before its name when it is not working?

            Comment


              #7
              no
              no

              it looks like all is normal. no error . nothing .

              Comment


                #8
                Hello dadarara,

                Are there new bars forming on the chart the strategy is applied to?

                Please create a new blank script. In the script just print the State and the Time in OnBarUpdate().

                Print(string.Format("{0} | State :{1}", Time[0], State));

                Can you reproduce testing only the new test script?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi

                  yes , new bars forming on the chart the strategy is applied to.

                  need to clarify what you asking me to do :
                  what do you mean by "new blank script" ? including all my trade logic? or to Generate new EMPTY strategy ?
                  the reason I ask is that when I run the SampleMACrossOver strategy overnight it work fine. BUT it does not have any session iterator either.
                  So asking me to create an empty script will not result in anything meaningful I think.

                  if we could monitor somehow the flow of data for the active strategy .... ?
                  placing PRINT commands will not help it of course. because they are simply NOT printed while this situation occurs.

                  please advise
                  Last edited by dadarara; 11-08-2022, 10:01 PM.

                  Comment


                    #10
                    Hello dadarara,

                    Yes, a new blank script without any logic.

                    Your claim is that strategies stop processing real-time data in OnBarUpdate().

                    Reduce the test to only testing that.

                    Once you certain the behavior cannot be reproduced, add a session iterator and print the session close time.

                    Test only that.

                    From there continue adding code until you discover the issue.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    110 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    59 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    37 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    41 views
                    0 likes
                    Last Post TheRealMorford  
                    Started by Mindset, 02-28-2026, 06:16 AM
                    0 responses
                    78 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Working...
                    X