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

Forcing OnBarUpdate?

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

    Forcing OnBarUpdate?

    Is there any way to force an OnBarUpdate call on an End of Day Chart?

    I understand that this isn't a conventional programming method, but for some reason, I can't get any of the bar information in methods outside of the OnBarUpdate.

    Even though the counts say they exist, I keep getting an array out of bounds exception.

    #2
    Hi, you could try this for embedded indicators - http://www.ninjatrader-support.com/H...V6/Update.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I tried calling Update() from my method, but it does not call OnBarUpdate(). I have put in debugging statements and it does not print from the method call. My method is definitely calling it.

      Any ideas?

      Comment


        #4
        Originally posted by mazachan View Post
        I tried calling Update() from my method, but it does not call OnBarUpdate(). I have put in debugging statements and it does not print from the method call. My method is definitely calling it.

        Any ideas?
        For an example of the Inside Bar indicator (thanks PrTester) that can be called from another indicator or strategy, see the indicator found at this posting:



        This is a complete example showing how the info in the Help section that Bertrand referred you to is used.

        If instead, you're trying to invoke Update() from a timer event within the same indicator, or something like that, then good luck, I couldn't get that to work either.

        Comment


          #5
          Yeah, that's exactly what I'm trying to do, calling it from an event. I guess I have my answer then.

          Thanks for your input

          Comment


            #6
            To NinjaTrader Development:

            Will there be a way to invoke the Update() method from an event in a future release of NinjaTrader?

            Comment


              #7
              If you post an example of what you guys have already tried that would be helpful. Thanks.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Josh View Post
                If you post an example of what you guys have already tried that would be helpful. Thanks.
                Josh,

                Unfortunately it was a number of months ago, and when it didn't work, I deleted the code and tried something else which sort of works, but is much more complicated and convoluted.

                But if memory serves, I just placed a call to Update() in the event handler routine for a timer, and I think he timer code was similar to what's found in the reference sample named "SampleCustomEvents.cs".

                I tried placing the call to Update() in both the event handler and in the method called by "TriggerCustomEvent()" and neither of these worked.

                Although I didn't mention the call to Update() at the time, that's what I was doing when I made the postings to this thread back in December, when I was trying to get the help explanations clarified.

                When the code I tried didn't work, I decided to do it a different way because I didn't want to wait for a new version of NinjaTrader to be released to add this new functionality. However, if I'm mistaken, and the functionality already exists in some fashion, I'd love to know that, so I can simplify my code.

                Best Regards,

                KBJ

                Comment


                  #9
                  can you share your work around concept. i am trying to initiate a barupdate too but am lost for answers. if there is a different way of doing it, however convoluted, i would be excited to try.

                  Comment


                    #10
                    KBJ,

                    I have no additional info to provide at this point in time. Thank you for your post.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Josh, thanks for the update.

                      junkone,

                      The code for that is buried in a very complicated application that I'm writing under contract, so unfortunately I cannot share the specifics.

                      However, I can tell you enough so you can do it yourself...

                      There were three problems that I was having with using timer events:

                      1) Accessing data in an instance of the indicator from the event handler didn't seem to work the way I first tried it. I'm not very good with this aspect of C#. What seemed to be happening was that I'd set a variable and then the data would immediately be "forgotten" before the next time the OnBarUpdate was called. What I went with was to set a flag in a static bool variable while in the event handler, that was then tested from the OnBarUpdate() method.

                      2) Getting the timing to occur correctly. The main thing I was trying to do was to get something to display on the screen when the timer event fired, but I wasn't able to get this to occur, because I could not access the data and methods I wanted to call from the timer's event handler (and if I remember correctly this also did not work from the method called by TriggerCustomEvent.)

                      3) I was also trying to get a custom Plot() method to run when the timer fired, so the screen would update then and not wait for the next tick to happen in OnBarUpdate(), but the Plot method didn't like to be called no matter what parameters I passed to it (and yes, I know this would really be unsupported if I had gotten it to work.)

                      So, what my application is doing is just #1 above, by using static data. It would be nice if I could get #2 to work, because it would clean up the code; and #3 because it would allow a snappier screen response. But I wasn't able to do either of these.

                      Hope this helps.

                      Comment


                        #12
                        i am trying to understand your process and relate it to my prob
                        i have my chart plotting and trade management done from onbarupdate event. i have a form that sends in info to my strategy that i need to plot on the screen and also perform some trading logic.

                        in terms of pseudocode





                        Code:
                        class  strategy
                            {
                        
                               
                        
                          var price, direction
                        
                          onbarupdate{
                        // do some action on price and direction
                        
                        }
                           enterTradesEvent(eventargs e){
                                price=e.price;
                            direction=e.direction;
                        }


                        the prob that i noticed was that i send a event from the form and it gets handed by the eventhanler in the strategy immediately. but there was a lag time till the onbarupdate was triggered. according to NT, the onbarupdate timing is triggerd by IB data. so i want to see if i can initiate in onbarupdate quicker.

                        Comment


                          #13
                          Originally posted by junkone View Post
                          i am trying to understand your process and relate it to my prob
                          i have my chart plotting and trade management done from onbarupdate event. i have a form that sends in info to my strategy that i need to plot on the screen and also perform some trading logic.

                          in terms of pseudocode





                          Code:
                          class  strategy
                              {
                          
                                 
                          
                            var price, direction
                          
                            onbarupdate{
                          // do some action on price and direction
                          
                          }
                             enterTradesEvent(eventargs e){
                                  price=e.price;
                              direction=e.direction;
                          }
                          the prob that i noticed was that i send a event from the form and it gets handed by the eventhanler in the strategy immediately. but there was a lag time till the onbarupdate was triggered. according to NT, the onbarupdate timing is triggerd by IB data. so i want to see if i can initiate in onbarupdate quicker.
                          For me, I'm capturing mouse events and it works fine in during the day because there are many ticks coming in to call OnBarUpdate. However, it fails for end of day charts since it won't be called until the next day.

                          The reason that I am doing it this way is that NT doesn't like it when I try to access the bar information inside the event handler, similar to what someone had reported in this thread:


                          It is good to see that I'm not the only one with this problem.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Shansen, 08-30-2019, 10:18 PM
                          24 responses
                          938 views
                          0 likes
                          Last Post spwizard  
                          Started by Max238, Today, 01:28 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post Max238
                          by Max238
                           
                          Started by rocketman7, Today, 01:00 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post rocketman7  
                          Started by wzgy0920, 04-20-2024, 06:09 PM
                          2 responses
                          27 views
                          0 likes
                          Last Post wzgy0920  
                          Started by wzgy0920, 02-22-2024, 01:11 AM
                          5 responses
                          32 views
                          0 likes
                          Last Post wzgy0920  
                          Working...
                          X