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
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..
Lines 2-6 can be written in just one line:
b = abs(close - open)
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
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
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
Thank you Vonasi and ROberto 🙂