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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        600 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        347 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        558 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        558 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X