Is barindex an integer? lowest sees it differently

Forums ProRealTime English forum ProBuilder support Is barindex an integer? lowest sees it differently

  • This topic has 4 replies, 3 voices, and was last updated 1 year ago by avatarWim.
Viewing 5 posts - 1 through 5 (of 5 total)
  • #209476
    Wim

    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.

    #209500

    Try replacing line 7 with:

    #209510
    Wim

    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?

    #209513

    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:

     

     

    2 users thanked author for this post.
    #209523
    Wim

    Thank you for pointing out what I wasn’t seeing. It is so basic, but still missed it completely this time.

     

Viewing 5 posts - 1 through 5 (of 5 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login