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

Plotting an indicator data series which is asynchronous to Price

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

    Plotting an indicator data series which is asynchronous to Price

    Hello,
    I hope I can describe what I am trying to accomplish with a simple example!
    Typically if one writes a custom indicator, it gets plotted on a price chart and its data series values are updated on an OnBarUpdate() callback. Suppose, just for example, instead of being updated on the OnBarUpdate(), I have a Timer running and on the Timer event callback, I do a Set() on the indicator's data series? Is this a valid thing to do? And if so, for example if markets are closed and no price bars are getting ticks, would my indicator even plot at all during these off hours? Not that I'd want it to, I just want to learn if I can update the indicator data series outside of and asynchronous to OnBarUpdate() calls i.e. asynchronous to price.
    Thanks in advance for any advise and info!

    #2
    Hi BigRunningBack, thanks for your note.

    The Values[][] array is tied directly to the bar update logic and how NinjaTrader builds charts. There is an index in that array for every bar on the chart. A timer would not be needed because any time based chart with an OnBarUpdate script will trigger every x periods, like a 4 minute chart, daily chart, etc.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,

      Thank you for your reply!

      I realize a timer is not necessary. It was a test to see if I can have any external source update an indicator, rather than the price bars in the chart.
      So back to my example of using a timer event to update my indicator plot, is this even possible? Or does an indicator absolutely MUST be driven off price or else it will not ever plot?

      That's exactly what I need to do. For now I am running a timer which generates values that I put into my indicator's data series array but I am not seeing anything getting plotted.

      Thank you for your help!

      Comment


        #4
        Hello BigRunningBack,

        We would suggest setting class level variables and to call Set() in OnBarUpdate to assign the plot with the value of this variable. You could update plot values outside of OnBarUpdate, but it will be important to set plot values so they are synchronized with each update to the indicator's primary data series. This would ensure reliable functionality when accessing the indicator programmatically from another indicator or strategy.

        Please let us know if we can be of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim,
          Thanks you for your reply. I've done a little experimenting, and this is what I am seeing so far...
          Yes, I am calling Set() on my dataseries everytime my Timer ticks ( 1 second interval), not in OnBarUpdate. Of course it is setting the values in the series, but the ONLY time I see the value plot is when a price tic comes in i.e. OnBarUpdate gets called from Ninja. Is there something I can do to force the indicator drawing update instead of it being dependent on a OnBarUpdate happening?
          Thanks for helping me get this to work!

          Comment


            #6
            Hello BigRunningBack,

            The plot will be synchronized to the primary data series. In the example attached when applied to a 30 second chart, we can see that the plot will be updated visually when Set is called from the timer. However, we would recommend setting a class level variable and then to set the plot with the new value in OnBarUpdate. (This ensures that when the indicator is referenced the plot value is up to date with the value it has been assigned and also ensures that a consistent line is drawn. I.E. If we get multiple new bars before the timer ticks, we will want to ensure that the plot has values assigned for each bar before the timer ticks to give a new value.)

            Please let me know if I can be of further assistance.
            Attached Files
            JimNinjaTrader Customer Service

            Comment


              #7
              Thank you Jim this should help!

              Comment


                #8
                Hello,

                Sorry to beat on this topic again!

                What if I want or need my indicator plot to NOT be synchronized to the primary data series? e.g. let's say my price data for my hypothetical instrument gets updated 1 tic every 30 seconds. But my custom indicator, which is not driven by the price data series, updates once every second? So my indicator updates 30 times for every price series update. And there could very well be very important data in there that wouldn't get plotted in the indicator window until the price updates!

                So, my questions are: 1. is there a way to have the indicator window plot async to and independent of the price window? and 2. is there somewhere else/another place I can draw anywhere in the NinjaTrader workspace that does NOT depend on synchronization with the price series? There by allowing me to draw and not wait for price tic updates?

                Hoping there is a way to do this!
                Thanks!

                Comment


                  #9
                  Originally posted by BigRunningBack View Post
                  Hello,

                  Sorry to beat on this topic again!

                  What if I want or need my indicator plot to NOT be synchronized to the primary data series? e.g. let's say my price data for my hypothetical instrument gets updated 1 tic every 30 seconds. But my custom indicator, which is not driven by the price data series, updates once every second? So my indicator updates 30 times for every price series update. And there could very well be very important data in there that wouldn't get plotted in the indicator window until the price updates!

                  So, my questions are: 1. is there a way to have the indicator window plot async to and independent of the price window? and 2. is there somewhere else/another place I can draw anywhere in the NinjaTrader workspace that does NOT depend on synchronization with the price series? There by allowing me to draw and not wait for price tic updates?

                  Hoping there is a way to do this!
                  Thanks!
                  ForceRefresh() whenever you update the plot holder value?

                  Comment


                    #10
                    Hello BigRunningBack,

                    Plots themselves will be synchronized to the primary data series of the script and there would not be a way to have the plots decoupled from this data series.

                    Drawing tools will place drawings on the chart whenever the Draw method is called, so this could be considered to draw on the chart without necessarily modifying the plot value.

                    Custom drawing can also be done on the chart if you need a more customized way to present information on the chart.

                    OnBarUpdate is event driven, and will not update if there is no data for the method to process. If you need to have actions taken every second, a timer can be added to have events fire every second. This timer can then be used to check your indicator's properties and call a Draw method, or to update variables that would then be used for your custom drawings in the Plot override. Overriding the Plot method is not supported, but you could reference the CustomPlotSample indicator and other indicators that use this override like the Pivots indicator for further direction.

                    Drawing methods - https://ninjatrader.com/support/help...t7/drawing.htm

                    Example that implements a timer - https://ninjatrader.com/support/help...to_output_.htm

                    We look forward to being of further assistance.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      Thank you everyone for your help!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Mindset, 05-06-2023, 09:03 PM
                      10 responses
                      262 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by michi08, 10-05-2018, 09:31 AM
                      5 responses
                      741 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by The_Sec, Today, 02:29 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post The_Sec
                      by The_Sec
                       
                      Started by tsantospinto, 04-12-2024, 07:04 PM
                      4 responses
                      62 views
                      0 likes
                      Last Post aligator  
                      Started by sightcareclickhere, Today, 01:55 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post sightcareclickhere  
                      Working...
                      X