I am looking into combining two function to print a condition.
I took the example from two different posts on the forum showing the function for keydown and the function click to get the price data but I am not sure how to create a condition that will map both the function.
As a reference code to get the keydown press and code to get the coordinate of the click
if (State == State.DataLoaded) { if (ChartPanel != null) { this.ChartPanel.KeyDown += new System.Windows.Input.KeyEventHandler(OnKeyDown); this.ChartPanel.KeyUp += new System.Windows.Input.KeyEventHandler(OnKeyUp); } } else if (State == State.Historical) { if (ChartControl != null) { foreach (ChartScale scale in ChartPanel.Scales) if (scale.ScaleJustification == ScaleJustification) chartScale = scale; ChartControl.MouseLeftButtonDown += MouseClicked; } } else if (State == State.Terminated) { if (ChartPanel != null) { this.ChartPanel.KeyDown -= OnKeyDown; this.ChartPanel.KeyUp -= OnKeyUp; ChartControl.MouseLeftButtonDown -= MouseClicked; } } } private bool cntKey = false; public void OnKeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == Key.LeftCtrl && !cntKey) { cntKey = true; Print("Down"); } } public void OnKeyUp(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == Key.LeftCtrl && cntKey) { cntKey = false; // Print("Up"); } } protected override void OnBarUpdate() {} //Add your custom indicator logic here. protected void MouseClicked(object sender, MouseButtonEventArgs e) { // convert e.GetPosition for different dpi settings clickPoint.X = ChartingExtensions.ConvertToHorizontalPixels(e.Get Position(ChartControl as IInputElement).X, ChartControl.PresentationSource); clickPoint.Y = ChartingExtensions.ConvertToVerticalPixels(e.GetPo sition(ChartControl as IInputElement).Y, ChartControl.PresentationSource); convertedPrice = Instrument.MasterInstrument.RoundToTickSize(chartS cale.GetValueByY((float)clickPoint.Y)); convertedTime = ChartControl.GetTimeBySlotIndex((int)ChartControl. GetSlotIndexByX((int)clickPoint.X)); Draw.TextFixed(this, "priceTime", string.Format("Price: {0}, Time: {1}", convertedPrice, convertedTime), TextPosition.BottomLeft); ForceRefresh(); }
Now what I want to achieve is something where I can combine the two function in one condition to output
if ([B][COLOR=#3498db]e.Key == Key.LeftCtrl && !cntKey[/COLOR][/B] [COLOR=#9b59b6]&& [B]Click[/B][/COLOR]) { Draw.TextFixed(this, "priceTime", string.Format("Price: {0}, Time: {1}", convertedPrice, convertedTime), TextPosition.BottomLeft); }
Thanks
Comment