首页 > 解决方案 > 为什么我的 Pine Script Zigzag% 不起作用?

问题描述

我希望每个人都度过了美好的一天。我目前在将 think script Zigzag% 转换为 pine 编辑器 zigzag% 时遇到问题。每次我尝试将它添加到图表时,都会弹出一个错误,说“不匹配的字符 'n' 期待 '='。它可能太小了以至于我错过了,但我似乎无法理解我错过了什么。在下面我将发布原始的 zigzag% think 脚本和我尝试的 pine 编辑器 zigzag%,我将不胜感激任何帮助。

原创think脚本之字形

input price = close;
input reversalAmount = 8.0;
input showBubbles = no;
input showLabel = no;

assert(reversalAmount > 0, "'reversal amount' should be positive: " + reversalAmount);

plot "ZZ%" = reference ZigZagHighLow(price, price, reversalAmount, 0, 1, 0);

def zzSave = if !IsNaN("ZZ%") then price else getValue(zzSave, 1);
def chg = (price / getValue(zzSave, 1) - 1) * 100;
def isUp = chg >= 0;
def isConf = AbsValue(chg) >= reversalAmount or (IsNaN(getValue("ZZ%", 1)) and getValue(isConf, 1));

"ZZ%".EnableApproximation();
"ZZ%".DefineColor("Up Trend", Color.UPTICK);
"ZZ%".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ%".DefineColor("Undefined", Color.DARK_ORANGE);
"ZZ%".AssignValueColor(if !isConf then "ZZ%".color("Undefined") else if isUp then "ZZ%".color("Up Trend") else "ZZ%".color("Down Trend"));

DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);

def barNumber = barNumber();

AddChartBubble(showBubbles and !IsNaN("ZZ%") and barNumber != 1, price, round(chg) + "%", if !isConf then globalColor("Unconfirmed") else if isUp then globalColor("Up") else globalColor("Down"), isUp);
AddLabel(showLabel and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + round(chg) + "%", if !isConf then globalColor("Unconfirmed") else if isUp then globalColor("Up") else globalColor("Down"));

Pine 编辑器(尝试)Zigzag%

//@version=5
zzreversalAmount = 8.0
plot (label, yes)

assert(zzreversalAmount > 0, "'reversal amount' should be positive: " + zzreversalAmount)

p1= plot ("ZZ%" = reference ZigZagHighLow(close, close, zzreversalAmount, 0, 1, 0))

zzSave = if !na("ZZ%") ? close else ta.valuewhen(zzSave, 1))
chg = (close / ta.valuewhen(zzSave, 1) - 1) * 100
isUp = chg >= 0
isConf = math.abs(chg) >= zzreversalAmount or (na(ta.valuewhen("ZZ%", 1)) and ta.valuewhen(isConf, 1))

"ZZ%"math.todegrees()
"ZZ%"color.from_gradient("Up Trend", color=color.UPTICK)
"ZZ%"color.from_gradient("Down Trend", color= Color.DOWNTICK)
"ZZ%"color.from_gradient("Undefined", color= Color.DARK_ORANGE)
"ZZ%"label.set_color(if !isConf ? "ZZ%".color("Undefined") else if isUp ? "ZZ%".color("Up Trend") else "ZZ%".color("Down Trend"))

line.set_color("Unconfirmed",color= color.darkorange)
line.set_color("Up",color= color.uptick)
line.set_color("Down", color= color.downtick)

barNumber = barNumber()

array.new_label(priceshowLabel and barNumber != 1, (if isConf ? "Confirmed " else "Unconfirmed ") + "ZigZag: " + round(chg) + "%", if !isConf ? globalColor("Unconfirmed") else if isUp ? globalColor("Up") else globalColor("Down"))

我已经用 close 代替了价格值而不是输入,并且我拿走了显示气泡,因为我不需要它来显示气泡

标签: pine-scriptthinkscript

解决方案


推荐阅读