full candle %

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #138656 quote
    jebus89
    Participant
    Master

    Created an indicator showing how much of a candle = the body of the candle, but im getting some weird results, 99% of the candles look correct, but im getting some that are above 100% which shouldnt happen. Would love some help as to why this is happening.

     

    a = high-low
    if close > open then
    b = close - open
    elsif close < open then
    b = open - close
    endif
    
    c = (b/a)*100
    
    return c
    #138658 quote
    jebus89
    Participant
    Master

    Nevermind i think i have solved it myself by adding this to the code:

     

    a = high-low
    if close > open then
    b = close - open
    elsif close < open then
    b = open - close
    endif
    
    c = (b/a)*100
    
    if c > 100 then
    c = 0
    elsif c < 100 then
    c = c
    endif
    
    return c

    I think what went wrong is that when open = close then it got buggy..

    #138661 quote
    robertogozzi
    Moderator
    Master

    Lines 2-6 can be written in just one line:

    b = abs(close - open)
    #138665 quote
    jebus89
    Participant
    Master

    Lines 2-6 can be written in just one line:

    Could you explain how the abs piece of code replaces mine? 🙂

     

    While your at it Roberto, could you help me with how to write this piece of code more simple if its possible?

     

    if a or a[1] or a[2] or a[3] or a[4] then
    b = 1
    endif
    #138672 quote
    robertogozzi
    Moderator
    Master

    Because when CLOSE > OPEN you have, say, 100, while when CLOSE <  OPEN you have -100. ABS() is a function that converts negative numbers into positive numbers, so the result will always be positive (which is what you need).

    The answer to the second question is:

    b = (summation[5](a) > 0)  //will sum a[0] through a[4] and if the result is > 0 will assign the logical value 1 (true) to b
    #138673 quote
    Vonasi
    Moderator
    Master

    ABS just returns everything as a positive value so it does not matter if close is higher or lower than open.

    Answer to second question:

    if summation[5](a) <> 0 then
    b=1
    endif
    #138674 quote
    Vonasi
    Moderator
    Master

    Too fast again Roberto!

    robertogozzi thanked this post
    #138677 quote
    jebus89
    Participant
    Master

    Thank you Vonasi and ROberto 🙂

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

full candle %


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
jebus89 @jebus89 Participant
Summary

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

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