Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OpenForm within Strategy

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

    OpenForm within Strategy

    Hello. I am trying to open a custom form from within a strategy.
    I can open the form as an addon module, then open it from the strategy but I am not show how to pass the check or form action from the addon form, back to the strategy that opened it.
    Can you help me with how that is done.

    If not my plan is to add the Form class for NT window to the Strategy itself, however that crashes when I attempt to open the form. So I guess I am missing something.
    a solution for either approach is welcomed.

    Thanks.


    This is the class extract from the addon-

    public class TradeMenu : NTWindow
    {
    private Button cancelButton;
    private InstrumentSelector instrumentSelectorInput;
    private Instrument instrumentValue;
    private Button okButton;
    private QuantityUpDown quantityUpDownInput;
    public TextBox SymF;
    public TextBox DateF;
    public TextBox HighF;
    public TextBox LowF;
    public CheckBox VwapZ;


    public Strategies.SwingScalpNQv6 TargetIndicator;
    public int ZoneType=0; // 0 means daily, 1 means Weekly;

    public TradeMenu()
    {
    Caption = "TradeManagement";
    Width = 400;
    Height = 250;
    Height = 10050;
    Loaded += OnWindow_Loaded;
    Closing += OnWindow_Close;
    }

    private void OnWindow_Loaded(object sender, RoutedEventArgs e)
    {
    Content = LoadXaml();
    }

    private void OnWindow_Close(object sender, System.ComponentModel.CancelEventArgs e)
    {
    if (cancelButton != null)
    cancelButton.Click -= OnCancelButton_Click;

    if (instrumentSelectorInput != null)
    instrumentSelectorInput.InstrumentChanged -= OnInstrument_Changed;

    if (okButton != null)
    okButton.Click -= OnOkButton_Click;
    }

    private DependencyObject LoadXaml()
    {
    Page page = new Page();

    FileStream fs = new FileStream(System.IO.Path.Combine(NinjaTrader.Core .Globals.UserDataDir, @"bin\Custom\AddOns\TradeMenu.xaml"), FileMode.Open);

    page = (Page)XamlReader.Load(fs);

    if (page == null)
    return null;

    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;
    SymF = LogicalTreeHelper.FindLogicalNode(page, "SymF") as TextBox;
    HighF = LogicalTreeHelper.FindLogicalNode(page, "HighF") as TextBox;
    LowF = LogicalTreeHelper.FindLogicalNode(page, "LowF") as TextBox;
    DateF = LogicalTreeHelper.FindLogicalNode(page, "DateF") as TextBox;
    VwapZ = LogicalTreeHelper.FindLogicalNode(page, "VwapZ") as CheckBox;

    DependencyObject pageContent = page.Content as DependencyObject;

    return pageContent;
    }

    private void OnCancelButton_Click(object sender, RoutedEventArgs e)
    {
    this.Close();
    }

    private void OnInstrument_Changed(object sender, EventArgs e)
    {
    instrumentValue = sender as Cbi.Instrument;
    }

    private void OnOkButton_Click(object sender, RoutedEventArgs e)
    {// Save File




    if (ZoneType==0)
    {
    if (TargetIndicator == null)
    return;

    // if (instrumentValue != null)
    // TargetIndicator.InstrumentValue = instrumentValue;

    // if (quantityUpDownInput != null)
    // TargetIndicator.IntValue = quantityUpDownInput.Value;

    // if (SymF != null)
    // TargetIndicator.StringValue = SymF.Text;

    //TargetIndicator.ShowValues();
    }





    this.Close();
    }
    }

    #2
    OK. I figured a way to do it using the addon SetIndicatorValueFromAddonWindowExampleTools example that was provided early. Would prefer to have the form load directly from the strategies in case I wanted to have multiple strategies without having to reference them in the addon. as in the example. However it works for now.

    Comment


      #3
      Hello richa61416,

      Below is a link to an example of opening a new WPF window (not WinForms) from a button click, and then returning information to the originating class object.


      You can use partial class if you need a set class name.
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      61 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      39 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      21 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      23 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      51 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X