Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't access to ChartControl inside DrawingTool

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

    Can't access to ChartControl inside DrawingTool

    I'm trying to access to ChartControl inside a DrawingTool, but it's not found.

    I want inside if (State == State.Terminated) to make something like this, when the DrawingTool is deleted:

    Code:
    ChartControl e = ChartPanel.ChartControl;
    
    if (e != null)
    {
    e.Dispatcher.Invoke((Action)(() =>
    {
    Window chartWindow = Window.GetWindow(e.Parent);
    
    quantitySelector = chartWindow.FindFirst("ChartTraderControlQuantityS elector") as QuantityUpDown;
    if (quantitySelector != null)
    {
    quantitySelector.Value = 1;
    }
    }));
    }
    Output shows null pointer error.​ (Error on calling 'OnStateChange' method: System.NullReferenceException: Object reference not set to an instance of an object.)​
    Last edited by franjcy; 03-19-2024, 12:59 PM.

    #2
    Hello franjcy,

    You will need to use the chartControl property from the OnRender() method, which you could assign to a variable if you want to use this elsewhere in the script.
    Be sure to check the variable is not null before using in other methods.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello franjcy,

      You will need to use the chartControl property from the OnRender() method, which you could assign to a variable if you want to use this elsewhere in the script.
      Be sure to check the variable is not null before using in other methods.
      https://ninjatrader.com/support/help...8/onrender.htm
      Perfect, it works like a charm. I created a globlal script variable assigned inside OnRender and then used inside (State == State.Terminated) and it works fine.

      Comment


        #4
        Worked for me, too! Thanks for sharing it and saving me time in looking for a solution.​

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        85 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        143 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        83 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        256 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        334 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X