plot - 如何在 Tradingview Pine Script 中绘制 X 根蜡烛的百分比变化?
问题描述
所以我只是试图在收盘价在 5 根蜡烛上变化 20% 的位置下方绘制绿色三角形。Pine 脚本给出了 plotshape 的语法错误。你不能在情节形状中放置一个条件吗?
study(title="20% change in 5 candles", overlay=true)
var Diff = 0
var PercentChange = 0
// Identify % change 5 candles away
Diff = close - close[5]
PercentChange = Diff / close[5]
// Plot signals to chart
plotshape(series=PercentChange > 0.2, title="Here", location=location.belowbar, color=color.green, style=shape.triangleup, text="here")
// Send out an alert if this candle meets our conditions
alertcondition(PercentChange > 0.2, title="20% change in 5 candles!", message="20% change in 5 candles")
解决方案
- var
Diff = 0
并var PercentChange
初始化为int
,但稍后将其分配给float
close 的值。使用var float = 0
或var Diff = 0.0
。 - 稍后您需要使用运算符而不是:
重新分配
var
值。:=
=
Diff := close - close[5]
- plotshape 函数之前错误的额外缩进。
//@version=4
study(title="20% change in 5 candles", overlay=true)
var float Diff = 0
var PercentChange = 0.0
// Identify % change 5 candles away
Diff := close - close[5]
PercentChange := Diff / close[5]
// Plot signals to chart
plotshape(series=PercentChange > 0.2, title="Here", location=location.belowbar, color=color.green, style=shape.triangleup, text="here")
// Send out an alert if this candle meets our conditions
alertcondition(PercentChange > 0.2, title="20% change in 5 candles!", message="20% change in 5 candles")
推荐阅读
- kubernetes - 更改 Kubernetes 工作节点的内存分配
- excel - 对传递给VBA中的函数的两个范围的差进行平方
- javascript - Adding JS to an existing HTML and CSS ui
- typescript - How to reinstall TypeScript
- python - scipy.optimize.linprog: What happens if we choose the coefficients orthogonal to the feasible set?
- java - The Python library easyhid doesn't need set udev rules, whereas similar libraries like usb4java for Java need them to work on Linux
- reactjs - How to test axios requests in react testing library and jest
- css - Is there a way to 'peg' the size of a font to the size of the browser window (with and height and line height, padding etc)?
- azure-eventhub - Azure Event Hub - Process data through scala script
- php - 如何以编程方式获取已安装的作曲家包?