Arrive8848
New member
My goal is to Average the green candlestick bodies and the red candlestick bodies separately. I can easily parse out the green candlesticks over a range, but I cannot seem to figure out a way to ignore the red values. For example, using a simple "if/then" statement I can differentiate between green and red. But I have to do something with the red. If I set it to zero or any positive number, the average is skewed. I need to actually just ignore it altogether, i.e. creating a subset of the whole. I am not used to languages that require an "else" to the "if" statement! In every other language I know, I would just have an "if" statement by itself. This would automatically discard anything that does not satisfy the "if" statement requirements.
Figure 1: Example dataset with various results
Figure 2: Example code for column "RPL w/ avg" above
Figure 1: Example dataset with various results
Figure 2: Example code for column "RPL w/ avg" above
Code:
def greenCandles;
switch(METRIC) {
case "open/close":
if(close > open) { # Green candle
greenCandles = 100 - (open / close) * 100;
} else { # Red candle
greenCandles = Average((100 - (open / close) * 100), LENGTH);
}
case "low/high":
if(close > open) {
greenCandles = 100 - (low / high) * 100;
} else {
greenCandles = Average((100 - (low / high) * 100), LENGTH);
}
}