Error in Highest[n](high)

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #5899 quote
    Adolfo
    Participant
    Senior

    Hi everyone!

    I’m getting this error when trying to set up one variable at Highest.

    REM Reset Januaty 1st
    lastyear = year-year[1]
    IF lastyear>=1 then
    maximo = Dopen(0)
    minimo = Dopen(0)
    velaapertura = Barindex
    endif
    
    velaactual = Barindex
    
    n=velaactual-velaapertura // 1,2,3...etc.
    
    IF Close>maximo then
    maximo=Highest[n](high)
    contador=contador+1
    endif
    IF Close<minimo then
    minimo = Lowest[n](low)
    contador=contador-1
    endif
    
    return contador

    If I set up n=1,2,3… etc is working ok.

    Result of “n” calculation is 1,2,3.. but getting this error alert: “Integer positive expected on HIGHEST”

    Any ideas?

    #5901 quote
    Nicolas
    Keymaster
    Master

    Because 0-1=-1

    Look at how you calculate your n variable! The first barindex is 0.

    #5902 quote
    Adolfo
    Participant
    Senior

    Thanks Nicolas, I tryed different ways to calculate “n”.

    n=abs(velaactual-velaapertura) // 1,2,3...etc
    n=velaactual-velaapertura 
    // OR
    n=velaapertura-velaactual

    Getting the same error in all cases, it says that “n” should be an integer positive.
    Return n is showing 1,2,3… so… is an integer, is positive… I can’t get the point :/

    Cheers!

    #5903 quote
    Nicolas
    Keymaster
    Master

    n variable may return 0 sometimes?

    #5904 quote
    Adolfo
    Participant
    Senior

    Yes, you are right! but still the same.

    velaapertura=Barindex-1

    At this point first result is 1 instead 0, but still the same error, here the code updated:

    REM Reset Januaty 1st
    lastyear = year-year[1]
    IF lastyear>=1 then
    maximo = Dopen(0)
    minimo = Dopen(0)
    velaapertura = Barindex-1
    endif
    
    velaactual = Barindex
    n=velaactual-velaapertura
    //n=5 //
    
    IF Close>maximo then
    maximo=Highest[n](high)
    contador=contador+1
    endif
    IF Close<minimo then
    minimo = Lowest[n](low)
    contador=contador-1
    endif
    
    return contador
    #5911 quote
    Nicolas
    Keymaster
    Master

    Just tried to solve this issue. I’m stuck here too 🙂 Sunday evening you know …

    In intraday your n variable still returns negative values though.

    Maybe you could explain me better what you want to do with this code? I would be more helpful!

    #5915 quote
    Adolfo
    Participant
    Senior

    Thanks Nicolas!

    I wanna set “n” as the result of the current bar minus the first bar (in this case January 1st bar) so, in January 15th the result of (n=currentbar-firstbar) should be “15” and set “n” (Highest[n](high) or Lowest[n](low) as 15.

    The point here is to get the maximum and minimum prices of the current year from variables Highest and Lowest. But.. Maybe there is a short and  easy way to find this, Like Dhigh…. I’m confused also…

    Thanks a lot again for your time Nicolas.

    #5922 quote
    Nicolas
    Keymaster
    Master

    Oh I see now 🙂

    Is this what you are trying to do? :

    once hh = high
    once ll = low
    
    //reset each year
    if year<>year[1] then
     hh = high
     ll = low
    endif
    
    //which value is max or min?
    hh = MAX(hh,high)
    ll = MIN(ll,low)
    
    RETURN hh,ll
    #5933 quote
    Adolfo
    Participant
    Senior

    Yes! Thanks so much Nicolas. Going to test it now!

    #5936 quote
    Adolfo
    Participant
    Senior

    Perfect but… Do we know, why, “n”, is not able no be at “Highest[n]”?

    Or should be an exact number and not a result?

    Fixed with your code but still thinking about it.

     

    Cheers!

    #5938 quote
    Nicolas
    Keymaster
    Master

    Nope, don’t have any idea of what causing this right now.. I’m happy you get what you want though.

    #8713 quote
    Adolfo
    Participant
    Senior

    Finally I thinkl I know what the problem is, and with your help and working together with RICHARDYUSTE, we realize we were getting “0” as first result, that was the problem. First result is “1” but Barindex was “0” sometime… Seems to be ok now.  🙂

    Best trading ever 🙂

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Error in Highest[n](high)


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Adolfo @adolfo_onrubia Participant
Summary

This topic contains 11 replies,
has 2 voices, and was last updated by Adolfo
9 years, 8 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/24/2016
Status: Active
Attachments: No files
Logo Logo
Loading...