Candle Body Indicator

Infb11

New member
I am looking for an indicator that alters me when the candle body is not 50% of it's total range, preferably by changing the outline color of the candle. Does anyone know how how to code this?
 
Solution
@Infb11 Something like this might work. Note that AssignPriceColor() will color the entire bar - it's a feature of the function.
Code:
def dir = if(close > open, close - open, open - close);
def range = dir < .50 * (high - low);
AssignPriceColor(if range then color.blue else color.current);

Pensar

Well-known member
VIP
Lifetime
@Infb11 Something like this might work. Note that AssignPriceColor() will color the entire bar - it's a feature of the function.
Code:
def dir = if(close > open, close - open, open - close);
def range = dir < .50 * (high - low);
AssignPriceColor(if range then color.blue else color.current);
 
Solution

Infb11

New member
@Infb11 Something like this might work. Note that AssignPriceColor() will color the entire bar - it's a feature of the function.
Code:
def dir = if(close > open, close - open, open - close);
def range = dir < .50 * (high - low);
AssignPriceColor(if range then color.blue else color.current);
Thank you!. One question, will the replicate for down bars or do I need to duplicate and change the def dir?
 

Pensar

Well-known member
VIP
Lifetime
Thank you!. One question, will the replicate for down bars or do I need to duplicate and change the def dir?
It should work for any direction of candle. Another (perhaps easier to read and understand) way to code the "dir" variable is
Code:
def dir = if close > open then close - open else open - close;
This simply makes sure that the smaller price value is always subtracted from the larger price value to avoid negative results.
 

Similar threads

Top