如何确定一根蜡烛的大小是否是看涨和看跌的两倍

How to determine if a candle is twice the size for both bullish and bearish

您好,我正在尝试向我的代码中添加一些内容,以确定一根蜡烛从开盘到收盘的大小是否大于前一根蜡烛的两倍,但是对于看涨蜡烛,我似乎无法弄清楚这一点,我也不知道完全确定它在看跌时能正常工作。我想要两倍大的蜡烛来突出黄色。

目前我的代码如下,但它似乎不起作用

//@version=4
study(title="vols",overlay=true)
///////////////////////Candles//////////////////////////////////
greenCandle = (close > open)
redCandle   = (close < open)
twoGreenCandles = greenCandle[1] and greenCandle
twoRedCandles   = redCandle[1]   and redCandle
////////////////////////////tick size///////////////////////////
greencandlesize = if greenCandle
    (close/open)/100
redcandlesize = if redCandle
    (close/open)/100
greengo = greencandlesize[1]<greencandlesize
grev = (greencandlesize[1]/100)<((greencandlesize /100)*2)
redgo = redcandlesize[1]>redcandlesize
rev = (redcandlesize[1]/100)>((redcandlesize /100)/2)
///////////////////candle and vol and wicks true////////////////
r = (twoGreenCandles or twoRedCandles) and (grev or rev)
/////////////////////////Color/////////////////////////////////
barcolor(color=r ? color.yellow: na)

如有任何帮助,我们将不胜感激

我写了一个简单的脚本,使用了 abs() 函数、一些绘图、条形颜色和一个警报。很简单,如果蜡烛在收盘时是最后一根蜡烛的两倍大,那么我们就将柱线颜色设为黄色,并且可以收到警报。有一些直方图形式的图,因此我们可以根据需要查看和测量它。如果你想要连续 2 个,你可以添加它,但我读它是因为你想要看涨或看跌,所以不确定。检查一下

//@version=4
study("My Script")

lastCandleSize = abs(close[1]-open[1])
thisCandleSize = abs(close-open)

twiceBig = thisCandleSize >= (lastCandleSize * 2) and barstate.isconfirmed

barcolor(twiceBig ? color.yellow : na)

plot(thisCandleSize, "This candle", color=#5d606b, style=plot.style_columns)
plot(lastCandleSize, "Last candle", color=#d1d4dc, style=plot.style_histogram, linewidth=4)

alertcondition(twiceBig, title='2x Candle', message='Candle was twice as big on {{interval}} chart. Price is {{close}}')