Compare Close to +0.1 through to 0.9 and -0.1 through to -0.9 of a variable

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

    Hi

    I want to be able to evaluate the close value of a candle to see if it matches another variable.

    For example, let’s say the close value of a candle is 12,347.0 and I have a level called sup1 at 12,347.8 that I care about. How can I match these to decimal points?

    I don’t want to just ROUND the Close and sup1 (which in this case wouldn’t work as 12,347 would not match 12,348) Even if ROUND did get close, I want to evaluate the decimal points.

    If Close = sup1+0.1 OR Close = sup1+0.2 OR Close = Sup1+0.3 …….. OR close = sup1-0.1 OR close = Sup1-0.2 OR Close = Sup1-0.3 ……. THEN DRAWHLINE(sup1)coloured(0,200,0)

    I’m struggling to get the comparison working.

    Thanks

    Rob

    #69543 quote
    robdav
    Participant
    Veteran

    Any pointers from anyone please?

    Thanks

    Rob

    #69547 quote
    robertogozzi
    Moderator
    Master

    Thos will allow you to validate CLOSE as “touching the line” when it is within a 0.3-pip range below or above it:

    IF close >= Sup1 - (0.3 * pipsize) AND close <= Sup1 + (0.3 * pipsize) THEN....
    robdav thanked this post
    #69624 quote
    robertogozzi
    Moderator
    Master

    You can create a function-like indicator, like this one (I also attach the .ITF file to be imported), which needs to be installed by ProBuilder but shouldn’t added to charts, just kept within ProBuilder itself to be called by strategies:

    //////////////////////////////////////////////////////////////////////////////////////////////
    //                             MyRange
    //
    // indicator to be installed with ProBuilder and be called by strategies
    //
    // input:
    //        x = number to be checked against a range
    //        y = base to define a range (+/- z)
    //        z = range within which x will be validated or not
    //
    // returns:
    //        0 = x is NOT within range z
    //        1 = x is within above said range
    //
    IF x >= (y - z) AND x <= (y + z) THEN
       Result = 1     //X is within range y-z through y+z
    ELSE
       Result = 0     //X is not within the above said range
    ENDIF
    RETURN Result
    //////////////////////////////////////////////////////////////////////////////////////////////
    

    This is a stupid strategy just to test it:

    //////////////////////////////////////////////////////////////////////////////////////////////
    //                             MyStrategy
    //
    x  = close
    y  = close + (0.3 * pipsize)
    z  = 0.5 * pipsize
    a  = CALL MyRange[x,y,z]    //     true
    //
    x1 = close
    y1 = close - (0.6 * pipsize)
    z1 = 0.5 * pipsize
    a1 = CALL MyRange[x1,y1,z1] //false
    //
    x2 = close
    y2 = close + (0.9 * pipsize)
    z2 = 0.5 * pipsize
    a2 = CALL MyRange[x2,y2,z2] //false
    //
    GRAPH a
    GRAPH a1
    GRAPH a2
    buy at -close limit
    robdav and Nicolas thanked this post
    #69627 quote
    robertogozzi
    Moderator
    Master

    If you want to verify whether CLOSE is within +- 0.5 pips from the HIGHEST high of the previous 10 bars you may write:

    condition = CALL MyRange[close,highest[10](high[1]),0.5 * pipsize]
    Nicolas, robdav, icharttop and Kovit thanked this post
    #69633 quote
    robdav
    Participant
    Veteran

    Thanks Robert,

    I will be working on this later!

    #70008 quote
    robdav
    Participant
    Veteran

    Many thanks Roberto, your first answer has turned out to be the simplest in this case.

    Thanks again, Robert

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

Compare Close to +0.1 through to 0.9 and -0.1 through to -0.9 of a variable


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
robdav @robdav Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by robdav
7 years, 9 months ago.

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