Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can I change a button text OnBarUpDate

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

    Can I change a button text OnBarUpDate

    I have 2 button on my ChartTrader that I use to place orders.

    I stole the code from you guys and create the buttons in State.Historical.

    PHP Code:
                else if (State == State.Historical)
                {
                    if (ChartControl != null)
                    {
                        ChartControl.Dispatcher.InvokeAsync(() =>
                        {
                            CreateWPFControls();
                        });
                    }
                }
    ​ 
    

    I do the button content and background in the method that creates the buttons

    Click image for larger version

Name:	image.png
Views:	77
Size:	369.8 KB
ID:	1339663​​


    Click image for larger version

Name:	image.png
Views:	107
Size:	86.8 KB
ID:	1339661

    I would like to change the button content and background depending on conditions on the chart.

    I tried placing this in OnBarUpdate()
    PHP Code:
                buttonsArray[2].Background    = Brushes.Blue;
    ​ 
    


    that didn't work.

    Is it possible to change the buttons during execution?

    if so, how?

    thanks
    Attached Files

    #2
    Hello cre8able,

    Yes you can do that using the variable. you need to use a dispatcher:

    if (ChartControl != null)
    {
    ChartControl.Dispatcher.InvokeAsync(() =>
    {
    buttonsArray[2].Background = Brushes.Blue;
    });
    }

    Comment


      #3
      I unsuccessfully tried this

      PHP Code:
              private void UpdateButtonColor(Brush color)
              {
                  if (buttonsArray[2] != null)
                  {
                      ChartControl.Dispatcher.InvokeAsync(() => buttonsArray[2].Background = color);
                  }
              }
              
              
      #region===        OnOrderUpdate    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
              
              protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
              {
                  // Handle entry orders here. The entryOrder object allows us to identify that the order that is calling the OnOrderUpdate() method is the entry order.
                  // Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
                  // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not gauranteed to be complete if it is referenced immediately after submitting
                  if (order.Name == "Long" || order.Name == "Short")
                  {
                      entryOrder = order;
      
                      // Reset the entryOrder object to null if order was cancelled without any fill
                      if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                      {
                          entryOrder = null;
                          sumFilled = 0;
                      }
                  }
                  
                  if (Close[0] > Open[0])
                      UpdateButtonColor(Brushes.Blue);
                  else
                      UpdateButtonColor(Brushes.Yellow);
                      
              }
      ​ 
      

      Comment


        #4
        Hello cre8able,

        What was unsuccessful?

        I would suggest looking at the following file, that shows how to toggle buttons based on conditions.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        556 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X