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

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 futtrader, 04-21-2024, 01:50 AM
        4 responses
        41 views
        0 likes
        Last Post futtrader  
        Started by Option Whisperer, Today, 09:55 AM
        1 response
        11 views
        0 likes
        Last Post bltdavid  
        Started by port119, Today, 02:43 PM
        0 responses
        1 view
        0 likes
        Last Post port119
        by port119
         
        Started by Philippe56140, Today, 02:35 PM
        0 responses
        3 views
        0 likes
        Last Post Philippe56140  
        Started by 00nevest, Today, 02:27 PM
        0 responses
        2 views
        0 likes
        Last Post 00nevest  
        Working...
        X