I developing an add-on and trying to draw custom DrawingTool from the add-on.
Draw partial class:
namespace NinjaTrader.NinjaScript.DrawingTools { public class MyDrawingTool : DrawingTool { //NinjaScript routine. public void Init() { } public void InitPosition(Point pos, ChartControl control, ChartScale scale) { } } public static partial class Draw { private static T MyDrawingToolCore<T>(NinjaScriptBase owner, string tag, bool isAutoScale, Point pos, DateTime time, ChartControl chartControl, ChartScale chartScale) where T : DrawingTool { if (owner == null) throw new ArgumentException("owner"); T chartMarkerT = DrawingTool.GetByTagOrNew(owner, typeof(T), tag, string.Empty) as T; if (chartMarkerT == null) return default(T); DrawingTool.SetDrawingToolCommonValues(chartMarkerT, tag, isAutoScale, owner, true); // dont nuke existing anchor refs //int currentBar = DrawingTool.GetCurrentBar(owner); //ChartBars chartBars = (owner as Gui.NinjaScript.IChartBars).ChartBars; (chartMarkerT as MyDrawingTool).Init(); (chartMarkerT as MyDrawingTool).InitPosition(pos, chartControl, chartScale); var anchor = DrawingTool.CreateChartAnchor(owner, 0, time, pos.Y); chartMarkerT.SetState(State.Active); return chartMarkerT; } public static MyDrawingTool MyDrawingTool(NinjaScriptBase owner, string tag, bool isAutoScale, Point pos, DateTime time, ChartControl chartControl, ChartScale chartScale) { return MyDrawingToolCore<MyDrawingTool>(owner, tag, isAutoScale, pos, time, chartControl, chartScale); } } }
namespace NinjaTrader.Gui.NinjaScript { private MyIndicator ord; protected override void OnWindowCreated(Window window) { _myChart = window as Gui.Chart.Chart; if (_myChart == null) { return; } ord = new MyIndicator(); _chartControl = _myChart.ActiveChartControl; _chartControl.Indicators.Add(ord); _chartControl.MouseLeftButtonDown += ActiveChartControl_MouseLeftButtonDown; } private void ActiveChartControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { _lastMousePoint = e.GetPosition(Chart.ActiveChartControl); Draw.MyDrawingTool(ord, Guid.NewGuid().ToString(), true, _lastMousePoint, DateTime.MinValue, Chart.ActiveChartControl, Chart.ActiveChartControl.ChartPanels[0].Scales.First(x => x.ScaleJustification == ScaleJustification.Right)); } public class MyIndicator : Indicator { protected override void OnStateChange() { if (State == State.SetDefaults) { Name = "Placeholder"; Description = "Placeholder."; } } protected override void OnBarUpdate() { } } }
Am I doing something wrong? How to correctly draw a custom drawing tool from an add-on?
Thanks!
Comment