The object is created using the code below:
Dispatcher.InvokeAsync((() => {
TrafficLight = new System.Windows.Controls.Grid {
Name = "MyCustomGrid2", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top
};
System.Windows.Controls.ColumnDefinition col0 = new System.Windows.Controls.ColumnDefinition();
System.Windows.Controls.ColumnDefinition col1 = new System.Windows.Controls.ColumnDefinition();
TrafficLight.ColumnDefinitions.Add(col0);
TrafficLight.ColumnDefinitions.Add(col1);
VWAP = new System.Windows.Controls.Button {
Name = "VWAPButton", Content = "VWAP", Foreground = Brushes.White, Background = Brushes.Black
};
EMA = new System.Windows.Controls.Button {
Name = "EMAButton", Content = "EMA", Foreground = Brushes.White, Background = Brushes.Black
};
System.Windows.Controls.Grid.SetColumn(VWAP, 0);
System.Windows.Controls.Grid.SetColumn(EMA, 1);
TrafficLight.Children.Add(VWAP);
TrafficLight.Children.Add(EMA);
UserControlCollection.Add(TrafficLight);
}));
}
I have a few more codes to display and destroy the object, but these codes are not relevant to my problem, as far as I know.
This code add two buttons at the top of the screen. Everything was working, until I decided to change the background color based on some criteria on the OnBarUpdate() method.
To accomplish this task, I had to use a dispatcher..
ChartControl.Dispatcher.InvokeAsync((() => {
if ( VWAP1.PlotVWAP[0] < Close[0]) { // When inspecting these values, they never change
VWAP.Background=Brushes.Green;
else
VWAP.Background=Brushes.Red;
}
Print(String.Format("VWAP: {0}", Close[0])); ///This code prints
if(EMAL[1] < EMAH[1] ) {
EMA.Background=Brushes.Red;
else
VWAP.Background=Brushes.Green;
}
Print(String.Format("EMA: {0}", Close[0])); ///// This code never prints
}));
Again, this code works, but when inspecting the variable values, they are off of the real ones.
Inside the invoke, Close[0] doesn't change at all, while outside, the value is correct and changing as the price changes on the chart.
Also, when I use the same invoke, or a new invoice, to change the other object EMA, it never executes.
I can't figure out what is wrong with the code.
Please help!

Comment