我正在尝试将内置的动量策略转换为带警报的学习。我不知道我做得对不对。图表被压缩成直线:(请帮帮我。谢谢。
这是原创的内置动量策略:
//@version=4
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)
strategy.entry("MomLE", strategy.long, stop=high+syminfo.mintick, comment="MomLE")
else
strategy.cancel("MomLE")
if (mom0 < 0 and mom1 < 0)
strategy.entry("MomSE", strategy.short, stop=low-syminfo.mintick, comment="MomSE")
else
strategy.cancel("MomSE")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)这是我关于警报的研究:
//@version=4
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)
alertcondition(condition=mom0 > 0 and mom1 > 0, message="Momentum increased")
alertcondition(condition=mom0 < 0 and mom1 < 0, message="Momentum decreased")
plot(series=mom1)发布于 2020-03-25 18:07:48
我断定这段代码是有效的。但是我还是不知道这是不是和内置策略一样
//@version=4
study(title="Momentum", shorttitle="Mom")
len = input(40, minval=1, title="Length")
src = input(close, title="Source")
mom = src - src[len]
mom0 = mom(src,len)
mom1 = mom(mom0,1)
alertcondition(condition=mom0 > 0 and mom1 > 0, message="Momentum increased")
alertcondition(condition=mom0 < 0 and mom1 < 0, message="Momentum decreased")
plot(mom0, color=color.olive, title="Mom")
plot(mom1, color=color.red, title="Mom")发布于 2020-03-27 03:21:45
您的代码将生成与策略相同的进入条件,但复制所有策略的行为将要求您构建逻辑,以复制它使用的特定` strategy .*()调用以及TV代理仿真器如何执行这些调用。
例如,您的条目发出停止单,当输入条件不再为真时,这些停止单将被取消,而这不会反映在您的研究代码中。
您可以通过删除这一行来改进您的代码,因为使用作为内置变量的名称来命名变量是一种糟糕的做法,而且该变量以后不会在脚本中使用。Pine中有一个名为mom()的内置函数( TV策略实际上应该使用它,而不是用户定义的函数来做同样的事情)。
mom = src - src[len]下面两行现在正在使用该函数,而不是前一行中的mom变量:
mom0 = mom(src,len)
mom1 = mom(mom0,1)https://stackoverflow.com/questions/60844756
复制相似问题