Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with LinReg

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

    Issue with LinReg

    I have a code something like this but unable to use method LinReg:

    // Calculate the highest high and lowest low over the past 20 bars
    double highestHigh = MAX(High, 20)[0];
    double lowestLow = MIN(Low, 20)[0];

    // Calculate the average of the highest high and lowest low
    double hllAverage = (highestHigh + lowestLow) / 2;

    // Calculate the closing price minus the average of the highest high and lowest low
    double closeMinusHllAverage = Close[0] - hllAverage;

    linreg = LinReg(closeMinusHllAverage, 20);


    I get the below error:
    The best overloaded method match for 'NinjaTrader.NinjaScript.Strategies.Strategy.LinRe g(NinjaTrader.NinjaScript.ISeries<double>, int)' has some invalid arguments CS1502
    Argument 1: cannot convert from 'double' to 'NinjaTrader.NinjaScript.ISeries<double>' CS1503
    ​​
    Attached Files

    #2
    The error is clear.

    Argument 1: cannot convert from 'double' to 'NinjaTrader.NinjaScript.ISeries<double>'

    When you call LinReg(A, B), the 'A' argument must
    be a Series<double>.

    The variable closeMinusHllAverage is a double,
    which is not the same thing as a Series<double>.

    ​-=o=-

    I think you're trying to ask for help in how to make
    the double variable closeMinusHllAverage​ into
    a Series<double> variable?

    Have you read this page?

    Comment


      #3
      Thanks for your reply. That's correct, I would like to make this work by passing a modified or dynamic way of passing this first parameter. By the way, the page that you referred here i get page not found error

      Comment


        #4
        Originally posted by csrkkalyan View Post
        the page that you referred here i get page not found error
        You're not the first person who has said that.

        I read these forums and compose all my posts in Firefox.
        [I just checked, the links work fine for me in Firefox.]

        Which version of Windows are you using?
        Which browser are you using?

        Hmm ... let me test here ...
        Surprisingly, the links do not work in Chrome -- I also
        get Page Not Found -- but look carefully at the web
        address -- on my PC, Chrome appended a bunch of
        garbage characters after 'seriest.htm'.

        Try doing some surgery on the web address, does
        the first part of the web address look ok? Delete all
        characters after 'seriest.htm' -- hopefully this will allow
        the correct web page to be shown.

        This bit of surgery worked for me.

        I have no idea how this occurs, I presume it is the NT
        forum software messing up somehow, but I can't really
        test or fix anything in these forums.

        Let me know if that helps.

        Comment


          #5
          Hello csrkkalyan,

          Thanks for your post.

          bltdavid has provided some great information on this topic.

          When passing two arguments into the LinReg() method, the first argument must be a Series<double> as noted in the syntax on the help guide.

          LinReg(ISeries<double> input, int period)[int barsAgo]

          LinReg(): https://ninjatrader.com/support/help...regression.htm

          Your variable being passed into the LinReg() method is a regular double variable, not a Series<double> so the error you mentioned occurs.

          A custom Series<double> variable would need to be created, you could assign the value you want to the Series<double> variable, then pass that variable into the LinReg() method.

          Here is a help guide page detailing creating and working with custom Series: https://ninjatrader.com/support/help...t8/seriest.htm
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            Thanks guys for your information. Did something like this and now error is gone, hope this is correct:

            First initiate the series in DataLoaded state (under OnStateChange) as

            myDoubleSeries = new Series<double>(this, MaximumBarsLookBack.Infinite);​

            and then in the OnBarUpdate:

            // Calculate the highest high and lowest low over the past 20 bars
            double highestHigh = MAX(High, 20)[0];
            double lowestLow = MIN(Low, 20)[0];

            // Calculate the average of the highest high and lowest low
            double hllAverage = (highestHigh + lowestLow) / 2;

            // Calculate the closing price minus the average of the highest high and lowest low
            double closeMinusHllAverage = Close[0] - hllAverage;

            myDoubleSeries[0] = closeMinusHllAverage;
            linreg = LinReg(myDoubleSeries, 20);​

            Comment


              #7
              Hello csrkkalyan,

              Thanks for your notes.

              Yes, that would be the correct way to pass a custom Series into the LinReg() method.

              Ensure that myDoubleSeries is being defined as a class-level variable in the script.

              For example, private Series<double> myDoubleSeries;
              <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              20 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              119 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              63 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              41 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              45 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X