Moving Average Mean Reversion Strategy

HNipps · strategy · 18 行 · 点赞 358 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=3
strategy(title="Moving Average Mean Reversion Strategy", shorttitle="MA-MR", overlay=true)
len = input(20, minval=1, title="Length")
src = input(close, title="Source")
out = sma(src, len)
// plot(out*1.1, color=green, title="MA")
// plot(out*0.9, color=green, title="MA")
// plot(out, color=blue, title="MA")
// plot(close, color=red, title="Close")
 
upper_bound = out * 1.1
lower_bound = out * 0.9
 
if crossunder(close, lower_bound)
    strategy.entry("buy", strategy.long, comment="MR-LE")
 
if crossover(close, upper_bound)
    strategy.entry("sell", strategy.short, comment="MR-SE")

← 返回列表