Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicators not painting on last bar

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

    Indicators not painting on last bar

    Version 7.1000.6, WinXP Pro. I am coding a custom indicator and found that OnBarUpdate() was not being called for the last bar on the chart. I removed my indicator and added an EMA14 indicator and saw the same problem. Downloaded V6.5 and have the same problem. Fresh install on a different machine and applied an EMA14 and same problem. Have tried this with CL & ES contracts, historical and live, all have the same problem.

    #2
    paulca, have you tried running your indicators with CalculateOnBarClose = false? The default setting is for indicators to update once the bar has closed.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Well that did fix the problem, thank you. Didn't even think of trying that since my code sets this propery to true during Init() and I was only using historical data so I only get called at the end of a bar anyway.

      That does actually prompt another question I have been meaning to ask - when using historical data why do I not get an OnBarUpdate() for each tick since the DB has an entry for each tick in chronological order?

      Paul

      Comment


        #4
        Paul, on historical data you only have access to the granularity the series you're working with is providing, so the OHLCV info - which would not include the intrabar formation of the bar, which is only available in realtime / market replay.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thanks Bertrand,

          I understand what I currently have available using historical data, the question was - since the DB contains every tick in chronological order, what is preventing NT from callling OnBarUpdate() on every tick when using historical data?

          TIA

          Comment


            #6
            Hi Paul, limiting is the granularity of the series used, if you run a 1 tick series, the OnBarUpdate() is called for each tick - if you like to see the intrabar action / signals for your indicators you could for example use Market Replay for the historical chart portion.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Originally posted by paulca View Post
              Thanks Bertrand,

              I understand what I currently have available using historical data, the question was - since the DB contains every tick in chronological order, what is preventing NT from callling OnBarUpdate() on every tick when using historical data?

              TIA
              That is what NT does when using Market Replay. Maybe you might consider using that if you want to see what actually went on during the hours in question?

              Comment


                #8
                I have the same problem with OnBarUpdate() not being called on the last bar. Yes, setting CalculateOnBarClose = false works, but I don't need/want my indicator to be calculated on every tick. When CalculateOnBarClose is set to true, why doesn't OnBarUpdate() get called?

                What I want to do is save Close[0] to my DB on the last bar. Is there another way to do this?

                Comment


                  #9
                  Originally posted by Klaorman View Post
                  I have the same problem with OnBarUpdate() not being called on the last bar. Yes, setting CalculateOnBarClose = false works, but I don't need/want my indicator to be calculated on every tick. When CalculateOnBarClose is set to true, why doesn't OnBarUpdate() get called?

                  What I want to do is save Close[0] to my DB on the last bar. Is there another way to do this?
                  The bar has to be updated at some point, either when the next bar opens (COBC = true), or when the bar is building (COBC = false). If you want to update at a different frequency intrabar, then you are going to have to create a time filter to update as you want.
                  Last edited by koganam; 12-06-2011, 01:15 AM.

                  Comment


                    #10
                    Originally posted by koganam View Post
                    The bar has to be updated at some point, either when the next bar opens (COBC = false), or when the bar is building (COBC = true). If you want to update at a different frequency intrabar, then you are going to have to create a time filter to update as you want.
                    Thanks for your reply, koganam. No, I don't want to update intrabar; I want to update when the last bar of the day closes -- I want to save the closing price of the day. I use COBC = true because it would be too CPU intensive to calculate my indicator on every tick. But, as noted, OnBarUpdate() doesn't get called when the last bar of the day closes when COBC = true. As you say, it will likely get called during the next session when the next bar opens, but then that means COBC should really be CONBO (Calculate on Next Bar Open). This seems like a bug to me.

                    Perhaps there's another way to get the closing price of the day?

                    Here's a workaround: Write another indicator that just looks for the last bar of the day and saves the closing price. This would be very light and can be run on every tick. This seems kludgey though, but I'll try it out.

                    Comment


                      #11
                      Hi Klaorman,

                      These are correct observations. With C# being event based, the bar closing and next bar opening events are the same. You may consider using GetBar() to get the bar closing price at a specific time each day. This sample can help use GetBar()
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        ... but then that means COBC should really be CONBO (Calculate on Next Bar Open). This seems like a bug to me.
                        NextBarOpen and CurrentBarClose are the same event. It is a matter of choice what to call it.

                        Comment


                          #13
                          Originally posted by NinjaTrader_RyanM View Post
                          Hi Klaorman,

                          These are correct observations. With C# being event based, the bar closing and next bar opening events are the same. You may consider using GetBar() to get the bar closing price at a specific time each day. This sample can help use GetBar()
                          http://www.ninjatrader.com/support/f...ad.php?t=19176
                          Hi Ryan,

                          But when would I call GetBar(), during the next trading session? Since OnBarUpdate() doesn't get called for the last bar when COBC = true, I'll have to get the day's closing price during the next trading session, correct?

                          I wrote the mini-indicator that I mentioned above to look for the last bar of the day with COBC = false. It worked when I put the indicator in a chart, so I added it to a Market Analyzer as a column looking at 2m bars and waited all day to see if it would work. Unfortunately, it didn't. I didn't put any Print() statements in the code to see its execution path because it had worked in the chart; the Print()s are in there for today's session! The only code I have in OnBarUpdate() is the following:

                          // if last bar of the day, save closing price
                          if ( ToTime( Time[0] ) == ToTime( 13, 00, 00 ) )
                          {
                          // Save closing price to DB
                          ...
                          }


                          I'm checking that a bar's timestamp is 1pm PST. No problems there, correct? In Market Analyzer COBC = false; I did, however, set the # of bars to look back to 2 because I didn't think it needed the default of 50, but I've reset it back to 50 for today. This code worked on a chart after the last bar had closed, but it didn't work in real-time in a Market Analyzer. Do you have any clues about why?

                          I have another question related to COBC: It's set to false for my main indicator in Market Analyzer, but initially I still occasionally got multiple alerts for the same signals (the alerts were identical to each other) intrabar when I called Alert(). I solved this by setting the rearm time to a bar's duration, but why does this happen even after I set the indicator to only calculate on bar close?

                          Thanks,
                          Klaorman

                          Comment


                            #14
                            Yes, GetBar() would be used to check prior bars. If the bar you want a value for hasn't yet closed, then it's a good opportunity to use CalculateOnBarClose = false. Anytime you need values for the "not yet closed" bar, then COBC = false is the only way.

                            With market analyzer, you don't have the convenience of chart visuals. Print statements are very useful for confirming values and following code flow so hopefully should tell you more about what your indicator is doing the next time you run it.

                            This doesn't have to be the type of thing where you wait until 1:00 PM every day to verify functionality and then you're out of luck until tomorrow once it passes. Confirm script behavior by setting the alert time a couple minutes ahead of the current time. Get things working on a simplified level and then customize it once it works as you expect.

                            Please be aware that bar stamps can vary based on the interval, and you may not have a time stamp exactly at 13:00. Print(Time[0]); will allow you to see each bar stamp.

                            Alerts are raised each time the condition is true. If you have alerts applied to a column, then it can be true for each row (instrument) in the market analyzer. Adding instrument name to any alert text may help you identify what specific row is calling it and why it may be triggered multiple times.
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_RyanM View Post
                              This doesn't have to be the type of thing where you wait until 1:00 PM every day to verify functionality and then you're out of luck until tomorrow once it passes. Confirm script behavior by setting the alert time a couple minutes ahead of the current time. Get things working on a simplified level and then customize it once it works as you expect.
                              Oh right, good idea. I tried this and verified that my script worked, but I was still afraid that it wouldn't work at the last bar. But it did! The only thing I had changed was to set the "# bars to look back" back to 50 from 2, so I guess that was the problem, although I'm not sure why that would cause my script not to run properly. However, NT was completely locked up for 5 minutes while my script was running (on the last 2m bar) because it was opening and closing DB connections for my 200-250 symbols on every tick. I've added a time check so that the script only runs during the last 30s of the day, but I have to make sure that my PC's clock is in sync with the market.

                              Originally posted by NinjaTrader_RyanM View Post
                              Alerts are raised each time the condition is true. If you have alerts applied to a column, then it can be true for each row (instrument) in the market analyzer. Adding instrument name to any alert text may help you identify what specific row is calling it and why it may be triggered multiple times.
                              The Alerts window already states the instrument in the Instrument column. I was getting the same alert for the same instrument several times intrabar when COBC = true. Even if an alert condition is true, shouldn't the COBC = true setting suppress the display of the alert (and actually, the indicator shouldn't even be calculated intrabar, so there shouldn't even be a true condition for the alert)?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Stanfillirenfro, Today, 07:23 AM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              2 responses
                              21 views
                              0 likes
                              Last Post cmtjoancolmenero  
                              Started by olisav57, Yesterday, 07:39 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by cocoescala, 10-12-2018, 11:02 PM
                              7 responses
                              944 views
                              0 likes
                              Last Post Jquiroz1975  
                              Started by oviejo, Today, 12:28 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X