当 运行 有 2 根蜡烛但少于 4 根时,我该如何突出显示?

How do I highlight when there is a run of 2 candles but less than 4?

您好,这是我的第一个代码,我只是四处寻找如何做。 我想要实现的是一个叠加层,当有 运行 根蜡烛时颜色相同,但仅当第二根蜡烛的体积小于第一根时才着色。我还想在将来添加其他内容,但我目前真的停留在这部分。任何帮助将不胜感激。 这是我目前所拥有的

//@version=4
study(title="Highlight candles", overlay=true)
///////////////////////Candles//////////////////////////////////////////////
greenCandle = (close > open)
redCandle = (close < open)

twoGreenCandles = greenCandle[1] and greenCandle
twoRedCandles = redCandle[1] and redCandle

////////////VOL////////////////////////
volumecng = volume[1] > volume

///////////////////candle and vol true////////////////
greenv2 = twogreencandles=true and volumecng =true

/////////////////////////Background////////////////////////////////////////////////
bgcolor(color=greenv2 ? color.lime : na)
bgcolor(color=twoRedCandles ? color.fuchsia : na)

在一行中两次使用 = 将导致错误,因为 = 用于定义变量。 == 可用于检查某项是否等于语句中的另一个值。

例如

x = 关闭 == 关闭[1]

只有 return 如果收盘值等于连续 2 个柱,则为真。但是,因为twoGreenCandles和volumecng是布尔值,我们可以简单地将2用“与”放在一起。

//@version=4
study(title="Highlight candles", overlay=true)
///////////////////////Candles//////////////////////////////////////////////
greenCandle = (close > open)
redCandle   = (close < open)

twoGreenCandles = greenCandle[1] and greenCandle
twoRedCandles   = redCandle[1]   and redCandle

////////////VOL////////////////////////
volumecng = volume[1] > volume

///////////////////candle and vol true////////////////
greenv2 = twoGreenCandles and volumecng 
redv2   = twoRedCandles   and volumecng 

/////////////////////////Background////////////////////////////////////////////////
bgcolor(color=greenv2 ? color.lime    : na)
bgcolor(color=redv2   ? color.fuchsia : na)

注意:此处背景颜色的替代方法是更改​​条形颜色。为此,将 bgcolor() 替换为 barcolor() 以更改蜡烛的颜色

干杯!