首页 > 解决方案 > 如何确定蜡烛的大小是否是看涨和看跌的两倍

问题描述

嗨,我试图在我的代码中添加一些东西,以确定蜡烛从开盘到收盘的大小是否大于前一根蜡烛的两倍,但我似乎无法弄清楚看涨蜡烛,我不完全确定它是否正常工作对于看跌。我想要两倍大的蜡烛来突出黄色。

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

//@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)

对此的任何帮助将不胜感激

标签: pine-script

解决方案


我使用 abs() 函数、一些绘图、条形颜色和警报编写了一个简单的脚本。很简单,如果蜡烛在收盘时是最后一根蜡烛的两倍大,那么我们将颜色设为黄色并获得警报。有一些以 hist 形式显示的图,因此我们可以查看它并根据需要对其进行测量。如果你想要连续 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}}')
    

推荐阅读