Renko Strategy with long short ema band

nil12285 · strategy · 39 行 · 点赞 508 · TradingView 原页

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

Pine Script

//@version=4
strategy("Renko Strategy with long short ema band", overlay=true)
 
offset = input(2, maxval=50)
atr = input(14, maxval=50)
shortlen = input(5, minval=3, title="Short Length")
longlen = input(10, minval=7, title="Long Length")
matype = input(title="MA Type", defval="EMA", options=["EMA", "SMA"])
 
renko_t = renko(syminfo.tickerid, "ATR", 14)
renko_low = security(renko_t, timeframe.period, low)
renko_close = security(renko_t, timeframe.period, close)
c = renko_low[1] >= renko_low ? color.red : color.lime 
// c = close >= open ? color.lime : color.red
plot(renko_low, linewidth=4, color=c, offset=offset)
 
 
shortma = if matype == 'EMA' 
    ema(renko_close, shortlen) 
else 
    sma(renko_close, shortlen)
 
 
longma = if matype == 'EMA' 
    ema(renko_close, longlen)
else 
    sma(renko_close, longlen)
 
plot(shortma, color=#f0c518, linewidth=2)
plot(longma, color=color.purple, linewidth=2)
 
 
longCondition = crossover(shortma, longma) and close > shortma and close > longma
if (longCondition)
    strategy.entry("Buy", strategy.long)
 
shortCondition = crossunder(shortma, longma) and close < shortma and close < longma
if (shortCondition)
    strategy.entry("Sell", strategy.short)

← 返回列表