首页 > 解决方案 > 如何在 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")

标签: plotsyntax-errorpine-script

解决方案


  1. varDiff = 0var PercentChange初始化为int,但稍后将其分配给floatclose 的值。使用 var float = 0var Diff = 0.0
  2. 稍后您需要使用运算符而不是: 重新分配var值。:==Diff := close - close[5]
  3. 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")

推荐阅读