Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unable to create instance of NinjaScript class

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

    Unable to create instance of NinjaScript class

    Hello,

    As I state in this post http://ninjatrader.com/support/forum...d.php?t=100183 , I recently changed my computer, installed Ninjatrader 8 and copied the code of my indicators and its dependency libraries to the new computer. The main (and I believe only) difference is the NT8 version.
    Old computer: 8.0.2.0.
    New computer: 8.0.6.1.

    The problem is, after compiling ok (and even NinjaScript editor detecting the namespace of the library, aka suggesting autocompletions), I get the following error when trying to open the Indicators window in a chart:
    "Error: Unable to create instance of NinjaScript 'NinjaTrader.NinjaScript.Indicators.zmqFeeder'. Most likely either the implementation no longer exists, there is no default constructor defined, the default constructor does not work correctly, or the 'OnStateChange' implementation for State=SetDefaults is flawed: Exception has been thrown by the target of an invocation.".

    I have been googling for a bit but most of the posts regarding the same issue are related to the NinjaTrader 7 version. Others refer to a constructor without parameters not being present, but in my code, every class has a constructor with no parameters. Others mentioned they got it solved by restarting NinjaTrader, but no luck for me.

    Could anybody help me? In the meantime, I will try to get the smallest case possible that reproduces my problem, and I will update this post when I have it.

    I got a small case that reproduces the issue. The library I'm using is ZMQ,
    more precisely, these bindings: https://github.com/zeromq/clrzmq4/releases

    However, I'm using an older version. For using the exact same version, please download it from https://drive.google.com/open?id=0B9...jNtNURtYjNXS0k

    Note the zip file is named Custom, because I made it directly from the "NinjaTrader 8/bin/Custom" folder, which is where I had the files. However, the top level ones were just for testing. The one I added in references in the NinjaScript editor was the one under "Custom/zmq/ZeroMQ.dll")

    So, simply decompress the zip file and add the zmq/ZeroMQ.dll to the NinjaScript references.

    This is the code of an indicator (named aaaTestIndicator).

    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    using ZeroMQ;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it. 
    namespace NinjaTrader.NinjaScript.Indicators
    {
    	public class aaaTestIndicator : Indicator
    	{
    		ZContext zmqContext;
    		
    		public aaaTestIndicator() {
    			this.zmqContext = new ZContext();
    		}
    		
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"A test indicator with the mere purpose of testing stuff.";
    				Name										= "aaaTestIndicator";
    				Calculate									= Calculate.OnBarClose;
    				IsOverlay									= false;
    				DisplayInDataBox							= true;
    				DrawOnPricePanel							= true;
    				DrawHorizontalGridLines						= true;
    				DrawVerticalGridLines						= true;
    				PaintPriceMarkers							= true;
    				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
    				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
    				//See Help Guide for additional information.
    				IsSuspendedWhileInactive					= true;
    			}
    			else if (State == State.Configure)
    			{
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			Print("A new bar was HERE");
    		}
    	}
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
    	public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    	{
    		private aaaTestIndicator[] cacheaaaTestIndicator;
    		public aaaTestIndicator aaaTestIndicator()
    		{
    			return aaaTestIndicator(Input);
    		}
    
    		public aaaTestIndicator aaaTestIndicator(ISeries<double> input)
    		{
    			if (cacheaaaTestIndicator != null)
    				for (int idx = 0; idx < cacheaaaTestIndicator.Length; idx++)
    					if (cacheaaaTestIndicator[idx] != null &&  cacheaaaTestIndicator[idx].EqualsInput(input))
    						return cacheaaaTestIndicator[idx];
    			return CacheIndicator<aaaTestIndicator>(new aaaTestIndicator(), input, ref cacheaaaTestIndicator);
    		}
    	}
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    	public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    	{
    		public Indicators.aaaTestIndicator aaaTestIndicator()
    		{
    			return indicator.aaaTestIndicator(Input);
    		}
    
    		public Indicators.aaaTestIndicator aaaTestIndicator(ISeries<double> input )
    		{
    			return indicator.aaaTestIndicator(input);
    		}
    	}
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
    	public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    	{
    		public Indicators.aaaTestIndicator aaaTestIndicator()
    		{
    			return indicator.aaaTestIndicator(Input);
    		}
    
    		public Indicators.aaaTestIndicator aaaTestIndicator(ISeries<double> input )
    		{
    			return indicator.aaaTestIndicator(input);
    		}
    	}
    }
    
    #endregion
    Best regards.
    Last edited by Flood; 05-10-2017, 04:12 AM.

    #2
    Hello,

    I just wanted to post a quick summary of the solution we had come to through email in case any other users require this information.

    It appears that the files in question are not currently working but I can see that cloning the linked git repo and rebuilding the library does work.

    The steps we had used to reach a solution are as follows:
    1. Clone the repo
    2. Open ZeroMQ.VS.csproj
    3. Rebuild the solution (I used debug)
    4. Copy the contents of the bin/Debug folder to the NinjaTrader 8 bin/custom folder
    5. After doing this, Reference the dll and restart the platform.



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DanielTynera, Today, 01:14 AM
    0 responses
    2 views
    0 likes
    Last Post DanielTynera  
    Started by yertle, 04-18-2024, 08:38 AM
    9 responses
    40 views
    0 likes
    Last Post yertle
    by yertle
     
    Started by techgetgame, Yesterday, 11:42 PM
    0 responses
    12 views
    0 likes
    Last Post techgetgame  
    Started by sephichapdson, Yesterday, 11:36 PM
    0 responses
    2 views
    0 likes
    Last Post sephichapdson  
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,615 views
    0 likes
    Last Post aligator  
    Working...
    X