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?
Because 0-1=-1
Look at how you calculate your n variable! The first barindex is 0.
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!
n variable may return 0 sometimes?
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
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!
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.
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
Yes! Thanks so much Nicolas. Going to test it now!
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!
Nope, don’t have any idea of what causing this right now.. I’m happy you get what you want though.
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 🙂