Simple range match formula

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #204852 quote
    robdav
    Participant
    Veteran

    Hi

    This should be simple, but I can’t work out how to do it!

    I’m trying to compare one value to another. Sometimes they are the same but sometimes there can be a difference of one, two or three…. so I need a formula along the lines of the below code. However, if the value can be different by 3 then that should also allow a difference of 1, 2 or 3 not just 3 if that makes sense?

    Many thanks for any help.

    Rob

    testsize = 3
    
    if ((value1 = (value2 - testsize)) or (value1 = (value2 + testsize))) then
    backgroundcolor("red",50)
    endif
    #204858 quote
    JS
    Participant
    Senior

    Hi @robdav

    Do you mean something like that…?

    Value1 = 3
    Value2 = 0
    
    xDiff = ABS(Value1 - Value2)
    
    If xDiff=1 then
    BackGroundColor(255,0,0)
    ElsIf xDiff=2 then
    BackGroundColor(0,255,0)
    ElsIf xDiff=3 then
    BackGroundColor(0,0,255)
    EndIf
    
    Return
    
    robdav thanked this post
    #204861 quote
    robdav
    Participant
    Veteran

    Hi @JS

    Not quite. Let me try another example.

    Let’s say value1 = 104

    I want to compare it to another value (value2), if I allow a difference of three then value2 could be

    101, 102, 103 – 104- 105, 106, 107

    or difference of 1 to value2 could be

    103 – 104 – 105

    Obviously both value1 and value2 are variables.

    Does that make more sense?

    Thanks, Rob

    #204862 quote
    JS
    Participant
    Senior

    Hi @robdav

    Try this…

    Value1 = 104
    Value2 = 106
    
    TestValue = 3
    
    For i = 1 to TestValue
    If Value2 = Value1 + i or Value2 = Value1 - i then
    BackGroundColor(255,0,0)
    Break
    EndIf
    Next
    
    Return
    robdav thanked this post
    #204864 quote
    robdav
    Participant
    Veteran

    Thanks @JS, it looks like it should work, I will test it tomorrow and confirm.

    JS thanked this post
    #204872 quote
    JS
    Participant
    Senior

    Hi @robdav

    Use “For i=0 to TestValue”

    Then you will also test whether Value2 is equal to Value1…

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

Simple range match formula


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
robdav @robdav Participant
Summary

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

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 11/26/2022
Status: Active
Attachments: No files
Logo Logo
Loading...