Announcement

Collapse
No announcement yet.

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
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    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​
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        560 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        325 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X