Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Methods other than MAX()/MIN() and HighestBar()/LowestBar() that use regular Doubles?

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

    Methods other than MAX()/MIN() and HighestBar()/LowestBar() that use regular Doubles?

    I'm looking for a Method for MAX()/MIN(), and/or HighestBar()/LowestBar() that uses regular doubles instead of ISeries<double> or will accept both. MAX()/MIN(), and HighestBar()/LowestBar() won't let you use regular doubles. I don't have that much experience with writing methods or using for loops. Does Ninja Script have a method for MAX or Highest price that will except regular doubles? Here is an example of my code. As you can see, MAX() and HighestBar will only take a ISeries<double>


    if(CurrentBar < MaxLookBack)
    return;

    int Multiplier = 10;

    double maxRange = MAX(High, MaxLookBack)[0] - MIN(Low, MaxLookBack)[0];
    double tickOffSet = TickSize * Multiplier;
    double theHashLine = MAX(High, MaxLookBack)[0] - maxRange - tickOffSet;


    HashLine[0] = fibLine;

    double highestHash0 = MAX(theHashLine, MaxLookBack)[0]; //get an error
    double highestHash1 = HighestBar(theHashLine, MaxLookBack); //get an error
    Last edited by jamestrader21x; 11-04-2021, 07:35 AM.

    #2
    Hi James, thanks for posting.

    The maximum and minimum need multiple values to evaluate a number to be the maximum or minimum out of all of them. If there is only one double value then there would be nothing else to compare against. There is a discussion here about getting a max value from a List<double>:

    https://stackoverflow.com/questions/...rom-listmytype (publicly available)

    Best regards,
    -ChrisL

    Comment


      #3
      In my example, I want to compare the highest HashLine[0] (which is an MA) vs future plots that may be lower than it. What I'm trying to code is, if future plots are lower than the highest plot, then set the current plot to price of highest plot. However, I can't use regular doubles with with MAX()/MIN(), or HighestBar()/LowestBar(). They will only take ISeries<double>. So, I didn't get that far to make a comparison. Since I don't have much experience with writing code for for loops and/or methods, I wanted to know if Ninja Script 8 has any other look back Methods that will accept regular doubles.

      if(CurrentBar < MaxLookBack)
      return;

      int Multiplier = 10;

      double maxRange = MAX(High, MaxLookBack)[0] - MIN(Low, MaxLookBack)[0];
      double tickOffSet = TickSize * Multiplier;
      double theHashLine = MAX(High, MaxLookBack)[0] - maxRange - tickOffSet;


      HashLine[0] = fibLine;

      double highestHash0 = MAX(theHashLine, MaxLookBack)[0]; //get an error
      double highestHash1 = HighestBar(theHashLine, MaxLookBack); //get an error

      Comment


        #4
        HI James, thanks for clarifying.

        You can keep track of the highest value in OnBarUpdate:

        private highestDouble = -1;
        OnBarUpdate:
        if(newDouble > highestDouble)
        highestDouble = newDouble;

        Since you are waiting on future values, the min or max methods can not be used and you need to monitor and save the new values as they come in.

        Best regards,
        -ChrisL

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        563 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        329 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X