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

Force OnBarUpdate

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

    Force OnBarUpdate

    Hi,

    So, a fairly common requirement I think, having googled it, but not sure I found my answer.

    Have a lot of Logic in OnBarUpdate and indicator set to OnEachTick (or OnPriceChange), which is normally fine. Tried it on some rather lethargic instruments of late and the updates are not fast enough because the indicator interacts with mouse clicks, etc. from the user. At the moment, it needs an inbound tick to kick things off.

    Now, I read about and tried 'Update()', which I hoped would do the trick, but it does not and it does clearly state in the docs it will be ignored if no bar updates are pending (shame). I could of course separate out all my logic into different functions, re-arrange OnBarUpdate, call things when a click is made, but, this is a large amount of work to overcome a very simple problem.

    So, the question is, how to 'fake' a tick (ala MT4/5!), or force OnBarUpdate to run without waiting for a tick and regardless of if there are bars to update? (praying for a simple function call )

    Thanks.

    #2
    Hello pjsmith,

    Thanks for writing in.

    Unfortunately, you cannot force OnBarUpdate() for ticks that are not there or to fake a tick.

    That said, what exactly are you wanting to trigger?

    Are you not able to trigger what you want with button events? If not, why is that?

    If you would like to force things to happen at a certain time without bar updates, you could consider using a timer.

    Note that when triggering things from other events that are not data processing events, (I.E. not OnBarUpdate() or OnMarketData()) you should use TriggerCustomEvent() to make sure BarsAgo references are correct.

    See this help guide page about using TriggerCustomEvent() and a timer: https://ninjatrader.com/support/help...ustomevent.htm

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      As I said in my original post, really. What I want to force is, OnBarUpdate. If that cannot be done, I have to relocate all the evaluation code outside of OnBarUpdate, update OnBarUpdate to use those functions instead, and call those functions from the click event, ensuring things are also synced up. Now, this is perfectly possible, but it's a lot of work and could all be avoided with a simple ForceOnBarUpdate() function (if one existed). Get it? I'm, just thinking there must have been a super simple and easy way to do this, but, I guess not.

      Comment


        #4
        Hello pjsmith,

        That is correct. OnBarUpdate() cannot be forced for ticks that are not there or to fake a tick.

        Let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by pjsmith View Post
          As I said in my original post, really. What I want to force is, OnBarUpdate. If that cannot be done, I have to relocate all the evaluation code outside of OnBarUpdate, update OnBarUpdate to use those functions instead, and call those functions from the click event, ensuring things are also synced up. Now, this is perfectly possible, but it's a lot of work and could all be avoided with a simple ForceOnBarUpdate() function (if one existed). Get it? I'm, just thinking there must have been a super simple and easy way to do this, but, I guess not.
          So, why can't you use TriggerCustomEvent?

          When the handler is called, just call OnBarUpdate() from the handler.
          Have you tried that?

          If needed, set a flag in your handler, 'IsFakeUpdate = true' so that any
          code in OnBarUpdate that needs to differentiate between your forced
          OnBarUpdate and a normal one can do so.

          But ...
          What I don't understand is, what outer controlling code is going to
          call the TriggerCustomEvent? Are you using a timer?
          Last edited by bltdavid; 01-31-2023, 11:03 PM.

          Comment


            #6
            Yes, calling OnBarUpdate with triggercustomevent might be a solution if that will work. Thank you.

            No timer. A button on the chart generates an event, sets a flag, and conditions in OnBarUpdate respond to it. I'd prefer those conditions were checked on click of the button, rather than waiting for a tick to come in. I was just looking for a simple workaround (this may be it), rather than re-working a large chunk of code.

            Comment


              #7
              Excellent.

              If you would, please report back to the forum how well it works.

              Good luck!

              Comment


                #8
                TriggerCustomEvent(o =>
                {
                OnBarUpdate();
                }, null);

                It runs but does not appear to have the desired effect, in that triggers/actions still seem to wait for an inbound tick. Will debug further when I get time.

                Comment


                  #9
                  Originally posted by pjsmith View Post
                  TriggerCustomEvent(o =>
                  {
                  OnBarUpdate();
                  }, null);

                  It runs but does not appear to have the desired effect, in that triggers/actions still seem to wait for an inbound tick. Will debug further when I get time.
                  Note that if you're using multiple data series you would update the last line before the comma to include the BIP value/Data series index.

                  Originally posted by pjsmith View Post
                  I have to relocate all the evaluation code outside of OnBarUpdate, update OnBarUpdate to use those functions instead, and call those functions from the click event, ensuring things are also synced up.

                  Exactly what I'm currently googling around to avoid.
                  Last edited by WalterSkinner; 01-31-2023, 01:29 PM.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bmartz, 03-12-2024, 06:12 AM
                  5 responses
                  32 views
                  0 likes
                  Last Post NinjaTrader_Zachary  
                  Started by Aviram Y, Today, 05:29 AM
                  4 responses
                  13 views
                  0 likes
                  Last Post Aviram Y  
                  Started by algospoke, 04-17-2024, 06:40 PM
                  3 responses
                  28 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by gentlebenthebear, Today, 01:30 AM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by cls71, Today, 04:45 AM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X