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

Use of ISeries<double> as Input

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

    Use of ISeries<double> as Input

    Dear Support,

    Using an ISeries double as input to MAX generates CS1502 and CS1503 errors. What is the proper code for use an ISeries<double> as input to MAX?

    Code:
    double Vrg = SMA(Volume, Period)[0];
    double Vro = (Volume[0] / Vrg);
    double Vmax = MAX(Vro, Period);
    Many thanks.

    #2
    Vro is not an ISeries.

    Did you try,
    Code:
    double Vmax = Math.Max(Vro, Period);

    Comment


      #3
      Originally posted by bltdavid View Post
      Vro is not an ISeries.

      Did you try,
      Code:
      double Vmax = Math.Max(Vro, Period);
      Thanks, but totally two different things.
      Math.Max() finds the highest of two values whereas MAX() finds the highest value of a series over a period.
      Last edited by aligator; 05-10-2019, 11:41 AM.

      Comment


        #4
        Hello aligator,
        Thanks for your post.

        You need to use a Series as an input. In your snippet "Vro" is not a series, it's a simple variable.

        Also, make sure to add the index your are checking from at the end of MAX()

        Code:
        double Vrg = SMA(Volume, Period)[0];
        Vro[0] = (Volume[0] / Vrg);
        double Vmax = MAX(Vro, Period)[0];
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_JoshG View Post
          Hello aligator,
          Thanks for your post.

          You need to use a Series as an input. In your snippet "Vro" is not a series, it's a simple variable.

          Also, make sure to add the index your are checking from at the end of MAX()

          Code:
          double Vrg = SMA(Volume, Period)[0];
          Vro[0] = (Volume[0] / Vrg);
          double Vmax = MAX(Vro, Period)[0];
          Thanks Josh. Here is the code and (I think) I am using a Series as input. But still getting the same error. I must be overlooking something.

          Code:
          namespace NinjaTrader.NinjaScript.Indicators
          {
              public class ET : Indicator
              {
                  private Series<double>        Vro;
                  private SMA                    Vrg;
                  private MAX                    Vmax;
                  private MIN                  Vmin;
          
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          Description                    = @"";
                          Name                        = "ET";
                          IsSuspendedWhileInactive    = true;
                          Period                        = 40;
          
                          AddPlot(new Stroke(Brushes.Orange, 4), PlotStyle.Bar, "Value");
                          AddLine(Brushes.SlateBlue,    0,    NinjaTrader.Custom.Resource.NinjaScriptIndicatorZeroLine);
                      }
          
                      else if (State == State.DataLoaded)
                      {
                          Vro        = new Series<double>(this);
                          Vrg     = SMA(Volume, Period);
                      }            
                  }
          
                  protected override void OnBarUpdate()
                  {
                      if (CurrentBar < Period)
                              return;
          
                      // ET parameters and Plots
                      double Vrg    = SMA(Volume, Period)[0];
                      Vro[0]        = (Volume[0] / Vrg);
                      double Vmax    = MAX(Vro, Period);
                      double Vmin    = MIN(Vro, Period);
          
                      Value[0]     = (Vro - Vmin) * 100 / (Vmax - Vmin);
          
                  }
          
                  #region Properties
          
                  [Browsable(false)]
                  [XmlIgnore()]
                  public Series<double> Value
                  {
                      get { return Values[0]; }
                  }    
          
                  [Range(1, int.MaxValue), NinjaScriptProperty]
                  [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
                  public int Period
                  { get; set; }
                  #endregion
              }
          }

          Comment


            #6
            aligator,

            You are overlooking the index for MAX() and MIN() similar to my sample.

            Code:
             double Vmax = MAX(Vro, Period)[SIZE=18px][B][0][/B][/SIZE];
            You can use any index you require for your logic, but if you want the Period to be calculated from the most recent bar you need to use a BarsAgo of 0
            Josh G.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_JoshG View Post
              aligator,

              You are overlooking the index for MAX() and MIN() similar to my sample.

              Code:
              double Vmax = MAX(Vro, Period)[SIZE=18px][B][0][/B][/SIZE];
              You can use any index you require for your logic, but if you want the Period to be calculated from the most recent bar you need to use a BarsAgo of 0
              Josh,

              Thanks a bunch!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by trilliantrader, 04-18-2024, 08:16 AM
              5 responses
              22 views
              0 likes
              Last Post trilliantrader  
              Started by Davidtowleii, Today, 12:15 AM
              0 responses
              3 views
              0 likes
              Last Post Davidtowleii  
              Started by guillembm, Yesterday, 11:25 AM
              2 responses
              9 views
              0 likes
              Last Post guillembm  
              Started by junkone, 04-21-2024, 07:17 AM
              9 responses
              70 views
              0 likes
              Last Post jeronymite  
              Started by mgco4you, Yesterday, 09:46 PM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X