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 it is, what outer controlling code is going to
          call the TriggerCustomEvent? Are you using a timer?

          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

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by cmv727, Today, 05:38 AM
                0 responses
                2 views
                0 likes
                Last Post cmv727
                by cmv727
                 
                Started by AlessioCianini12, Today, 01:38 AM
                0 responses
                27 views
                0 likes
                Last Post AlessioCianini12  
                Started by nandhumca, Yesterday, 11:54 PM
                0 responses
                29 views
                0 likes
                Last Post nandhumca  
                Started by nandhumca, Yesterday, 11:51 PM
                0 responses
                28 views
                0 likes
                Last Post nandhumca  
                Started by ezrollin, Yesterday, 11:48 PM
                2 responses
                29 views
                0 likes
                Last Post ezrollin  
                Working...
                X