Error A positive integer field is expected

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #161869 quote
    dbl007dbl007
    Participant
    Junior

    I got the Calculation error: ‘Error in the indicator… A positive integer field is expected with Count’

    Decrease = Close < Close[1]
    Count = 0
    FOR i = 1 TO BarIndex DO
     IF Decrease[Count] THEN
      Count = Count - 1
     ELSE
      BREAK
     ENDIF
    NEXT
    RETURN Count
    

    I have to re-code it as

    Decrease = Close < Close[1]
    Count = 0
    FOR i = 1 TO BarIndex DO
     IF Decrease[Count] THEN
      Count = Count + 1
     ELSE
      BREAK
     ENDIF
    NEXT
    n = 0 - Count
    RETURN n

    Why ?

    #161877 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    If you discovered how to work it out correctly it’s because you got the hang of it!

    #161886 quote
    VonasiVonasi
    Moderator
    Master

    You answered your own question. If a negative integer is not allowed then don’t use one and use a positive one that is allowed instead!

    #161900 quote
    NicolasNicolas
    Keymaster
    Legend

    Because COUNT variable is sometimes negative! 😉 Not possible to use a variable with a negative offset!

    Decrease[-1] will flash that error.

    #161925 quote
    dbl007dbl007
    Participant
    Junior

    Haha. Now I realized my mistake. I copy this example somewhere without realizing that it use the Count to index. I ‘assume’ it use the variable i to index.

    The correct code should be

    Decrease = Close < Close[1]
    Count = 0
    FOR i = 0 TO BarIndex - 1 DO
     IF Decrease[i] THEN
      Count = Count - 1
     ELSE
      BREAK
     ENDIF
    NEXT
    
    RETURN Count

    I learn the danger pf copy/paste code.

    Thks everyone for taking interest and interesting comments.  Cheers.

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Error A positive integer field is expected


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
dbl007 @dbl007 Participant
Summary

This topic contains 4 replies,
has 4 voices, and was last updated by dbl007dbl007
5 years, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 02/18/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...