• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Log Error message " Unable to create instance of NinjaScript..."

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

    Log Error message " Unable to create instance of NinjaScript..."

    Hello,
    After I created my strategy directly in the NinjaScript .
    Directly in the NinjaScript I created a new folder named MyStrategies under Strategies folder and then I created my new strategy.

    The problem is that after completion succeeded I tried to load my strategy through the Strategies window but I did not see the folder I created and my new strategy.
    The logger write “Unable to create instance of NinjaScript …..”
    If I close NT and then open it again then I do see my new folder and strategy.
    But if I recompiled again the problem returned, I don’t see my folder and my strategy under this folder and logger show “Unable to create instance of NinjaScript …..”

    If I drag my strategy file into the main strategy folder “Strategies” recompile it again everything is fine.
    If I drag the strategy back from the main folder to my folder, recompile again then again there is a problem.
    I think that there is a problem with a namespace.

    In addition, if I drag my strategy from my folder to the main folder, open the strategy file
    I see that the name space is not updated accordingly

    I get "namespace NinjaTrader.NinjaScript.Strategies.MyStrategies”
    instead of “NinjaTrader.NinjaScript.Strategies”

    If I close the file again and reopen it then namespace updated OK.

    Right now I just built an empty strategy that do nothing ,the strategy contains a property of class type only for test
    And it also happens.

    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.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    using NinjaTrader.NinjaScript.Strategies.MyStrategies;
    #endregion
    
    //This namespace holds Strategies in this folder and is required. Do not change it. 
    namespace NinjaTrader.NinjaScript.Strategies.MyStrategies
    {
        public class dbgTest : Strategy
        {
            public class StgCnfg
            {
                public int x = 0;
    
                public StgCnfg()
                {
                    this.x = 0;
                }
            }
    
            //==========================================================================================================================
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Strategy here.";
                    Name                                        = "dbgTest";
                    Calculate                                    = Calculate.OnEachTick;
                    EntriesPerDirection                            = 1;
                    EntryHandling                                = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy                = true;
                    ExitOnSessionCloseSeconds                    = 30;
                    IsFillLimitOnTouch                            = false;
                    MaximumBarsLookBack                            = MaximumBarsLookBack.Infinite;
                    OrderFillResolution                            = OrderFillResolution.Standard;
                    Slippage                                    = 0;
                    StartBehavior                                = StartBehavior.WaitUntilFlat;
                    TimeInForce                                    = TimeInForce.Gtc;
                    TraceOrders                                    = true;
                    RealtimeErrorHandling                        = RealtimeErrorHandling.IgnoreAllErrors;
                    StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade                            = 100;
                    // Disable this property for performance gains in Strategy Analyzer optimizations
                    // See the Help Guide for additional information
                    IsInstantiatedOnEachOptimizationIteration    = true;
    
                    m_StgCnfg = new dbgTest.StgCnfg();
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, 
                Cbi.MarketPosition marketPosition, string orderId, DateTime time)
            {
    
            }
    
            protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, 
                int quantity, int filled, double averageFillPrice, 
                Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
            {
    
            }
    
            protected override void OnBarUpdate()
            {
                //Add your custom strategy logic here.
            }
    
            #region Properties
            [NinjaScriptProperty]
            [XmlIgnore]
            [Display(Name = "StgConfig", GroupName = "NinjaScriptParameters", Order = 0)]
            public dbgTest.StgCnfg  m_StgCnfg { set;get;}
    
            #endregion
        }
    }
    Sincerely,kobi


    #2
    Hi levikNT, thanks for your note.

    There seems to be some kind of development environment issue. Please try creating a new NinjaTrader.Custom.dll by following these steps:
    • Close out of NinjaTrader
    • Navigate to Documents\NinjaTrader 8\bin\Custom
    • Delete the file named "NinjaTrader.Custom.dll"
    • Restart NinjaTrader> Compile> Test the script again.
    Please let me know if this does not resolve this issue.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello Chris L.
      I already tried it, but it didn't solve the problem.
      I also uninstall NT and Install NT again, and it also didn't solve the problem.
      sincerely, Kobi

      Comment


        #4
        Hello levikNT,

        Thanks for your reply.

        I would like to see if this happens on a clean NinjaTrader 8 folder in the Documents. If you do develop with NT, I recommend having a clean development environment or else instance errors like this could happen.

        To create a clean temporary NinjaTrader folder:
        1. Shutdown NinjaTrader
        2. Rename (My) Documents\NinjaTrader 8\ to (My) Documents\NinjaTrader 8.original\
        3. Download the NinjaTrader installation package from the link below
          http://ninjatrader.com/GetStarted
        4. Run the repair from this installer (if the repair is unsuccessful, uninstall and then re-install NinjaTrader)

        Do the same thing with adding a folder in the NinjaScript editor, it should compile without issues.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by indy73, Today, 10:52 PM
        0 responses
        3 views
        0 likes
        Last Post indy73
        by indy73
         
        Started by martyn73, Today, 07:04 PM
        0 responses
        5 views
        0 likes
        Last Post martyn73  
        Started by sergey_z, Today, 02:56 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by samir, Today, 02:46 PM
        1 response
        20 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by neoikon, Today, 02:24 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Working...
        X