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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        67 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        150 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        162 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        99 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        287 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X