Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy licensing and object reference not set to instance

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

    strategy licensing and object reference not set to instance

    i must be missing something ... but can anyone shed some light on this:

    Code:
    using NinjaTrader.Strategy;
    namespace Foo.Bar
    {
        public partial class FooBar : Strategy
        {
            protected override void Initialize()
            {
                VendorLicense("Company", "Product", "Url", "Email");
            }
            // ... //
            public void Test()
            {
                Print("Hello, World");
            }
        }
    }
    that is compiled as an external dll ... and i've added the reference to that DLL ...

    next, i create a strategy from within NT7, and intellisence does pick up Foo.Bar.FooBar.Test() as a valid method ... here's that code:

    Code:
    // default using from NT Strategy Wizard
    // ... //
    namespace NinjaTrader.Strategy
    {
        public class FooBarTest : Strategy
        {
            Foo.Bar.FooBar fb;
            protected override void Initialize()
            {
                Foo.Bar.FooBar fb = new Foo.Bar.FooBar();
            }
    
            protected override void OnBarUpdate()
            {
                fb.Test();
            }
        }
    }
    three things are curious to me:
    1) FooBar and FooBarTest both show up in Strategies window, and licensing works great for FooBar but not FooBarTest
    2) when I first apply FooBarTest, i get an error in OnBarUpdate() saying that the Object Reference is not set to an instance of an object.
    3) there is no Hello, World in the Output Window for FooBarTest

    thanks in advance for any helpful pointers ;-)

    cheers,
    -e

    #2
    Without much testing a hunch here as input -

    protected override void Initialize()
    {
    Foo.Bar.FooBar fb = new Foo.Bar.FooBar();
    }

    if you move this to OnStartUp() in NT7?

    Would you get a better outcome?

    Comment


      #3
      Bertrand,

      thanks for the quick reply ... i moved the code into OnBarUpdate and wrapped it with a check for fb == null:
      Code:
              protected override void OnBarUpdate()
              {
                  if (fb == null)
                  {
                      fb = new Foo.Bar.FooBar();
                  }
                  fb.Test();
              }
      and that definitely solved #3 and seemed to take care of #2 issues as well ...

      but i like your implementation better since it looks like OnStartUp() is only invoked once (as opposed to Initialize()).

      ------

      any thoughts on issue #1 with the vendor licensing?

      i definitely get the warning message if i invoke FooBar directly ... but no such warning comes when i invoke FooBarTest.

      cheers,
      -e

      Comment


        #4
        not sure the OnStartUp() idea works ... i thought it did initially, but after some more testing, it's back to its old tricks again ... nonetheless, my workaround above for OnBarUpdate() seems to do the trick.

        now for issue #1 ... the licensing ... it would appear that VendorLicense() is not invoked when cascaded down from Strategy -> instantiated Strategy ... so top-level strategy calls it from Initialize() but instantiating another Strategy inside of the top-level strategy does not render the top-level strategy inoperable.

        still looking for a NT-sanctioned way to utilize the VendorLicense() method for nested objects, as such ... any tips / hints / ideas most appreciated ;-)

        cheers,
        -e

        Comment


          #5
          e-man, I checked into - unfortunately this is not possible - you would need to place the VendorLicense call directly in the Initialize() of each indicator / strategy you want to license with it.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          647 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X