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

Does an event fire when a chart's time or price scales are expanded or compressed?

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

    Does an event fire when a chart's time or price scales are expanded or compressed?

    I am using an indicator to overlay a set of moving averages and text on a chart. When that indicator is used I want to be able to reposition the text vertically or horizontally when the price scale on the side, or the time scale at the bottom, are changed using the mouse. I am trying to find which event is fired when either of those two mouse moves happen. OnRender fires almost constantly when the market is active and I can use ChartControl and ChartScale from there to get SlotsPainted and MaxMinusMin to make text positioning adjustments.

    But due to resource use intensity, if I don't have to use OnRender, I would prefer not to. I could check for changes (SlotsPainted and MaxMinusMin) each time OnBarUpdate fires. But if there is an event that fires when the mouse is used to expand or compress the two scales, that would be much less resource intensive. I tried using Drawing Tools events: OnBarsChanged, and OnMouseMove, but those are not available within my indicator context. Maybe there is a workaround way for me to use those, idk. I tried all the State change events, but none of those fire when I change the two scales with the mouse. I will piggyback OnBarUpdate if necessary, but that's such a big waste if there is an event that fires only when the mouse is used in the circumstance described.
    Last edited by c2injacator; 07-21-2023, 08:37 PM.

    #2
    Hello c2injacator,

    Thanks for your post.

    There is no supported event method available for detecting when the price scale or time scale is changed.

    This would require using ChartControl and ChartScale in OnRender() as you have noted.

    See the help guide documentation below for more information about ChartControl, ChartScale, and OnRender().

    ChartControl: https://ninjatrader.com/support/help...artcontrol.htm

    ChartScale: https://ninjatrader.com/support/help...chartscale.htm

    OnRender(): https://ninjatrader.com/support/help...8/onrender.htm
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      I tried adding this code just above the OnBarUpdate method in the indicator that I'm using to create the overlay:

      }​
      public event PropertyChangedEventHandler PropertyChanged;
      private void OnPropertyRaised(string propertyname)
      {
      if (PropertyChanged != null)
      {
      PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
      Print("propertyname: " + propertyname);
      if (propertyname == "SlotsPainted")
      {
      Print("SlotsPainted");
      }
      }
      }​
      The code compiles, but it does not respond to any property changes. I think INotifyPropertyChanged​ may already be implemented as part of the Indicators namespace, but maybe that code is not directly available to users, idk.

      I'm thinking a C# expert on the NinjaTrader team, like you or someone who writes the software would know what I would need to add to the code above to make it properly respond when properties are changed.

      Testing a set of properties that only change occasionally in a method like OnBarUpdate, or OnRender is massive overkill, esp when there are several indicators that need actual updating in real time (Calculate.OnPriceChange). So I'm already pushing resources to the limit and have to keep a close eye on the growing exe size. I have partially solved that issue by limiting the number of charts to 2, and the number of bars loaded to 2000 in the Data Series.​

      Comment


        #4
        Hello c2injacator,

        Thanks for your notes.

        INotifiyPropertyChanged is a way to raise events in MVVM and wouldn't be used in NS, which has no meaning to the chart since it is not listening to property change events. The event you need to use is OnRender(). OnRender() gets called when you manually manipulate the chart in addition to many other reasons.

        Note that you should be looping over the visible bars and only calculating for that range of the chart.

        If you are doing something in OnRender() and its making the chart lag, you might need to add IsInHitTest to avoid recalculating while the chart is being clicked and manipulated.

        IsInHitTest: https://ninjatrader.com/support/help...ghtsub=hittest

        OnRender(): https://ninjatrader.com/support/help...nrender​
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Balage0922, Today, 07:38 AM
        0 responses
        5 views
        0 likes
        Last Post Balage0922  
        Started by JoMoon2024, Today, 06:56 AM
        0 responses
        6 views
        0 likes
        Last Post JoMoon2024  
        Started by Haiasi, 04-25-2024, 06:53 PM
        2 responses
        19 views
        0 likes
        Last Post Massinisa  
        Started by Creamers, Today, 05:32 AM
        0 responses
        6 views
        0 likes
        Last Post Creamers  
        Started by Segwin, 05-07-2018, 02:15 PM
        12 responses
        1,786 views
        0 likes
        Last Post Leafcutter  
        Working...
        X