Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How I solved a Quantity Text Box Problem

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

    How I solved a Quantity Text Box Problem

    I have a strategy I've been working on for quite some time. It replaces most of the ChartTrader right-margin controls. In it I can set stop and target quantities and have buttons for different kinds of trades. But I wanted to be able to still use the right-click on the chart options to also place trades. But the problem was when I change quantities in my strategy this do not change the default ChartTrader strategy. So I got access to the Quantity TextBox and changed the .Text amount. This did change the amount in the text box, but not on the right click menu. This is documented by Microsoft, changing a text box value programmatically does not trigger a TextChanged event. There has to be an actual key event.

    So I tried different ways and nothing worked. Finally I tried a SendWait to send an ENTER key, and it worked. Here is the code. Note that since I've hidden the ChartTrader control grid in which the text box resides, I had to unhide it for the moment, because if the text box is hidden it can't gain focus.

    ChartControl.Dispatcher.InvokeAsync((() =>
    {
    AccountSelector acctsel = (Window.GetWindow(ChartControl.Parent) as Chart).FindFirst("ChartTraderControlAccountSelecto r") as AccountSelector;
    acctsel.SelectedAccount = Account.All.First(a => a.Name == Account.Name);

    TextBox quantityTextBox = (Window.GetWindow(ChartControl.Parent) as Chart).FindFirst("ChartTraderControlQuantityEdit") as TextBox;
    string text = (Tgt1Quantity + Tgt2Quantity + Tgt3Quantity).ToString();
    if (text != quantityTextBox.Text)
    {
    ChartTraderControlGrid1.Visibility = Visibility.Visible;
    quantityTextBox.Focus();
    quantityTextBox.Text = text;
    System.Windows.Forms.SendKeys.SendWait("{ENTER}");
    ChartTraderControlGrid1.Visibility = Visibility.Collapsed;
    }
    }));
    Last edited by gbourque; 03-16-2025, 04:21 PM.

    #2
    Hello gbourque,

    After setting the Visibility, instead of setting Text, set the Value.

    Below is a link to an example.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      TextBox does not have a Value property. See image.

      Attached Files

      Comment


        #4
        Print(quantityTextBox.GetType());

        System.Windows.Controls.TextBox

        Comment


          #5
          Hello gbourque,

          The object is not a textbox but contains one. This is a NinjaTrader.Gui.Tools.QuantityUpDown as demonstrated in the example I have provided you.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Chelsea is right again!

            Yeah, I wish I had seen this example before. I had tried something like this, but think I was getting the wrong control. I don't even have to make it visible for this to work, like with the AccountSelector. Now it all makes sense.

            Better solution. Thank you.

            AccountSelector acctSel = (Window.GetWindow(ChartControl.Parent) as Chart).FindFirst("ChartTraderControlAccountSelecto r") as AccountSelector;
            acctSel.SelectedAccount = Account.All.First(a => a.Name == Account.Name);​

            QuantityUpDown quantitySel = (Window.GetWindow(ChartControl.Parent) as Chart).FindFirst("ChartTraderControlQuantitySelect or") as QuantityUpDown;
            quantitySel.Value = Tgt1Quantity + Tgt2Quantity + Tgt3Quantity;

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            38 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            124 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            64 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            41 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X