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

Use Text Field values with Basic Entry Custom Button

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

    Use Text Field values with Basic Entry Custom Button

    Hi there,

    I’ve currently got some custom buttons on the basic entry/SuperDOM windows that I would like to execute custom orders when clicked. When they are clicked, I would like to be able to read the quantity and other necessary values like the instrument and limit, and use those values to execute the proper order. Can you tell me how I can access the text field values on the basic entry/SuperDOM windows?

    Thank you!

    #2
    Hello farrenzo47,

    This would not be documented, but you can get the objects by AutomationID.

    Below is a link to a forum post where NinjaTrader_Jesse has outlined how to find the AutomationIDs of objects in a window.


    I think the ones you will need are the SuperDOMControlInstrumentSelector, SuperDOMControlAccountSelector, and SuperDOMControlQuantityUpDown.

    Limit orders are placed by left-clicking the SuperDOM at the price row where you want to place the order. There is no control for limit that has an automationID.

    If you are not familiar with using AutomationIDs, I have a few examples you may find helpful.
    Hello All, Moving forward this will be maintained in the help guide reference samples and no longer maintained on the forum. Creating Chart WPF (UI) Modifications from an Indicator - https://ninjatrader.com/support/help...ui)-modifi.htm (https://ninjatrader.com/support/helpGuides/nt8/creating-chart-wpf-(ui)-modifi.htm) I've
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for your helpful response! I'm still having a bit of trouble using the Automation ID to get the necessary UI elements. I'm trying to do a FindFirst() search on the window element for the BasicEntryControlQuantityEdit to start out with, and am getting an error when I try to coerce it into a Textbox. Can you explain how I can coerce a DependencyObject (which I get from the search) into the necessary UI elements?

      The line of code in question is: var quant = window.FindFirst("BasicEntryControlQuantityEdit") as System.Windows.Forms.Control;
      And the error I am getting is: "Cannot convert type 'System.Windows.DependencyObject' to 'System.Windows.Forms.Control' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion"

      Thanks!

      Comment


        #4
        Hello farrenzo47,

        I believe in this case you would need to use the specific type for the control and not System.Windows.Forms.Control. System.Windows.Forms.is also not used in NT8.

        It would generally be suggested to use the same general format you have displayed or the following for the cast:

        Code:
        FulllyQualifiedType variableName = parentObject.FindFirst("AutomationID") as FulllyQualifiedType;
        A fully qualified type name looks like the following where it includes the full namespace:
        Code:
        NinjaTrader.Gui.NinjaScript.AtmStrategy.AtmStrategySelector
        The automation id BasicEntryControlQuantityEdit points to a TextBox, you can use Inspect to see the objects type. This would be System.Windows.Controls.TextBox.

        However, this is part of a parent control which is likely easier to use which is the NinjaTrader.Gui.Tools.QuantityUpDown: BasicEntryControlQuantityUpDown
        You can find some samples of the QuantityUpDown in posts through the forum where other users have asked about it, likely more than TextBox.

        If you are still having the error and cannot solve it, I would suggest making a simple test that demonstrates the error and that you can also upload with your reply. I could take a look at it to see if I can better understand the error in contrast to the code used while also being able to test it.

        Last edited by NinjaTrader_Jesse; 12-14-2018, 09:43 AM.
        JesseNinjaTrader Customer Service

        Comment


          #5
          This is perfect, thank you Jesse! Do you know of a good way to find the namespace of a element that you see in Inspect.exe? I ran into that issue because I was assuming that the TextBox was a Form element rather than a Control.

          Thank you!

          Comment


            #6
            Hello farrenzo47,

            This is a good question. One important observation here would be that NT8 does not use System.Windows.Forms for its UI which brings me to another item. It is important to understand there are two main window frameworks which can be used with C# which are Windows Forms (System.Windows.Forms) and WPF (System.Windows.Controls). These are not generally interchangeable and NT7 used Windows Forms where NT8 uses WPF so there is a large difference in samples between the platforms. If either of these concepts are unclear, I would suggest searching about each of these namespaces online for further education information.

            Generally, it's pretty easy to determine the namespace for controls in NT8, they are either going to be a WPF control or a Custom control. So it's always one of those two which will be the System.Windows.Controls namespace or one of the NinjaTrader namespaces. You can add other references in NinjaScript which may entail those controls are in some other custom namespace, but for the most part you will just use a couple of namespaces for controls.

            For the NinjaTrader controls or even WPF controls, it's generally easiest to open the Visual Studio Project from the NinjaScript Editor and use Visual Studios Object Browser (View -> Object Browser) to search for the type without the full name.

            An example could be searching for QuantityUpDown will show the object in the NinjaTrader.Gui.Tools namespace.

            Searching for TextBox will show both System.Windows.Controls and also System.Windows.Forms.TextBox. Being that we are using NT8 we know we do not want the Windows Forms control so you can safely pick the one that does not include "forms" in its name. An alternative for WPF controls which may be easier is just searching online for "WPF TextBox". This type of search most often results in an MSDN article showing the assembly and namespace for the control.


            You can learn about Object Explorer by using Microsofts documentation. This is a very good way to locate NinjaTrader specific namespaces and controls for UI development as there is not a lot of documentation on this subject in the help guide. It is generally expected that the developer doing the UI development is very familiar with how WPF works for NT8 development. I would suggest doing some research on WPF/XAML development if this subject is at all foggy for you as that will help with NT8 UI development and manipulating existing WPF controls.


            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by kujista, Today, 05:44 AM
            0 responses
            5 views
            0 likes
            Last Post kujista
            by kujista
             
            Started by ZenCortexCLICK, Today, 04:58 AM
            0 responses
            5 views
            0 likes
            Last Post ZenCortexCLICK  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            172 responses
            2,281 views
            0 likes
            Last Post sidlercom80  
            Started by Irukandji, Yesterday, 02:53 AM
            2 responses
            18 views
            0 likes
            Last Post Irukandji  
            Started by adeelshahzad, Today, 03:54 AM
            0 responses
            8 views
            0 likes
            Last Post adeelshahzad  
            Working...
            X