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

Problem using Meta.Numerics library

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

    Problem using Meta.Numerics library

    Hello Everyone,

    For some rigorous statistical calculations, I tried to use Meta.Numerics which is a 3rd party maths and statistical library for .Net platform. So I did the following:

    1- Downloaded the reference dll
    2- Copied it to C:\Users\***\Documents\NinjaTrader 7\bin\Custom
    3- Added the address in References... dialog box
    4- Restarted NT7 (32-bit)
    5- added the libraries in "Using declarations" section

    Up to this point, everything went smooth and the code compiled without a hitch. But when I wanted to use a type with "new" command, after compiling, the strategy didn't show up in the strategy list to add to my chart. Now I know that when this happens, it indicates that something is wrong in the compiling but it is beyond my comprehension. Also I read somewhere in the forum that to use 3rd dlls, they must be compiled using .Net version 3.5, but yet again I'm not that into programming to check if the version of the aforesaid dll.

    Here's the simple code that I used:

    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    using Meta.Numerics;
    using Meta.Numerics.Statistics;
    using Meta.Numerics.Statistics.Distributions;
    #endregion
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// Enter the description of your strategy here
        /// </summary>
    	
        [Description("Enter the description of your strategy here")]
        public class Foo : Strategy
        {
            #region Variables
            // Wizard generated variables
            private int myInput0 = 1; // Default setting for MyInput0
            // User defined variables (add any user defined variables below)
            #endregion
    
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
    		double outp;
    		Distribution d = new LognormalDistribution();
            protected override void Initialize()
            {
    			Distribution d = new LognormalDistribution();
    			CalculateOnBarClose = true;
    			outp = d.Median;
    			Print("Output is: "+outp);
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    
            }
    
            #region Properties
            [Description("")]
            [GridCategory("Parameters")]
            public int MyInput0
            {
                get { return myInput0; }
                set { myInput0 = Math.Max(1, value); }
            }
            #endregion
        }
    }
    Information regarding Meta.Numerics can be found on the project's Codeplex site:

    https://metanumerics.codeplex.com

    Any help will be greatly appreciated. Thanks in advance.

    #2
    Hello arian_gh,

    Thank you for your post.

    Please check the Log tab, are there any messages concerning the strategy?

    Comment


      #3
      Hello Patrick,

      Yes, I checked the log and here's the message:

      Code:
      3/23/2015 3:08:36 AM	Default	Unable to create instance of 'NinjaTrader.Strategy.Foo'. Most likely there is no default constructor defined, or the default constructor does not work correctly: Exception has been thrown by the target of an invocation.	
      
      3/23/2015 3:00:10 AM	Strategy	Failed to call method 'Initialize' for strategy 'Foo/b47412c42d3b48cb8c3fe957d19eee6d': Could not load file or assembly 'Meta.Numerics, Version=3.0.0.0, Culture=neutral, PublicKeyToken=67d25c65a6631347' or one of its dependencies. The system cannot find the file specified.
      Also, when I remove this part:

      Code:
      Distribution d = new LognormalDistribution();
      I get no error on log.
      Last edited by arian_gh; 03-23-2015, 01:20 AM.

      Comment


        #4
        Hello arian_gh,

        Do you know if this assembly (.dll) was created with .Net 4?

        Comment


          #5
          No, unfortunately that's the thing I don't know how to check.

          Comment


            #6
            Can you contact the developer of the library and ask for a .NET 3.5 version?

            Comment


              #7
              Well I'll try if I have to. But is there any other workaround for this issue?

              Comment


                #8
                There is no work around for .NET 4 .dll files.

                Comment


                  #9
                  I downloaded the source code from codeplex.com and opened it using Vs 2013. It turned out that the target framework is .Net 3.5. I even rebuild the solution and tried to use the file again but no luck. I'm really frustrated. Can be the problem related to Windows 8 compatibility?

                  P.S. I contacted the designer but he seemed not to be respondent.

                  Comment


                    #10
                    Solved!

                    Hello Again,

                    So after some few hours of work, I finally found a workaround for the mentioned dll to work. Here's what I did:

                    1- Downloaded the source code from https://metanumerics.codeplex.com/SourceControl/latest

                    2- Unzipped the file and opened ...\metanumerics-73149\Numerics-v2\CodeplexNumerics.sln in Vs 2013

                    3- In VS 2013 set the build configuration to Release.

                    4- Rebuilt the solution and then used the dll.

                    For any other 3rd party dlls which may have the same issue, this might solve the problem as well.

                    All the best.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by alifarahani, Today, 09:40 AM
                    6 responses
                    31 views
                    0 likes
                    Last Post alifarahani  
                    Started by Waxavi, Today, 02:10 AM
                    1 response
                    17 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by Kaledus, Today, 01:29 PM
                    5 responses
                    14 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by Waxavi, Today, 02:00 AM
                    1 response
                    12 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by gentlebenthebear, Today, 01:30 AM
                    3 responses
                    17 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X