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

OnBarUpdate not being called in strategy

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

    OnBarUpdate not being called in strategy

    In the past few weeks I have been dealing with a very frustrating problem which I was able to replicate on two discrete NinjaTrader systems:

    Basically in a nutshell my strategies were running, the charts were updating, but on some symbols I didn't see entries when they were supposed to happen. Upon reload of those chart the entries were present. So at first I thought there was a logic problem in my strategy. But after some digging I had a nagging suspicion that OnBarUpdate may not be called on some of the symbols. Which is why I then added the following code into my OBU method:

    Code:
    protected override void OnBarUpdate() {
    			
       if (BarsInProgress == 0 && FirstTickOfBar && !Historical) {
    	String heartbeat = "**** " + Times[0][startIndexSeriesZero] + ": Heartbeat " + instrumentName + " ****";
    	Print(heartbeat);
    	Log(heartbeat, LogLevel.Information);
    }
    Here is the output from the 9:00am candle rollover on my dev system:



    As you can see I am missing several symbols - I have no idea why!

    On my other production system I am experiencing the very same problem:



    Same strategy, same setup, here it's the USDJPY which doesn't print for some reason. It also did not trigger several executions overnight. Again, on reload of the chart those executions are there - they should have been taken.

    To summarize:
    • Roll over notifications are not present.
    • Executions do not take place.
    • No errors are seen in the log or output.
    • The problem happens on two discrete systems.


    I think I'm going to need some help with this as I have no idea what would cause something like this

    Many thanks in advance.

    #2
    Originally posted by molecool View Post
    In the past few weeks I have been dealing with a very frustrating problem which I was able to replicate on two discrete NinjaTrader systems:

    Basically in a nutshell my strategies were running, the charts were updating, but on some symbols I didn't see entries when they were supposed to happen. Upon reload of those chart the entries were present. So at first I thought there was a logic problem in my strategy. But after some digging I had a nagging suspicion that OnBarUpdate may not be called on some of the symbols. Which is why I then added the following code into my OBU method:

    Code:
    protected override void OnBarUpdate() {
    			
       if (BarsInProgress == 0 && FirstTickOfBar && !Historical) {
    	String heartbeat = "**** " + Times[0][startIndexSeriesZero] + ": Heartbeat " + instrumentName + " ****";
    	Print(heartbeat);
    	Log(heartbeat, LogLevel.Information);
    }
    Here is the output from the 9:00am candle rollover on my dev system:



    As you can see I am missing several symbols - I have no idea why!

    On my other production system I am experiencing the very same problem:



    Same strategy, same setup, here it's the USDJPY which doesn't print for some reason. It also did not trigger several executions overnight. Again, on reload of the chart those executions are there - they should have been taken.

    To summarize:
    • Roll over notifications are not present.
    • Executions do not take place.
    • No errors are seen in the log or output.
    • The problem happens on two discrete systems.


    I think I'm going to need some help with this as I have no idea what would cause something like this

    Many thanks in advance.
    What does it show in Market Replay? There may have been no real tick on the bar in realtime?

    Comment


      #3
      Originally posted by koganam View Post
      What does it show in Market Replay? There may have been no real tick on the bar in realtime?
      No there are definitely ticks - I'm seeing the b/a spread change on my chart. See the enclosed screen grab; my strategy is printing the current spread.

      This is very confusing....
      Attached Files

      Comment


        #4
        I would suggest first to isolate and simplify the problem as much as possible.

        Implement the most simple strategy (that does nothing, just prints the bars in OnBarUpdate()) and check, if all bars are processed as you expect.
        • If all bars are processed - you know, there is problem somewhere in the strategy. (in this case - the the way to spot the problem is to iteratively simplify your strategy and make small steps backwards by removing code and backtsting again - until you find it works. The cause of problems will be in the small part of last removed code.)
        • If some bars are NOT processed - then - it should not be hard to find out reason for this


        Finally, if you prepare showcase example and zip your NinjaTrader7 folder, then
        guys from NT7 can easily reproduce and localize the problem
        Last edited by misova; 09-28-2015, 09:44 AM.

        Comment


          #5
          Originally posted by misova View Post
          I would suggest first to isolate and simplify the problem as much as possible.

          Implement the most simple strategy (that does nothing, just prints the bars in OnBarUpdate()) and check, if all bars are processed as you expect.
          • If all bars are processed - you know, there is problem somewhere in the strategy. (in this case - the the way to spot the problem is to iteratively simplify your strategy and make small steps backwards by removing code and backtsting again - until you find it works. The cause of problems will be in the small part of last removed code.)
          • If some bars are NOT processed - then - it should not be hard to find out reason for this


          Finally, if you prepare showcase example and zip your NinjaTrader7 folder, then
          guys from NT7 can easily reproduce and localize the problem
          Yeah, I know the routine. However no matter how complex the strategy OnBarUpdate should ALWAYS be called. Whether or not it executes after that is another story. The fact that the heartbeat doesn't happen despite being the first call in OBU suggests that there is an underlying issue.

          Comment


            #6
            One common issue with NT7 is that it does not sync various types of bars.
            That means, you can have M5 bar on prices, while tick data missing on the same prices.
            They are simply not properly synchronized and can be different on each data-series.
            The differences are small most of the time, but does not have to be.

            When trading such desynchronized data-series, the trades can be missing, executions can be missing. So it is needed to check exact bars of that bar-series, where you are submitting orders (and ignore other data-series).

            This can cause, you see M5 bar and expect clear execution, but due to missing tick-data, there is no execution (if orders are sent into tick data-series).

            This all can cause real chaos sometimes, when things seem to be clear subjectively, but reality under the hood is different.

            So good question is - can you find the bar-data you are missing/expecting in historical data manager?
            When looking for executions - are you looking it in the data-series, where orders are submitted?
            Last edited by misova; 09-28-2015, 11:51 AM.

            Comment


              #7
              Definitely not my strategy

              This afternoon I wrote a test strategy which I have enclosed. Among several other symbols it was running on the EURUSD and on my first production system I have now seen it miss two hourly roll overs. My second production system is missing wheat roll overs. My third system (identical settings/setup/strategies) is missing roll overs on three symbols - screen grabs below.

              FYI - min bars required is always 0 and there are 1000 candles on my chart. The first system runs CQG and FXCM feeds with Rhithmic and eSignal as backups - the second system runs only CQG and FXCM - the third one is running Kinetick only. So clearly this is neither related to my strategy nor the data feeds - there appears to be an underlying intermittent NinjaTrader issue.

              This may also be related to another bug I reported a while back which was related to multiple data series strategies. In that case I was unable to run executions more than a few days back as mysteriously no entries were being taken beyond that. The NT support team was able to confirm this problem and hopefully it was fixed in NT8.

              Anyway, this is the reason why I added more than one data series to my test strategy. I am pretty certain that this does not happen unless more than one data series are present. Feel free to run the test on your end - on my mine it's running against 60-minute charts.
              Attached Files
              Last edited by molecool; 09-28-2015, 02:48 PM.

              Comment


                #8
                Originally posted by misova View Post
                One common issue with NT7 is that it does not sync various types of bars.
                That means, you can have M5 bar on prices, while tick data missing on the same prices.
                They are simply not properly synchronized and can be different on each data-series.
                The differences are small most of the time, but does not have to be.

                When trading such desynchronized data-series, the trades can be missing, executions can be missing. So it is needed to check exact bars of that bar-series, where you are submitting orders (and ignore other data-series).

                This can cause, you see M5 bar and expect clear execution, but due to missing tick-data, there is no execution (if orders are sent into tick data-series).

                This all can cause real chaos sometimes, when things seem to be clear subjectively, but reality under the hood is different.

                So good question is - can you find the bar-data you are missing/expecting in historical data manager?
                When looking for executions - are you looking it in the data-series, where orders are submitted?
                I know you are trying to help but I'm afraid you're barking up the wrong tree. I have been writing NinjaScript since 2009 and have a pretty deep understanding of how things work underneath the hood. Please see the comment I just posted below. This is not related to my strategy and I just proved it via a simplified test strategy.

                Comment


                  #9
                  Hello molecool,

                  Thank you for your patience on this matter.

                  May we also test your database on our end? Is there a specific Instrument List you are using or a list of instruments we may test?

                  You can send us over your database by going to Help > Mail to Platform Support... > ensure the Database option is enabled and reference this thread in your e-mail: "http://ninjatrader.com/support/forum/showthread.php?t=78589"

                  Comment


                    #10
                    Originally posted by NinjaTrader_PatrickH View Post
                    Hello molecool,

                    Thank you for your patience on this matter.

                    May we also test your database on our end? Is there a specific Instrument List you are using or a list of instruments we may test?

                    You can send us over your database by going to Help > Mail to Platform Support... > ensure the Database option is enabled and reference this thread in your e-mail: "http://ninjatrader.com/support/forum/showthread.php?t=78589"
                    I sent over the database files for all three systems. However I forgot to include the URL here - sorry! They all have the same subject: "OnBarUpdate not being called in strategy" - so should be easy find them

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by algospoke, Today, 06:40 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post algospoke  
                    Started by maybeimnotrader, Today, 05:46 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post maybeimnotrader  
                    Started by quantismo, Today, 05:13 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post quantismo  
                    Started by AttiM, 02-14-2024, 05:20 PM
                    8 responses
                    168 views
                    0 likes
                    Last Post jeronymite  
                    Started by cre8able, Today, 04:22 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post cre8able  
                    Working...
                    X