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

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

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

    #16
    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.Show();
    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(() =>
    {

    win.MyCustomMethodName(StringValue);
    }));​
    Last edited by NinjaTrader_Jesse; 02-07-2023, 01:49 PM.
    JesseNinjaTrader Customer Service

    Comment


      #17
      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:
      Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
      Last edited by rafaelcoisa; 02-07-2023, 03:14 PM.

      Comment


        #18
        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:

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

        Comment


          #19
          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" (https://ninjatrader.com/support/foru...egy#post774548), 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:
          Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.


          * Indicator script:
          Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.






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

          Comment


            #20
            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.

            Hello, How can I loop through all open windows and dosomething on each window. I thought about a foreach within a dispatcher but I do not know how to access the list of open windows. I've put the foreach attempt below. foreach(Ninjatrader.Gui.Chart.Chart win in XXXXX) { win.Activate(); //do something } I've tried "in






            JesseNinjaTrader Customer Service

            Comment


              #21
              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?​

              Comment


                #22
                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

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by DJ888, 04-16-2024, 06:09 PM
                4 responses
                11 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by terofs, Today, 04:18 PM
                0 responses
                5 views
                0 likes
                Last Post terofs
                by terofs
                 
                Started by nandhumca, Today, 03:41 PM
                0 responses
                5 views
                0 likes
                Last Post nandhumca  
                Started by The_Sec, Today, 03:37 PM
                0 responses
                3 views
                0 likes
                Last Post The_Sec
                by The_Sec
                 
                Started by GwFutures1988, Today, 02:48 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Working...
                X