Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Draw DrawingTool from add-on

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

    Draw DrawingTool from add-on

    Hello everyone,
    I developing an add-on and trying to draw custom DrawingTool from the add-on.

    Draw partial class:
    Code:
    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);
            }
        }​
    }
    Add-on code:
    Code:
    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()
            {
            }​
    }
    }​​
    Basically when user clicked on chart control I calling Draw.MyDrawingTool function to draw the DrawingTool but inside MyDrawingToolCore<T> DrawingTool.GetByTagOrNew(owner, typeof(T), tag, string.Empty) as T; always returning null.

    Am I doing something wrong? How to correctly draw a custom drawing tool from an add-on?

    Thanks!

    #2
    Hello yyesyyesyyes,

    Unfortunately, there is no supported way to call drawing tools from an addon, and thus there is no documentation.

    Drawing Tools are designed to be called from an indicator or strategy class only.

    Further, calling an indicator from an Addon is also not supported.

    This thread will remain open for any community members that would like to provide unsupported code.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rbeckmann05, Yesterday, 06:48 PM
    1 response
    12 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    15 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Working...
    X