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

Set ChartTrader Order Quantity via script

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

    Set ChartTrader Order Quantity via script

    Hi, is it possible to access the chart trader to set the order Qty per script, e.g. from an indicator?

    Click image for larger version

Name:	explorer_QtC6zjm3Xc.jpg
Views:	355
Size:	9.5 KB
ID:	1214799

    Code:
    chartTrader = chartWindow.FindFirst("ChartWindowChartTraderControl") as ChartTrader;
    chartTrader.OrderQty ???
    sidlercom80
    NinjaTrader Ecosystem Vendor - Sidi Trading

    #2
    Hello sidlercom80,

    Thanks for your question, yes this is possible.

    Please see the example attached for capturing ChartTrader controls for using in code.

    If you want to programmatically change a property of this control, you will need to use ChartControl.Dispatcher.InvokeAsync() since the element would reside on the chart's UI thread.

    Let us know if there is anything else we can do to help.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim, for your demo file. I'm trying to set a binding (Two Way) correctly so that via NotifyPropertiechanged event handler in the Base class, the propertie is updated both in the chart trader (UI) and the properties directly. Unfortunately, I can't quite get the binding right. Everything works except for setting the "quantitySelector.Value" directly via the binding. Do you have a tip for me?

      Code:
      // find the ChartTrader quantity selector by AutomationID
      quantitySelector = chartWindow.FindFirst("ChartTraderControlQuantitySelector") as QuantityUpDown;
      if (quantitySelector != null)
         {
             quantitySelector.ValueChanged += QuantitySelector_ValueChanged;
             currentQuantity = quantitySelector.Value;
              //set binding to our OrderQty property in base class
              quantitySelector.SetBinding(QuantityUpDown.ValueProperty, new Binding
                      {      
                              Source = ???
                              Path = new PropertyPath("OrderQty"),
                              Mode = BindingMode.TwoWay,
                              UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                          });
           }
      The OrderQty propertie is the property in the base class that is to update itself.
      sidlercom80
      NinjaTrader Ecosystem Vendor - Sidi Trading

      Comment


        #4
        Hello sidlercom80,

        The closest example we have shows a class inheriting from INotifyPropertyChanged and uses XAML to describe bindings.

        This is a bit of an advanced example that goes beyond our scope of support, so we may recommend checking out other publicly available WPF resources on binding.

        If you happen to accomplish your goal, your feedback may be useful for the community, so please write back!
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          For those who are interested, here is my solution:

          Base class:
          Code:
          public int SelectedOrderQty
          {
              get { return selectedOrderQty; }
              set
                   {
                       if (selectedOrderQty != value)
                       {
                           selectedOrderQty = Math.Max(1, value);
                           NotifyPropertyChanged();
                        }
                    }
          }
          
          
          [XmlIgnore, Browsable(false)] public object PropertyBase { get { return this; } }
          View class:
          Code:
          //find the ChartTrader quantity selector by AutomationID
          quantitySelector = chartWindow.FindFirst("ChartTraderControlQuantitySelector") as QuantityUpDown;
          if (quantitySelector != null)
          {
            //set binding to our OrderQty property in the base class
            quantitySelector.SetBinding(QuantityUpDown.ValueProperty, new Binding
               {
                     Source = PropertyBase,
                     Path = new PropertyPath("SelectedOrderQty"),
                     Mode = BindingMode.TwoWay,
                     UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                });
          }
          sidlercom80
          NinjaTrader Ecosystem Vendor - Sidi Trading

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by yertle, Yesterday, 08:38 AM
          7 responses
          28 views
          0 likes
          Last Post yertle
          by yertle
           
          Started by bmartz, 03-12-2024, 06:12 AM
          2 responses
          21 views
          0 likes
          Last Post bmartz
          by bmartz
           
          Started by funk10101, Today, 12:02 AM
          0 responses
          4 views
          0 likes
          Last Post funk10101  
          Started by gravdigaz6, Yesterday, 11:40 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by MarianApalaghiei, Yesterday, 10:49 PM
          3 responses
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X