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

Using Addon classes as strategy logic extension

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

    Using Addon classes as strategy logic extension

    Hello, I have been building a strategy and the code got a little too long, so i decided to revamp it.

    I have used Addon classes as suggested here, but with a slight change that might be causing the issue.

    The issue is an error, but as far as I can see, the only issue is the error and nothing else, everything works as expected in spite of it.

    Error:
    22/04/2023 4:31:46 NinjaScript Unable to create instance of NinjaScript 'class_name'. 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: System.MissingMethodException: Constructor on type 'NinjaTrader.NinjaScript.AddOns.Classes.Patterns.f older_name.class_name' not found. at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at NinjaTrader.Core.AssemblyRegistry.set_Item(String assemblyName, Assembly value)


    This Is is the base code used for all these extensions:
    Code:
    public class class_name: NinjaTrader.NinjaScript.AddOnBase
    {
    public Strategy _strategy;
    
    private custom_addon_1;
    private custom_addon_2;
    private custom_addon_3;
    
    private custom_indicator_1;
    private default_indicator_1;
    
    
    
    
    public class_name(Strategy strategy)
    {
    _strategy = strategy;
    
    custom_addon_1 = _strategy.CustomAddon1();
    custom_addon_2 = _strategy.CustomAddon2();
    custom_addon_3 = _strategy.CustomAddon3();
    
    custom_indicator_1 = _strategy.CustonIndicator1();
    default_indicator_1 = _strategy.DefaultIndicator1();​ // this could be for example SMA(200);
    
    
    
    }
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @".";
    }
    
    
    }​
    And then i use the logic the same way i use it inside a strategy, just adding _strategy to some things like Low,Close,Open,High of bars.

    Code:
    bool someBoolValue = _strategy.Close[0].ApproxCompare(default_indicator_1[0]) == -1;

    In the strategy code, i declare the addon class under the class block:
    Code:
    private AddonClass1 addon_class_1;
    and then create an instance of it under the State.DataLoaded block, passing the strategy as an argument:
    Code:
                else if (State == State.DataLoaded)
                {
                    addon_class_1= new AddonClass1( this );
                }​
    Am i doing something wrong here? everything works fine i just want to make sure this is nothing critical to the strategy performance. ( it already ran live and worked as expected ).


    Thanks for the continued support!

    Aviram Y.
    Last edited by Aviram Y; 04-22-2023, 08:59 AM.

    #2
    Just an idea ,,,

    After every re-compile, are you exiting NinjaTrader and restarting
    before you commence testing/using your changes?

    Comment


      #3
      Originally posted by bltdavid View Post
      Just an idea ,,,

      After every re-compile, are you exiting NinjaTrader and restarting
      before you commence testing/using your changes?
      Thanks for the help! very appreciated!

      Should I be fully exiting Ninjatrader after each re-compile? seems time consuming..

      The answer the question, I am not doing that, I just re-compile after every change i make an rerun the same strategy analyzer window when back testing.

      Comment


        #4
        Originally posted by Aviram Y View Post
        Should I be fully exiting Ninjatrader after each re-compile? seems time consuming..
        Especially if... you have to TYPE IN A NON-TRIVIAL PASSWORD EVERY TIME. NinjaTrader, can you give us back "remember me and keep me signed in"? I easily have to sign in a dozen or more times per day, and that's probably an understatement, and there is not a live account connected when I'm doing this to be worried about the security for (I have a live account but don't use it for this sort of thing like iterating the development of an add-on). Knock on wood, so far, I haven't gotten myself locked out, but I'll bet one day that will happen.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Hello Aviram,

          Thanks for your post.

          This error typically appears when changes have been made to a script but the prior version of the script is being used for backtests or being used on a chart window.

          After making changes to your script and compiling the script in the NinjaScript Editor window, change the strategy in the Strategy Analyzer to a different strategy, such as SampleMACrossover. Then change the strategy in the Strategy Analyzer back to the strategy you are testing to make sure the changes you made to that stratgey took effect.

          Please let me know if this does not resolve the error message appearing.
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            NinjaTrader_BrandonH says
            After making changes to your script and compiling the script in the NinjaScript Editor window, change the strategy in the Strategy Analyzer to a different strategy, such as SampleMACrossover. Then change the strategy in the Strategy Analyzer back to the strategy you are testing to make sure the changes you made to that stratgey took effect.
            Well, that may work ... but surely the platform can determine if a strategy (or Indicator or AddOn) has been recompiled and automatically reload it as need be, particularly in such obvious cases? The suggested workaround seems to be compensating for a lack of obvious functionality that should "just be there".

            Thanks.
            Multi-Dimensional Managed Trading
            jeronymite
            NinjaTrader Ecosystem Vendor - Mizpah Software

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Option Whisperer, Today, 09:55 AM
            0 responses
            5 views
            0 likes
            Last Post Option Whisperer  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            8 responses
            58 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by halgo_boulder, 04-20-2024, 08:44 AM
            2 responses
            22 views
            0 likes
            Last Post halgo_boulder  
            Started by mishhh, 05-25-2010, 08:54 AM
            19 responses
            6,189 views
            0 likes
            Last Post rene69851  
            Started by gwenael, Today, 09:29 AM
            0 responses
            6 views
            0 likes
            Last Post gwenael
            by gwenael
             
            Working...
            X