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


About a 2015 sample (indicator/strategy opens window) by NinjaTrader_ChelseaB

  • Filter
  • Time
  • Show
Clear All
new posts

    Hello rafaelcoisa,

    Please see post 6 for an example of sending data to the window from the indicator. We already went over that, you would pass any value using a custom method. You would save a variable to your window as a private variable, any time you need to pass something to the window you would use that variable and methods inside the window class.

    To be more specific this is the example that I am referring to:

    Win myWindow = new WPFwindow.Win();
    myWindow.MyCustomMethodName(this, "StringValue");​

    In the sample you linked in post 7 it appears you were trying to use a property named "StringValue" but when you called the method you just passed "aaa", if you wanted to pass a property from the indciator it would be win.MyCustomMethodName(StringValue);. You don't need any of the OnPropertyChanged code because that won't work in the window anyway, you just need to pass a value. The method inside the window would then set whatever control StringValue should apply to:

    public void MyCustomMethodName(string value)
    displayText.Text = value;

    The reason that didnt work is that you are setting it before the window is loaded. You need to set the value later, calling the method right after showing the window only aligns with what you originally were trying to do which was pass the instance of the indicator to the window (this). That would be fine because you are not updating the UI, your saving an instance into the class. If you wanted to update a variable on the UI you could do that from OnBarUpdate as an example.

    win.Dispatcher.InvokeAsync(new Action(() =>

    Last edited by NinjaTrader_Jesse; 02-07-2023, 01:49 PM.
    JesseNinjaTrader Customer Service


      Hey NinjaTrader_Jesse,

      I followed your suggestion, but this error occurred:

      Indicator 'CallWindicator0': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.

      The updated code with the suggested modifications:
      Last edited by rafaelcoisa; 02-07-2023, 03:14 PM.


        Hello rafaelcoisa,

        That means something was null. You would have to figure out which object you used is null.

        I am going to take a guess based on what I see in that file. You use a button to open the window so I am assuming that the code in OnBarUpdate needs a null check so that code is not called while your window is not open.

        As you are using objects you need null checks, for example:

        if(win != null)
            // do something with the win variable, its not null now
        JesseNinjaTrader Customer Service


          Hey NinjaTrader_Jesse,

          I think I confirmed my theory about the impossibility of communication between the custom window and the indicator after restoring the workspace.

          In the sample indicator "SetIndicatorValueFromAddonWindowExample" (, implement "IWorkspacePersistence" and comment out the line " this.Close(); " in the "OnOkButton_Click" event.

          Then open a window. Close NinjaTrader, save the workspace and reopen it.

          The custom window and the chart will be restored, but the OK button will not send any information to the chart.

          NinjaTrader_ChelseaB did not implement this interface in the sample because it is impossible to restore a custom window and use its functionalities because the custom window instance has no way to reference the indicator instance.

          Am I right NinjaTrader_ChelseaB?

          sample indicator "SetIndicatorValueFromAddonWindowExample" with "IWorkspacePersistence" implemented:
          * AddOn script:

          * Indicator script:

          Last edited by rafaelcoisa; 02-07-2023, 06:22 PM.


            Hello rafaelcoisa,

            The sample you linked to is not a good way to implement what you are trying to do, your post 7 was closer. Your indicator needs to create the window and pass any data needed to it. If you want to support a use case where the window was already open before the indicator can create it you would need to use the indicator to find your window instead of clicking a button to open it and then pass the data.

            Your goal is going be to very complex due to the requirements so there is not going to be 1 sample that encompasses everything you are asking. You will need to make your own custom logic to account for all use cases that you want your window to work in. The fundamentals of how to pass data to the window and update it, how to save and load it have already been provided here so you can proceed from that point to accommodate any other situations it needs to work in.

            To find an open window you can loop through the windows collection, that would be if you are trying to know if the window needs to be created or if it was already loaded. You would have to implement your own way to uniquely identify each window and which indicator it corresponds to, as mentioned your request is complex so you are going to be doing a lot of custom coding here.


            JesseNinjaTrader Customer Service


              Hey NinjaTrader_Jesse,

              I'm thinking about a tangential solution to my problem:
              saving and restoring the custom window's location during its open window and close window events.
              I know how to get the <Topmost> value. But, how can I get the <Location> value of the window?​


                Hello rafaelcoisa,

                You can research properties for a WPF window in external C# documents, an NT window is under the hood just a normal WPF window. I wouldn't be able to provide any help regarding using the open/close events to save or load as there is already a mechanism for saving which is the IWorkspacePersistence interface.
                JesseNinjaTrader Customer Service


                Latest Posts


                Topics Statistics Last Post
                Started by Net_Trader, 03-15-2023, 03:17 PM
                16 responses
                Last Post Net_Trader  
                Started by Vern10, Today, 10:51 AM
                4 responses
                Last Post Vern10
                by Vern10
                Started by HalTech, Today, 02:11 PM
                2 responses
                Last Post HalTech
                by HalTech
                Started by Gianpiero, Today, 01:41 PM
                1 response
                Last Post NinjaTrader_Ray  
                Started by josh18955, Today, 11:16 AM
                1 response
                Last Post Leeroy_Jenkins