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

Pass Variable from Indicator To Addon

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

    Pass Variable from Indicator To Addon

    I was working off the example SetIndicatorValueFromAddonWindowExample found at http://ninjatrader.com/support/forum...059#post477059.

    There is a string StringValue in the indicator. How can I pass that to the Addon so that it show up in the TextBox StringValueInput. I want to be able to do something like

    (LogicalTreeHelper.FindLogicalNode(page, "StringValueInput") as TextBox).Text = StringValue;

    Thanks.

    #2
    Hello TAJTrades,

    The example sets a property in the class of an indicator called TargetIndicator. This property is set to the instance of the indicator so information can be passed back.

    You could access any public property of your indicator this way (the way I'm setting the same values).
    Code:
    stringValueInput		= LogicalTreeHelper.FindLogicalNode(page, "StringValueInput") as TextBox;
    
    if (stringValueInput != null)
    stringValueInput.Text = TargetIndicator.StringValue;
    Or if you wanted, you could pass information in through the constructor.

    Initialize new objects with constructors. Use the new keyword and overloads.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Maybe I am still missing something. I tried your suggestion using the code changes below. I thought I would try to Print it first and the code failed. Could you try adding the OutPut.Process on your end as the problem may be with my Install or I am still not doing something correctly.

      I made 1 change to the Indicator file by changing the StringValue to "From Indicator Text". And in the Addons file I attempted four versions of OutPut.Process.
      Thanks for your help on this.



      Code:
      Indicator Sript:
      //  Changed StringValue to "From Indicator Text"
      
      if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Indicator here.";
                      Name                                        = "SetIndicatorValueFromAddonWindowExample";
                      Calculate                                    = Calculate.OnBarClose;
                      IsOverlay                                    = true;
                      DisplayInDataBox                            = false;
                      //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                      //See Help Guide for additional information.
                      IsSuspendedWhileInactive                    = true;
      
                      InstrumentValue                                = Instrument.GetInstrument("AAPL");
                      IntValue                                    = 0;
      
                      //StringValue                                    = string.Empty;
                      //  CHANED TO:
                      StringValue                                    = "From Indicator Text";
                  }
      
      
      Addon Script:
      //    Printed "page Not Null"  so I know the OutPut.Process works.
      //    All four attempts at printing TargetIndicator.StringValue Failed.  
      //    Nothing shows on OutPut Window and the Window fails to open.
      
      
              private DependencyObject LoadXaml()
              {
                  Page page = new Page();
                  FileStream fs = new FileStream(System.IO.Path.Combine(NinjaTrader.Core.Globals.UserDataDir, @"bin\Custom\AddOns\SetIndicatorValueFromAddonWindowExampleToolsContent.xaml"), FileMode.Open);
                  page = (Page)XamlReader.Load(fs);
      
                  if (page == null)
                      return null;
                  
      string pageStatus = "page Not Null";            
      NinjaTrader.Code.Output.Process(pageStatus, PrintTo.OutputTab1);
      
      //  The above printed to the OutPutTab1.  So printing to the OutPutTab1 is not the issue
                  
      //NinjaTrader.Code.Output.Process(TargetIndicator.StringValue , PrintTo.OutputTab1);
      //NinjaTrader.Code.Output.Process(TargetIndicator.StringValue as string, PrintTo.OutputTab1);
      //NinjaTrader.Code.Output.Process((string)TargetIndicator.StringValue , PrintTo.OutputTab1);
      //NinjaTrader.Code.Output.Process(TargetIndicator.StringValue.ToString() , PrintTo.OutputTab1);
                  
      //  All 4 of the above attempts to print TargetIndicator.StringValue failed            
                  
                  cancelButton = LogicalTreeHelper.FindLogicalNode(page, "CancelButton") as Button;
                  if (cancelButton != null)
                      cancelButton.Click += OnCancelButton_Click;
      
                  okButton = LogicalTreeHelper.FindLogicalNode(page, "OkButton") as Button;
                  if (okButton != null)
                      okButton.Click += OnOkButton_Click;
      
                  instrumentSelectorInput = LogicalTreeHelper.FindLogicalNode(page, "InstrumentSelectorInput") as InstrumentSelector;
                  if (instrumentSelectorInput != null)
                      instrumentSelectorInput.InstrumentChanged += OnInstrument_Changed;
      
                  quantityUpDownInput    = LogicalTreeHelper.FindLogicalNode(page, "QuantityUpDownInput") as QuantityUpDown;
                  stringValueInput    = LogicalTreeHelper.FindLogicalNode(page, "StringValueInput") as TextBox;
                  
                  
                  DependencyObject pageContent = page.Content as DependencyObject;
                  return pageContent;
              }

      Comment


        #4
        Hi TAJTrades,

        Ah, its an order of operations issue.

        Instead of loading the xaml when the constructor triggers (which the TargetIndicator hasn't been set by this time), load the xaml after the window has loaded (by adding an event handler to Loaded).

        I've updated my original post with these changes.

        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          ChelseaB,

          Bingo. Thanks much. I was thinking it was a casting issue and had started down that path. Did not think about it being a process issue. It now works exactly as I need. Now I will create my own reference sample for all the major wpf controls (DatePicker, Color Picker, TextBox, ComboBox, CheckBox, RadioButton and some type of GridView). Could not have gotten out of the box without you, Thanks again.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by funk10101, Today, 12:02 AM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by GLFX005, Today, 03:23 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by nandhumca, Yesterday, 03:41 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by The_Sec, Yesterday, 03:37 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by vecnopus, Today, 06:15 AM
          0 responses
          1 view
          0 likes
          Last Post vecnopus  
          Working...
          X