• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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.

    https://www.dotnetperls.com/constructor
    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.

        http://ninjatrader.com/support/forum...686#post492686
        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 DariusDeck, Yesterday, 04:22 PM
          4 responses
          33 views
          0 likes
          Last Post DariusDeck  
          Started by StevenNelson, Today, 05:49 AM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_PatrickG  
          Started by fx.practic, Today, 01:41 AM
          0 responses
          12 views
          0 likes
          Last Post fx.practic  
          Started by wolfcuring, Today, 01:29 AM
          0 responses
          4 views
          0 likes
          Last Post wolfcuring  
          Started by BrandonT1292, 06-17-2019, 03:03 PM
          2 responses
          31 views
          0 likes
          Last Post thinarthrill  
          Working...
          X