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

Compiler claims method has invalid argument

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

    Compiler claims method has invalid argument

    I tried writing my own method so I don't have redo the formula over and over again in the future. The method definition and use is colored in green.

    Compiler errors:
    1) Best overloaded method match for ('...Skewed') has some invalid arguments.
    2) Argument '2': cannot convert from double to DataSeries

    My confusion:
    1) The argument closeOpen is a DataSeries value
    2) The argument closeOpen is a DataSeries value

    How do I supply the correct argument for distVal in method Skewed?

    protected override void OnBarUpdate()
    {
    closeOpen.Set(Close[
    0] - Open[0]);
    if (CurrentBar >= barLookBack)
    Skewness.Set( Skewed(barLookBack, closeOpen[0]) [0] ); // The compiler errors are on this line
    }

    public DataSeries Skewed(int lookBack, DataSeries distVal)
    {
    distribution.Set(distVal[
    0]);
    if (CurrentBar >= lookBack)
    {

    xBar.Set(SMA( distribution , lookBack)[
    0]);
    sDev.Set(StdDev(distribution, lookBack)[
    0]);

    double sumofDistribution = 0;
    for (int i = 0; i <= lookBack; i++)
    {
    sumofDistribution = Math.Pow(distribution[i] - xBar[
    0], 3) + sumofDistribution;
    }

    returnVal.Set(
    1 / ( (lookBack - 1) * Math.Pow(sDev[0], 3) ) * sumofDistribution);

    return returnVal;
    }

    elsereturn returnVal ;
    }

    #2
    Someone will review this on Monday.
    RayNinjaTrader Customer Service

    Comment


      #3
      Hey tex,

      Why don't you just return a double value rather than a dataseries. I think you problem is that you're trying to .Set a specific cell in the dataseries with an entire dataseries, rather than .Set a specific cell with a value.
      mrlogik
      NinjaTrader Ecosystem Vendor - Purelogik Trading

      Comment


        #4
        Originally posted by mrlogik View Post
        Hey tex,

        Why don't you just return a double value rather than a dataseries. I think you problem is that you're trying to .Set a specific cell in the dataseries with an entire dataseries, rather than .Set a specific cell with a value.
        mrlogik,

        Thanks again for the reply. What I'm trying to do is supply the formula in the method. Right now I measure the skew of distribution of the Close - Open. But I might also want to look at the skew of the High - Close.

        I tried changing the method from DataSeries to double but still get the same compiler error codes.

        I can't think of a way to supply the forumla in the method, regardless if it returns a double or DataSeries value.

        The part in red generates the error.

        Skewness.Set( Skewed(barLookBack, closeOpen[0] ) [0] );

        Comment


          #5
          you're function takes an input of DataSeries type, yet closeOpen[0] is not a DataSeries, but rather a specific value. That is why that is not working. IF you change it to a double, you will supply the formula in the method. You can do it either way it just changes the syntax, and changes the protability of the function.

          Also, what is returnval? Where are these parameters defined?

          Having the CurrentBar >= check in both the OnBarUpdate and Skew function is redundant. I only say this because it complicates the code to have excess code.
          mrlogik
          NinjaTrader Ecosystem Vendor - Purelogik Trading

          Comment


            #6
            What I'm not understanding is how closeOpen is not a DataSeries. To measure a distribution, I need 300 separate data points linked to individual bars. How is it possible to return a double value if it's a data series? What am I misunderstanding?

            Also, what is returnval? Where are these parameters defined?
            Let me defer this question for later. The coding error must be related to some concept that I don't understand. Once I understand how I can use a double value to calculate a dataseries, I'll rewrite the method.

            The duplicate code has been removed.

            Comment


              #7
              If you have the [0], you're passing a specific point of the dataseries.
              If you don't have the [0], you're passing the entire dataseries.
              mrlogik
              NinjaTrader Ecosystem Vendor - Purelogik Trading

              Comment


                #8
                I simplified the code as much as possible to replicate the error. That helped me pinpoint what I did wrong with the dataseries and specific reference point. I think I owe you a beer, logik.

                This is my final code:

                protected override void OnBarUpdate()
                {
                closeOpen.Set(Close[
                0] - Open[0]);
                Skewness.Set(Skewed(barLookBack , closeOpen));
                }

                public double Skewed( int lookBack , DataSeries distribution )
                {
                if (CurrentBar >= barLookBack)
                {
                xBar.Set(SMA(distribution,lookBack)[
                0]);
                sDev.Set(StdDev(distribution, lookBack)[
                0]);

                double sumofCloseOpen = 0 ;
                for (int i = 0 ; i <= lookBack; i++)
                {
                sumofCloseOpen = Math.Pow(distribution[i] - xBar[
                0], 3) + sumofCloseOpen ;
                }

                return (1 / ( (lookBack - 1) * Math.Pow(sDev[0], 3) ) * sumofCloseOpen);
                }
                else return 0 ;
                }
                Last edited by texasnomad; 10-26-2008, 02:04 PM.

                Comment


                  #9
                  Well done.

                  Always comment your code.
                  Always keep things simple.
                  mrlogik
                  NinjaTrader Ecosystem Vendor - Purelogik Trading

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by wzgy0920, 04-20-2024, 06:09 PM
                  2 responses
                  26 views
                  0 likes
                  Last Post wzgy0920  
                  Started by wzgy0920, 02-22-2024, 01:11 AM
                  5 responses
                  32 views
                  0 likes
                  Last Post wzgy0920  
                  Started by wzgy0920, Yesterday, 09:53 PM
                  2 responses
                  49 views
                  0 likes
                  Last Post wzgy0920  
                  Started by Kensonprib, 04-28-2021, 10:11 AM
                  5 responses
                  191 views
                  0 likes
                  Last Post Hasadafa  
                  Started by GussJ, 03-04-2020, 03:11 PM
                  11 responses
                  3,230 views
                  0 likes
                  Last Post xiinteractive  
                  Working...
                  X