有人能帮我把mom策略松脚本代码转换成警报吗?以下是代码:
//@version=3
strategy("Momentum Strategy", overlay=true)
length = input(12)
price = close
momentum(seria, length) =>
mom = seria - seria[length]
mom
mom0 = momentum(price, length)
mom1 = momentum(mom0, 1)
if (mom0 > 0 and mom1 > 0)
stop_price = high+syminfo.mintick
strategy.entry("MomLE", strategy.long, stop=stop_price, comment="MomLE", qty=2)
else
strategy.cancel("MomLE")
if (mom0 < 0 and mom1 < 0)
stop_price = low - syminfo.mintick
strategy.entry("MomSE", strategy.short, stop=stop_price, comment="MomSE", qty=2)
else
strategy.cancel("MomSE")发布于 2018-10-03 12:14:16
有人能帮我把mom策略松脚本代码转换成警报吗?
要将策略代码转换为可以生成警报的指示符,有四项工作要做:
strategy()函数替换为study()。strategy.entry()和strategy.exit()函数。如下所示:
//@version=3
study("Momentum Alert", overlay=true)
length = input(12)
price = close
momentum(seria, length) =>
mom = seria - seria[length]
mom
mom0 = momentum(price, length)
mom1 = momentum(mom0, 1)
// Create alert conditions
alertcondition(condition=mom0 > 0 and mom1 > 0,
message="Momentum increased")
alertcondition(condition=mom < 0 and mom1 < 0,
message="Momentum decreased")
// Output something
plot(series=mom0)*:TradingView的alertcondition()函数不是所谓的“输出函数”。但每个指示器都需要这样的功能(例如,用于绘制、着色或创建形状)。否则你会得到“脚本必须至少有一个输出函数调用”错误。
这就是为什么我在上面的示例代码中添加了plot()函数,尽管严格地说,它并不一定适用于您的问题。
https://stackoverflow.com/questions/52567698
复制相似问题