pine-script - 如何确定蜡烛的大小是否是看涨和看跌的两倍
问题描述
嗨,我试图在我的代码中添加一些东西,以确定蜡烛从开盘到收盘的大小是否大于前一根蜡烛的两倍,但我似乎无法弄清楚看涨蜡烛,我不完全确定它是否正常工作对于看跌。我想要两倍大的蜡烛来突出黄色。
到目前为止,我的代码如下,但它似乎不起作用
//@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() 函数、一些绘图、条形颜色和警报编写了一个简单的脚本。很简单,如果蜡烛在收盘时是最后一根蜡烛的两倍大,那么我们将颜色设为黄色并获得警报。有一些以 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}}')
推荐阅读
- firebase - 我可以使用 Terraform 部署 Firebase https 可调用 (.onCall) 吗?
- angular - 在引导网格中循环角度对象
- html - 以 Latin-1 编码但以 UTF-8 读取的文件可以解决任何问题吗?
- php - 如何在 json laravel 中获取条带错误?
- python - 编码概率加权函数误差
- java - 如何从 Java 中的另一种方法访问变量?
- ios - UITableViewCell 强引用循环,但未被 Instruments 中的 Leaks 拾取
- sql - Sql Json - 使用 SQL Server 2017 Express 更新数组中的 Json 属性
- r - 将非缺失日期转换为 R 中缺失的日期
- circuit - 简化卡诺图