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

Subscribe to Chart OnRender event from within Add-On

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

    Subscribe to Chart OnRender event from within Add-On

    Hello,

    I'm designing an Add-On to customize the native Chart Window which needs to render custom WPF objects to the chart and update their coordinates during the chart's OnRender event. Can you kindly let me know if 1) This is achievable through the add-on framework? and 2) Can you point me to any examples using a similar method?

    Thank you in advance for your time.


    #2
    Hello CDXTrader,

    It is certainly possible to append items to a chart from an addon however accessing the charts OnRender from that context is not something I could provide any suggestions for. If you develop this as an indicator or script which applies directly to the chart which also naively has OnRender you could certainly use OnRender for other purposes.

    An alternative suggestion would be to avoid using OnRender and instead do something similar to what the DrawingToolTiles indicator does.

    The Indicator DrawingToolTile (included in NT8) makes use of the UserControlCollection along with the mouse events of the chart to control the window instead of using rendering. Depending on what you are trying to use to position the objects you may be able to utilize one of the other events of the chart control. If you can provide some detail on the overall goal and why OnRender would be needed that would help me point a direction better.




    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 12-06-2019, 10:48 AM.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      Thank you for the response. What I'm needing to do is place WPF controls (a grid for example) at order prices on a chart and then have those controls remain at the correct price whenever the chart is moved by any means (scrollbar, autoscale, etc.) I'm having difficulty figuring out how to do that without the OnRender event. This project requires an add-on because it will need to continue tracking price data outside of any chart or other app window.

      Adding, removing and moving the WPF objects on the chart seems to work ok. I accomplish that in a similar fashion as the DrawingToolTile as you mentioned. Is there another 'chart move' event that maybe I'm missing that would help me make this happen?

      Thank you.

      Comment


        #4
        Hello CDXTrader,

        Yes from an addon that is not really a use case it would be advised for as you are dealing with the charts events and rendering. Any updates your logic requires would be custom, you could try subscribing to the various events of the ChartControl however from the addons perspective it is not associated with a specific chart to receive specific OnRender updates.

        This project requires an add-on because it will need to continue tracking price data outside of any chart or other app window.
        You can use a lot of the addon code from an indicator, if OnRender is required I would suggest trying to migrate the code into an indicator so it can directly use its override.

        Adding, removing and moving the WPF objects on the chart seems to work ok. I accomplish that in a similar fashion as the DrawingToolTile as you mentioned. Is there another 'chart move' event that maybe I'm missing that would help me make this happen?
        Not specifically for NinjaScript no, you could look at the standard WPF events surrounding the mouse and keyboard to capture dragging or movement. As noted an addon is not expected to deal with rendering or accessing rendering so there are not really any specific events associated with notifying your addon of rendering changes from other areas like a chart.



        I look forward to being of further assistance.



        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks for the explanation, Jesse.
          That gives me a better understanding of what I'm dealing with between the Add-On and Indicator frameworks.

          Comment


            #6
            Hi Jesse,

            I have a followup question for you on this topic.
            I was able to successfully refresh my custom UIElements on the Chart Control through the various mouse and window events. All seems to work great except for the couple of use cases where I add or refresh the coordinates of the UIElements but the Chart Control has no reason to repaint (ie. no render events firing). As soon as the Chart render event fires (such as manually moving the chart) the UIElements are visible again. The specific case I'm trying to resolve is after changing chart instruments. My objects are not visible after the instrument change unless I trigger a re-paint manually (such as moving the chart) or wait until all PrimaryBars data is loaded.

            I realize it's likely not supported or documented but Is there any means of forcing the Chart Control to re-paint itself from an Add-On? I've tried UpdateLayout() and InvalidateVisual() but those don't seem to actually trigger the rendering. A secondary option I could make work is knowing when the PrimaryBars data is loaded. Is there any event or property I can use to check for that?

            Thanks for your time.

            Comment


              #7
              Hello CDXTrader,

              The only way I am aware of that can truly force the chart to render is to add a drawing object and then immediately remove it. Removing an object calls the render loop however I wouldn't have a suggestion on how to do that from an Addon. If what you are doing is within an Indicator you could call its draw /remove methods to do that.

              There are no data loading events that I am aware of for the chart control or window. The chart really doesn't expose its data in that way for addons to observe, the chart works more like a chain with its UI properties delegating values to sub objects. It only exposes very little as public.

              How are you using the primary bar data in this situation? It sounds like it would work so long as the primary bar data was populated. Are you saying thats not working because what you do runs once and that is before the data was populated?

              I look forward to being of further assistance.









              JesseNinjaTrader Customer Service

              Comment


                #8
                Hi Jesse. I'm actually working on this project with CDXTrader.

                What we're seeing is that we'll add our drawing object to ChartControl.Children before the chart finishes it's rendering process. For example, when the instrument (or interval) is changed by the user with the instrument selector, the "Instrument Changed" event fires. If we re-drawn our controls during this period, it's too soon in the sequence of events and the chart ends up either refreshing the Children collection without our control OR doesn't properly repaint our control.

                What we really need is a way to know that the chart has finished its reload cycle and is ready for interaction. In the instrument change example above, we've solved this by setting a timer to add our control 1 second after the event is fired. However, this is a hack of sorts and won't work in other places where we're seeing this situation.

                As far as primary bar data, we were trying to find an event or trigger that might let us know that the chart bars have been refreshed and repainted, so it's okay to add our controls.

                Thoughts?

                Comment


                  #9
                  Hello MarkWise ,

                  There is nothing I could really suggest for that type of use case, the chart is not really designed in a way to allow addons to access its life cycle or other data. The chart its self has events for loading data which then triggers other events for its children but that system is not exposed as something your script could attach to or monitor.

                  You may need to use another timer and poll for changes in your code if you have some ability to detect changes for what you are watching. I am not aware of anything you could check from this context so you would likely need to experiment there if that is to be used.

                  Another possibility would be to add a indicator to the chart and watch for it to be done loading, however not everything loads at the same speed on a chart so that may not work if other items are loading slowly and you needed any of that data.

                  I believe the core problem here is that the chart is not really designed in a way to be monitored from an addon so there are not any specfific methods you can subscribe to for the data related events. If you are adding or removing items from outside of its general events/context it won't have any need to update or know you made changes so anything out of the charts scope will be totally custom for your addon.

                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by junkone, Today, 11:37 AM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by frankthearm, Yesterday, 09:08 AM
                  11 responses
                  42 views
                  0 likes
                  Last Post frankthearm  
                  Started by quantismo, 04-17-2024, 05:13 PM
                  5 responses
                  35 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by proptrade13, Today, 11:06 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by love2code2trade, 04-17-2024, 01:45 PM
                  4 responses
                  35 views
                  0 likes
                  Last Post love2code2trade  
                  Working...
                  X