首页 > 解决方案 > 为什么转换后的 think script 代码不起作用?

问题描述

我希望每个人都度过了美好的一天。我在将我的 think 脚本代码转换为 pine 脚本时遇到问题。我了解 pine 脚本的基础知识,但我似乎无法弄清楚为什么我的代码有错误。每次我绘制它时,都会弹出一个错误“不匹配的输入'然后'期待'行尾没有续行”。我的目标是将变量 EMA 指标从 think 脚本转换为 pine 脚本中的变量 ema。我将在下面列出我尝试转换的 think 脚本指示器代码和 pine 脚本代码。非常感谢任何形式的帮助。

认为脚本变量 EMA 代码:

"input price = close;input length = 10; def tmp1 = if price > price[1] then price - price[1] else 0;def tmp2 = if price[1] > price then price[1] - price else 0;def d2 = sum(tmp1, length);def d4 = sum(tmp2, length);def cond = d2 + d4 == 0;def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price
);plot VMA = asd;"

Pine 脚本(尝试转换) 可变 EMA 代码

//@version=5//VARIABLEMOVINGAVERAGE length = input.int(10, title= "length") tmp1= input  (if close > close[1] then close - close[1] else 0) tmp2 = input (if close[1] > close then close[1] - close else 0) d2 = input (sum(tmp1, length)) d4 = input (sum(tmp2, length)) cond = input (d2 + d4 == 0) ad3 = input (if cond then 0 else (d2 - d4) / (d2 + d4) * 100) coeff = input (2 / (length + 1) * AbsValue(ad3) / 100) asd = input (compoundValue "visible data" = coeff * close + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = close) plot1 = plot VMA == asd"

标签: pine-scriptthinkscript

解决方案


//@version=5
indicator("Variable Moving Average", overlay = true)

length = input.int(10, title= "length")
tmp1 = close > close[1] ? close - close[1] : 0
tmp2 = close[1] > close ? close[1] - close : 0
d2 = math.sum(tmp1, length)
d4 = math.sum(tmp2, length)
cond = d2 + d4 == 0
ad3 = cond ? 0 : (d2 - d4) / (d2 + d4) * 100
coeff = 2 / (length + 1) * math.abs(ad3) / 100

float asd = na
asd := coeff * close + nz(asd[1], 0) * (1 - coeff)

plot1 = plot(asd)

推荐阅读