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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        43 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        20 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        30 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        47 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        38 views
        0 likes
        Last Post CarlTrading  
        Working...
        X