I assign a plot value in OnBarUpdate, for example: Value[0] = EMA(EmaPeriod)[0] ;
OnMarketData assigns values to a couple of class variables for R and G of the RGB set; e.g., according to a transaction taking place at either bid or ask.
Back in OnBarUpdate attempting to adjust the plot color via PlotBrushes[0][0] from SolidColorBrush(Color.FromArgb(a,R,G,b)) only works if Calculate.OnBarClose. If Calculate.OnEachTick, the plot color never changes.
See the attached screenshots.
private byte by_red = 255 ; private byte by_green = 255 ; private byte by_blue = 0 ; protected override void OnMarketData(MarketDataEventArgs e) { if (e.MarketDataType == MarketDataType.Last && CurrentBar >= 0) { if (e.Price >= e.Ask) { by_red = 0 ; by_green = 255 ; } else if (e.Price <= e.Bid) { by_red = 255 ; by_green = 0 ; } } } protected override void OnBarUpdate() { Value[0] = EMA(EmaPeriod)[0] ; Brush brush = new SolidColorBrush(Color.FromArgb(255, by_red, by_green, by_blue)); brush.Freeze(); PlotBrushes[0][0] = brush ; }
Comment