pine-script - 具有两个以上超趋势的 PineScript
问题描述
我正在尝试编写一个 pine 脚本(版本 4),其中将有三个超级趋势指标来创建买入或卖出信号。
- 必须根据 buySignal 或 sellSignal 标准绘制线。
- 如果三个超级趋势中有两个给出入场信号,则会产生信号
以下是代码。我错过了什么。图表未显示任何买入或卖出信号。
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)
解决方案
尝试使用绘图调试您的条件。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
.
推荐阅读
- python - Python 中的 module.function() 与 object.method()。他们是一样的吗?
- python - 如何找到数据框中每个点相对于另一个数据框中所有点的最小距离?
- .net-core - 使用 dotnet pack 的多阶段管道在版本控制方面失败
- spring-boot - 构建时从 application.properties 设置值
- python - 我无法将数据 json 加载到我的 postgres 数据库中
- mapstruct - Mapstruct - 将 customModel 映射到它的字符串表示形式
- android - 如何刷新分页 3 库中的页码
- python - 索引以处理输入
- java - Mapstruct - 字符串操作,但仅限于一个属性
- python - Pycharm 找不到解释器(2)