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

How does NT know what to put in/out of DrawObjects or chartPanel.ChartObjects

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

    How does NT know what to put in/out of DrawObjects or chartPanel.ChartObjects

    I am developing a simple indicator that keeps track of the DrawingTools and Indicators on the chart for crossover detection and I have been struggling for a few days figuring out how to detect if a DrawingTool or ChartObject has been deleted (to remove it from my tracking of course). However, after trying out all the various approaches e.g. deleting an IChartObject will call OnRender (but all the objects get taken out and then reinserted back in!), watching ChartObjects.CollectionChanged etc. have been very unsatisfying and I have literally tried them all (with many posts over the years asking about a proper delete event in this forum).
    Then it occurred to me that NinjaTrader "knows" about what to put back into the Collection after it has taken all of them out (for whatever re-initialization purpose I guess) - this means that there is a "master collection" somewhere that NinjaTrader keeps track of. May I know where can I find this "master" collection? I am not asking for an event I can attach etc. I am just asking where does NinjaTrader keep track of the ChartObjects so that I can check it as and when needed to see if an object still exists in the chart.

    Thanks.

    #2
    Hello mav8rick,

    The chart knows what to put in the panel because that is part of its internal logic, this is not something that is simply a collection and is exposed to NinjaScript but is how the chart overall works with all of its included features and settings being used.

    The ChartObjects collection that you are using is the internal collection which you would have access to and is also the collection the chart is using to expose its objects, there is not a different master collection which contains other items that can be used.

    Generally if you are using these collections you would never store any kind of reference to anything in the collection as it may be temporary, you would instead always just iterate the current contents to do your task on those current items. For drawing objects you could store the objects Tag and then check if a object with that Tag still exists.




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

    Comment


      #3
      Hi Jesse, thanks for your quick reply. Hear me out a bit:
      1. I'm not a "newbie" to all the issues and what is mentioned in the Help Guide; I understand that - while unexpected - all the ChartObject instances are recreated multiple times during a session through some unexpected action e.g. adding another indicator to the chart, changing of properties etc. I have spent a couple of days reading every post I can get my hands on in this forum so I'm aware of the design direction NinjaTrader has taken
      2. There are 2 main "powers" that NinjaTrader fulfills - 1 for automated trading and 1 for semi-automated/discretionary and in this case, I'm talking about discretionary:
        • While the Condition Builder is powerful, you can understand that it requires quite a lot of to clicks to add some notification alerts for each chart. Imagine if I'm trying to trade 6-8 stocks based on 1-min (how to update the alerts quick enough to keep up with the current volatility?)
        • NinjaTrader assumes that everything important can be recreated as "calculations" BUT NinjaTrader also knows to persist the user-drawn objects since those CANNOT be recreated from "calculations" alone
        • My little indicator simplifies setting alerts for crossovers by just clicking on a line or indicator (drawn on the main panel) and pressing e.g. Ctrl-A (so much easier - 1 second job)
      3. When a user adds/removes another indicator - in my use case - that action does not indicate that the alerts should be removed but because of the way it is setup, my indicator - which is keeping track of the crossovers would be terminated but there isn't a proper mechanism to persist this (yeah, I read about the file etc.) but if you can persist user drawn objects, it's not unreasonable for me to expect to be able to tag some info on those objects so that I can get those back between all the Configure-Termination cycle right?
        • Arguably, this is a common usage scenario - a discretionary trader will use the higher timeframes to draw the lines (trend lines, channels etc.) and then switch down to a lower timeframe to trade and after some time, go back to a higher timeframe for "air" (redraw the lines but keep some of the alerts) and then go back to a lower timeframe to trade. However, imagine in all these, the user has to reset all the alerts (but for what? From a user's point of view, nothing has changed)
        • Arguably, unless the instrument has changed on the chart, all that I - as a user - am trying to express (the crossovers/alerts etc.) should not change (a crossover is a crossover whether on a 30-min or a 1-min chart)
      4. Depending on the current price action, as a trader, I may want to trade crossovers against system drawn plots (e.g. SMA) or against my own drawn lines/drawings - I need to express and persist this across the Configure-Termination cycle
      5. That brings me to the issue of tracking ChartObject deletes e.g. once a user removes a line, I need to know that so that I can remove that from my list of tracked items. However, ChartObjects changes in a way that makes that hard (remove and the re-add back but when is that list "confirmed" so that I can do my comparison? Even assuming that I use tag comparison?) - same thing with DrawObjects
        • I know instances of indicators and DrawingTools are being being Terminated and recreated constantly but NinjaTrader knows which one to "re-instantiate" and which ones not to (e.g. deleted) - I'm merely asking how can we get to this list? If there isn't such a list/collection then how does Ninja Trader know which ones to leave out?
      In summary, I'm asking about 2 things:
      1. There should be a reasonable way to keep track of what user "expressed" (set alerts/relations) in between Configure-Terminated cycles and obviously there's no way to "calculate" that from any series because that happened after the calculations are done
      2. I want to know when an object (indicator/DrawingTool) is deleted and will not be re-instantiated - there is no definitive event notifying when the chart is completely "rejigged" but NinjaTrader has to know and keep track of what's deleted and what's not; can we not know the same?
      Thank you for reading this long post. Hope you don't find my expectations unreasonable.

      Comment


        #4
        Hello mav8rick,

        because of the way it is setup, my indicator - which is keeping track of the crossovers would be terminated but there isn't a proper mechanism to persist this (yeah, I read about the file etc.) but if you can persist user drawn objects, it's not unreasonable for me to expect to be able to tag some info on those objects so that I can get those back between all the Configure-Termination cycle right?
        There is no existing system in place for saving user specified data on a chart object so yes this is not reasonable. You could implement your own system to save data if you need to do that but that is otherwise not a feature of NinjaScript by default. Serialization only happens for public properties so if what you are trying to persist is not designed and intended to be saved in the template/workspace it will not be persisted. The chart will otherwise make copies of the instances when recreating them to gather settings and defaults. Its not as simple as a collection of items, the chart does a lot of work to do reloads and prepare instances of objects for use.

        I'm merely asking how can we get to this list? If there isn't such a list/collection then how does Ninja Trader know which ones to leave out?
        This is part of how the chart works this is not just a list of items. When you do actions in the chart that causes different outcomes in the charts logic which in turn causes the collection to be updated or items to be refreshed etc. What is exposed for your NinjaScript to use is the ChartObjects collection which would be the list of items that gets built. That collection would be the only context which is expected for NinjaScript to be able to access or when the objects are actually able to be accessed.


        There should be a reasonable way to keep track of what user "expressed" (set alerts/relations) in between Configure-Terminated cycles and obviously there's no way to "calculate" that from any series because that happened after the calculations are done
        There is not really a system in place for that, it is generally expected that everything reloads when something changes. Your indicator in general is not expected to track other indicator or other items beyond its own states as it is applied to the chart as well. The chart doesn't care if your indicator is trying to observe other items, its going to work in one specific way which all the children need to follow. You can certainly program around those rules but that would require you to make up logic to do that.

        I want to know when an object (indicator/DrawingTool) is deleted and will not be re-instantiated - there is no definitive event notifying when the chart is completely "rejigged" but NinjaTrader has to know and keep track of what's deleted and what's not; can we not know the same?
        You would likely need to poll for those changes, as noted there is no existing event for that purpose. This would be a custom type of logic you would have to create to track that if your script needs to track something.

        Please let me know if I may be of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse,

          Thank you for reviewing my post. In closing this post, I would summarize my requests as such:
          1. NinjaTrader works BOTH for discretionary and automated systems traders. I am sure a lot of people believe in the platform for discretionary trading, all I'm asking is for the designers and architects to review that simple use case i.e. allow some kind of mechanism to persist some data even on the change of timeframes or addition/deletion of indicators (in this case, when a user is trying to do something on the same instrument across different timeframes and/or adding indicators but still maintaining that instrument)
          2. As for detecting deleted objects - I can accept the suggestion to poll if there is an efficient and reasonable way to do that but ChartObjects/DrawingTools is not usable because:
            1. The base removes and adds back to the collection NOT because there's any change to the indicator settings or even the instrument or even the timeframe and this occurs many times on an action. How do I know if the removal is to "refresh" or an actual removal? We see that the object is no longer in ChartObjects/DrawingTools but is it because it hasn't been added back to the collection as part of the refresh cycle or because it is truly deleted? How do we know?
            2. In addition to the above, we don't know when the adding/removal is "done". If there is an indication when that adding and removal due to e.g. a rejig of the timeframe, is done, we can then poll those lists (ChartObjects/DrawingTools) at an appropriate time to do our processing
            3. I have the imagination that maybe a little bit more information about the underlying problem/architecture would enable us to solve the problem on our own (e.g. for issue 1, I have developed my own hack); maybe a bit more info on what happens in a ChartObject/Indicator deletion cycle would help?

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bill2023, Yesterday, 08:51 AM
          8 responses
          43 views
          0 likes
          Last Post bill2023  
          Started by yertle, Today, 08:38 AM
          6 responses
          25 views
          0 likes
          Last Post ryjoga
          by ryjoga
           
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          24 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          16 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          46 views
          0 likes
          Last Post jeronymite  
          Working...
          X