首页 > 解决方案 > 具有两个以上超趋势的 PineScript

问题描述

我正在尝试编写一个 pine 脚本(版本 4),其中将有三个超级趋势指标来创建买入或卖出信号。

以下是代码。我错过了什么。图表未显示任何买入或卖出信号。

B_Cond1 = trend_1 == 1 and trend_1[1] == -1 and trend_2 == 1 and trend_2[1] == -1
B_Cond2 = trend_1 == 1 and trend_1[1] == -1 and trend_3 == 1 and trend_3[1] == -1
B_Cond3 = trend_2 == 1 and trend_2[1] == -1 and trend_3 == 1 and trend_3[1] == -1

buySignal = B_Cond1 or B_Cond2 or B_Cond3

S_Cond1 = trend_1 == -1 and trend_1[1] //== 1 and trend_2 == -1 and trend_2[1] == 1
S_Cond2 = trend_1 == -1 and trend_1[1] == 1 and trend_3 == -1 and trend_3[1] == 1
S_Cond3 = trend_2 == -1 and trend_2[1] == 1 and trend_3 == -1 and trend_3[1] == 1

sellSignal = S_Cond1 or S_Cond2 or S_Cond3

plotshape(buySignal, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor = color.white, transp = 0)
plotshape(sellSignal, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor = color.white, transp = 0)

标签: pine-scripttrading

解决方案


尝试使用绘图调试您的条件。buySignal通过分离来简化你的:

//@version=4
study("My Script")

plot (B_Cond1 ? 1 : 0, title = "B_Cond1", color = color.red)
plot (B_Cond2 ? 1 : 0, title = "B_Cond2", color = color.green)
plot (B_Cond3 ? 1 : 0, title = "B_Cond3", color = color.orange)

plot (buySignal ? 1 : 0, title = "buySignal", color = color.blue)

plot(close)

并检查您的条件是否相互满足。

sellSignal.


推荐阅读