Code not plotting complex OHLC request on tradingview
Posted: Mon Aug 21, 2023 11:12 am
This line codes plots some grey candles with this condition: The OHLC (Open, High, Low, Close) values of the last completed candle's body and wicks are completely contained within the body and wicks of the previous candle.
But none with these conditions: A grey candle will be plotted when either of the following conditions is met:
The high of the last completed candle touches or goes above the high of the previous candle, the low of the last completed candle touches or goes below the low of the previous candle, and the close of the last completed candle remains within the range of the previous candle's high and low.
// Check if the last completed candle's OHLC values are contained within the previous candle's body and wicks
isOHLCContained = (lastOpen >= prevOpen and lastOpen <= prevClose and lastHigh <= prevHigh and lastLow >= prevLow and lastClose >= prevLow and lastClose <= prevHigh)
// Check if the high and low of the last completed candle touch the high and low of the previous candle
isHighLowTouching = (lastHigh >= prevHigh and lastLow <= prevLow and lastClose >= prevLow and lastClose <= prevHigh)
greyCandleConsolidation = isOHLCContained or isHighLowTouching
But none with these conditions: A grey candle will be plotted when either of the following conditions is met:
The high of the last completed candle touches or goes above the high of the previous candle, the low of the last completed candle touches or goes below the low of the previous candle, and the close of the last completed candle remains within the range of the previous candle's high and low.
// Check if the last completed candle's OHLC values are contained within the previous candle's body and wicks
isOHLCContained = (lastOpen >= prevOpen and lastOpen <= prevClose and lastHigh <= prevHigh and lastLow >= prevLow and lastClose >= prevLow and lastClose <= prevHigh)
// Check if the high and low of the last completed candle touch the high and low of the previous candle
isHighLowTouching = (lastHigh >= prevHigh and lastLow <= prevLow and lastClose >= prevLow and lastClose <= prevHigh)
greyCandleConsolidation = isOHLCContained or isHighLowTouching