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 Aviram Y, Today, 05:29 AM
      4 responses
      11 views
      0 likes
      Last Post Aviram Y  
      Started by algospoke, 04-17-2024, 06:40 PM
      3 responses
      27 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by bmartz, 03-12-2024, 06:12 AM
      3 responses
      30 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Started by gentlebenthebear, Today, 01:30 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by cls71, Today, 04:45 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X