I am having some problems with Lowest and Highest functions in my indicator. Every now and then the indicator crashes with the error message that Lowest (or Highest) requires a positive integer as parameter. So i wrote some lines to test this further and find the culprit. And . . . the culprit seems to be “barindex”. The code passes the variable numberBars, being the difference between actual bar and a historic bar, to the function Lowest. When I supply the bar numbers of these 2 bars myself to Lowest, no problem. When I ask the indicator to calculate the numberBars as the difference of “barindex – historicbarindex”, pang, error message, indicator wiped of the chart. I tried to rescue the situation by adding Floor(substraction,0) to the code. But Lowest stubbornly interprets this numberBars also as a non-integer. What am I missing here?
My test was on the DAX 1 minute chart this morning, at barindex 1503. With the line currentIndex=barindex as comment, it returns 1503 and 103 as barindex and 103 as numberBars (screenshot 1). When I uncomment the line, the indicator crashes (screenshot 2).
Thanks for helping me out here.
First set currentIndex to value of actual bar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// WM-LowestHighest
//
startIndex=1400
currentIndex=1503
//currentIndex = barindex // un-comment for testing with barindex instead of fixed value
Thanks Roberto. But that was how I started. I added the Floor-trick hoping that would definitely make numberBars an integer. To me it’s an integer, but not to Lowest and Highest. Next tip?
When you use currentIndex = barindex, for any bar in history lower than or equal to your startindex=1400, then your numberbars= currentIndex – startIndex is negative, or at best, zero (with or without floor, doesn’t matter it’s not about the decimals), and it is prevented by the error message because it makes no sense to use a negative parameter for lowest or highest, even if its absolute value is an integer, it has to be a positive number of candles. You can fix it by not calculating lowest/highest as long as numberBars is negative or 0 with:
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue