Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error compiling user indicator

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

    Error compiling user indicator

    Hi,
    I wrote an indicator called SRMomentum which I am trying to call from another indicator called SRMomentumSetup.
    SRMomentum is working fine as expected and has the following constuctor

    public SRMomentum SRMomentum(int period)
    {
    return SRMomentum(Input, period);
    }


    In SRMomentumSetup, I declare my class variables:

    SRMomentum lowMomentum, highMomentum;

    and instantiate the objects in State.DataLoaded:
    lowMomentum = new SRMomentum(LowPeriod);
    highMomentum = new SRMomentum(HighPeriod);


    However I am getting the error for both these lines:

    'Ninjatrader.NinjaScript.Indicators.SRMomentum' does not contain a constructor that takes 1 arguments

    Any ideas what the problem could be please?
    Regards,
    iq

    #2
    Hi iq, thanks for your note.

    The "new" keyword should not be used to instantiate a NinjaScript object. NinjaTrader calls "new" internally and this is where the NinjaTrader generated code at the bottom of all indicators comes into play. Incidentally, no custom constructor is needed. If you remove "new" from the two lines and look at the parameter list that SRMomentum can take then the code will compile correctly. It likely needs an input series, such as Close for example.

    e.g. lowMomentum = SRMomentum(Close, LowPeriod);

    Take a look at the parameter list when you type "SRMomentum(", the editor will tell you all the parameters needed.

    Best regards.

    Comment


      #3
      Hi Chris - Doh! I completely firgot - thanks!
      Regards,
      iq

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      68 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      151 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      162 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      100 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      288 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X