Increment a Value Failure – Infinite Loops

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #74307 quote
    JonnyBoy
    Participant
    New

    Hi Everybody,

    I’ve used the forum as a guest for a long time but first post.

    I am trying to build an indicator that increments a value everytime (eachbar) that the IF statement is TRUE and de-increments the value on each bar it is FALSE.

    So for example if the condition had been TRUE for 5 bars the value would equal 5, then if the next bar was FALSE value = 4 and so on.

    Attempt 1 – using IF statements:

    IF LOW > LowPointave THEN
    LowAdd = LowAdd + 1 
    ELSE
    LowAdd = LowAdd - 1
    ENDIF

    Result was the indicator just flipped between 1 and -1.

     

    Attempt 2 – Using Loops

    IF LOW > LowPointave THEN
    i = 1
    ELSE
    i = 0
    ENDIF
    
    LowAdd = 0
    WHILE i = 1 DO
    LowAdd = LowAdd + 1 
    WEND
    

     

    Result – “An infinite loop or loop with too many iterations was detected….”

     

    What does this mean and is there any way I can meet my goal?

     

    Thanks kindly ,

     

    Jon

    #74308 quote
    Vonasi
    Moderator
    Master

    Your first example works. I tested this:

    LowPointave = average[200](low)
    
    IF LOW > LowPointave THEN
    LowAdd = LowAdd + 1
    ELSE
    LowAdd = LowAdd - 1
    ENDIF
    
    return lowadd

    and got this:

    [attachment file=74309]

    So it must be whatever your LowPointAve is that is the problem.

    Screenshot_1-12.png Screenshot_1-12.png
    #74322 quote
    Nicolas
    Keymaster
    Legend

    You are stuck in the loop between lines 4 and 8,  it will never break because your variable i remains 1 infinitely…

Viewing 3 posts - 1 through 3 (of 3 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

Increment a Value Failure – Infinite Loops


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
JonnyBoy @spammywammy Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by Nicolas
8 years, 2 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 06/25/2018
Status: Active
Attachments: 1 files
Logo Logo
Loading...