• 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.


No announcement yet.

Partner 728x90


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

  • Filter
  • Time
  • Show
Clear All
new posts

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

    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.

    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;
    //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
            [Display(Name = "StgConfig", GroupName = "NinjaScriptParameters", Order = 0)]
            public dbgTest.StgCnfg  m_StgCnfg { set;get;}

    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


      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


        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
        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


        Latest Posts


        Topics Statistics Last Post
        Started by Benjaminf, Today, 02:21 PM
        2 responses
        Last Post Eric M.
        by Eric M.
        Started by dieci, Today, 03:31 PM
        0 responses
        Last Post dieci
        by dieci
        Started by StevenNelson, Today, 03:05 PM
        2 responses
        Last Post StevenNelson  
        Started by grayfrog, 05-24-2020, 09:29 PM
        5 responses
        Last Post NinjaTrader_RyanS  
        Started by chrismcdermut, Today, 01:46 PM
        1 response
        Last Post NinjaTrader_Kate