I am trying to convert built-in Momentum strategy to study with alerts. I don't know if I did it right. Chart is compressed to straight line :( Please, help me. Thank you.
This is original built-in Momentum strategy:
//@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)
This is my study with alerts:
//@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)