Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How/When do you pass PriceSeries<double>, ISeries<double> or Series<double>,

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

    How/When do you pass PriceSeries<double>, ISeries<double> or Series<double>,

    Hi, I am porting DoubleStochasticOptimized over to NT8.

    I pretty much figured out the conversion from DataSeries to NT8 Series<double> use, but just want to clarify what we use the following for:

    ISeries<double> or Series<double>:

    Definition:
    private Series<double> p1;

    State == State.Configure:
    p1 = new Series<double>(this);

    OnBarUpdate():
    p1[0] = 2.0;

    Passing this to a method (passing by reference so I can update in the method):
    K[0] = DoubleStochasticsOptimized(ref p1, ref p2, ref p3, ref kEMA, ref pEMA, Highs, Times;

    Definition at the method:
    public double tDoubleStochasticsOptimized(ref Series<double> p1, ref Series<double> p2, ref Series<double> p3, ref JMA kEMA, ref JMA pEMA, ISeries<double> dHighs, TimeSeries<DateTime> dTimes)

    QUESTION 1: Is the use of Series<double> correct?

    QUESTION 2: Passing in Highs[0] to a method (see above, not by reference):
    - How do you declare the method to receive the Series<double>? (IE: I tried PriceSeries<double>, and ISeries<double> and these return errors).

    QUESTION 3: Passing in Times[0] to a method (see above, not by reference):
    - How do you declare the method to receive the TimeSeries<DateTime>? (IE: I tried TimeSeries<DateTime>, and ISeries<DateTime> but these return errors).

    Thanks in advance

    #2
    Question 1: Yes this the correct way to do this. ISeries is the interface for all the other series that can be done. Series<T> is the generic form in this case.

    Question 2 & 3: What is the error you are receiving?

    Comment


      #3
      Originally posted by Calonious View Post
      Question 2 & 3: What is the error you are receiving?
      1) here is the error, trying to pass using PriceSeries<double> dHighs:
      K[0] = tDoubleStochasticsOptimized(ref p1, ref p2, ref p3, ref kEMA, ref pEMA, Highs);

      and method:
      public double tDoubleStochasticsOptimized(ref Series<double> p1, ref Series<double> p2, ref Series<double> p3, ref JMA kEMA, ref JMA pEMA, PriceSeries<double> dHighs)

      The non-generic type 'NinjaTrader.NinjaScript.PriceSeries' cannot be used with type arguments.

      2) here is the error, trying to pass using Series<double> dHighs:
      K[0] = tDoubleStochasticsOptimized(ref p1, ref p2, ref p3, ref kEMA, ref pEMA, Highs);

      and method:
      public double tDoubleStochasticsOptimized(ref Series<double> p1, ref Series<double> p2, ref Series<double> p3, ref JMA kEMA, ref JMA pEMA, Series<double> dHighs)

      I get a "best overload method mismatch" (too long to type).

      I attached my code (uncomment the line at 85 to call the method).
      Attached Files

      Comment


        #4
        Took a look at it and then followed up on their documentation.

        You can pass a PriceSeries such as High through a method but you need to use ISeries<double> as that is how the PriceSeries are structured. If you make a custom Series<T> you then need to use the same type structure as you are passing through as well. So, if you have a Series<bool> object you need to use that as your method parameter as well.

        Take a look a the documentation for the ISeries<T> under the Common section. This should help explain further.

        I reattached the code for you as well.
        Attached Files

        Comment


          #5
          Hi Calonious, thank you very much again. You are a real asset to this community!

          I have got this to work, although I think it looks slightly different than in NT7 which I will verify.

          I am confused on one thing though.

          K[0] = DoubleStochasticsOptimized( ref p1, ref p2, ref p3, ref kEMA1, ref pEMA1, High, Low, Close, Period);

          on calling the method, You had changed HIGHS to HIGH. I had thought that the HIGHS is the SERIES of doubles, and HIGH was a SINGLE double.

          In the method, you defined it as ISeries<double> dHighs and I can reference the series of highs

          QUESTION: Why didn't you specify HIGHS vs HIGH when you passed this to the function?


          public double DoubleStochasticsOptimized(ref Series<double> p1, ref Series<double> p2, ref Series<double> p3, ref JMA kEMA, ref JMA pEMA, ISeries<double> dHighs, ISeries<double> dLows, ISeries<double> dCloses, int dStochPeriod)
          {

          // Print ("in DS P1: <" + p1[0] + ">, dHighs[1] = <" + dHighs[1] + ">" );

          double r = MAX(dHighs, dStochPeriod)[0] - MIN(dLows, dStochPeriod)[0];
          // Print ("past r: <" + r + ">" );

          p1[0] = ((dCloses[0] - MIN(dLows, dStochPeriod)[0]) / (r == 0 ? 1 : r)) * 100;
          // Print ("P1: <" + p1[0] + ">" );

          pEMA = JMA(p1,5,100);
          p2[0] = pEMA[0];
          // Print ("P2: <" + p2[0] + ">" );

          double s = MAX(p2, dStochPeriod)[0] - MIN(p2, dStochPeriod)[0];
          // Print ("s: <" + s + ">" );

          p3[0] = ((p2[0] - MIN(p2, dStochPeriod)[0]) / (s == 0 ? 1 : s)) * 100;
          kEMA = JMA(p3,3,-50);
          // Print ("P3: <" + p3[0] + ">, kEMA[0] <" + kEMA[0] + ">" );
          // K[0] = kEMA[0];
          //Print ("MFDoubleStochasticsOptimized: <" + kEMA[0] + ">" );
          return (kEMA[0]);
          }
          Attached Files

          Comment


            #6
            More than likely just a spelling error on my end. I didn't put any meaning behind it.
            As just the method parameter name you use anything like - 'HiGhS' but for continuity and ease of use throughout your code you would want to make it look viable like using 'high'

            I had thought that the HIGHS is the SERIES of doubles, and HIGH was a SINGLE double.
            High is the single series of the primary instrument on the chart.

            Highs is multiple series of High from the number of Instruments/Data Series you add to the script

            When referencing a single value from either it will look like this respectively -

            High[0] - CurrentBar Value of the primary
            Highs[1][0] - CurrentBar value of the secondary series

            However, you can use just Highs[1] to reference the exact ISeries you want to pass through your method.

            Hope this helps.

            Comment


              #7
              Hello DaFish,

              Thanks for your posts.

              Thanks to Calonious for his correct responses.
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Passing ISeries&lt;DateTime&gt; tTime to a method - error

                Hi. for the life of me I can't figure this out... I got the ISeries<double> to work, by passing in Low (or Lows[0]) and receiving this on the method as an ISeries<double>. When I go to do the exact same thing with ISeries<DateTime>, I get a overload error and I have no idea what I am doing wrong. Please help.

                if(BarsInProgress == 0)
                {
                MFTestSeries (Time);
                }
                }

                public bool MFTestSeries (ISeries<DateTime> tTime)

                {
                bool retval = false;

                Print ("MFTestSeries: time <" + tTime[0].ToString() + ">");

                return (retval);

                }
                Attached Files

                Comment


                  #9
                  "Time" is a TimeSeries

                  Code:
                  public bool MFTestSeries ([B]TimeSeries [/B]tTime)
                  {
                  	bool retval = false;
                  
                  	Print ("MFTestSeries: time <" + tTime[0].ToString() + ">");
                  
                  	return (retval);
                  }
                  If you want it to accept an Series<DateTime>, which is your own custom type series you could throw special DateTime objects into, you must construct the Series<DateTime> and assign the values as you need. If you're just going to use the TimeSeries Time[] provided, there's not really any need to do a custom series, but here is how that will work:

                  Code:
                  private Series<DateTime> myTime;
                  
                  protected override void OnStateChange()
                  {
                  	if (State == State.SetDefaults)
                  	{		
                  		Name    = "MyCustomIndicator";			
                  	}
                  	else if (State == State.Configure)
                  	{
                  		myTime = new Series<DateTime>(this);
                  	}
                  }
                  
                  protected override void OnBarUpdate()
                  {
                  	// only add a date time that matches my criteria
                  	if(SomeTimeCondition)
                  		myTime[0] = Time[0];		
                  	
                  	MFTestSeries (myTime);
                  }			
                  
                  public bool MFTestSeries (Series<DateTime> tTime)
                  {
                  	bool retval = false;
                  
                  	Print ("MFTestSeries: time <" + tTime[0] + ">");
                  
                  	return (retval);			
                  }
                  Also, just a quick tip, you no longer need to convert special types .ToString() in Print(). Just using Print(Time[0]) will do since Print() just accepts a generic object value and will convert to string for you.
                  MatthewNinjaTrader Product Management

                  Comment


                    #10
                    Thanks so much Matthew.

                    Just to make sure I have the others correct and I don't have to keep coming back. Please check these and correct if needed... I didn't really know when to use ISeries<double> or Series<double> - both worked...

                    MFTestSeries (Time);
                    public bool MFTestSeries (TimeSeries tTime)

                    MFTestSeries (Low); (or High, or Highs[0].....
                    public bool MFTestSeries (ISeries<double> tLows)

                    MFTestSeries (Volume);
                    public bool MFTestSeries (VolumeSeries tVolume)

                    MFTestSeries (CCI(6));
                    public bool MFTestSeries (Series<double> tCCIData) (note: NOT using ISeries<double)

                    Please confirm

                    Comment


                      #11
                      Yes, that will work.

                      However the last one might be unnecessary (depending on what you're doing with it within the method). If you made just one ISeries<double> it can accept both the provided PriceSeries objects, as well as any custom data series (an indicator, or your down Series<double> in your class).

                      Code:
                      // accepts a price series and a custom series (indicator)
                      public bool MFTestSeries (ISeries<double> tLow)
                      {
                      	return true;	
                      }
                      If you made it a Series<double>, your methods would only accept a custom series objects/indicators, but NOT any price serie
                      Code:
                      // ONLY accepts a custom series (indicator)
                      public bool MFTestSeries (Series<double> tCCIData)
                      {
                      	return true;
                      }
                      MatthewNinjaTrader Product Management

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by arvidvanstaey, Today, 02:19 PM
                      4 responses
                      11 views
                      0 likes
                      Last Post arvidvanstaey  
                      Started by samish18, 04-17-2024, 08:57 AM
                      16 responses
                      60 views
                      0 likes
                      Last Post samish18  
                      Started by jordanq2, Today, 03:10 PM
                      2 responses
                      9 views
                      0 likes
                      Last Post jordanq2  
                      Started by traderqz, Today, 12:06 AM
                      10 responses
                      18 views
                      0 likes
                      Last Post traderqz  
                      Started by algospoke, 04-17-2024, 06:40 PM
                      5 responses
                      47 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Working...
                      X