OPEN-SOURCE SCRIPT

My strategy


//version=5
strategy("Dynamic RSI Momentum", "DRM Strategy", process_orders_on_close = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 50 )

// +++++++++++++++++++++
// ++ INPUT ++
// +++++++++++++++++++++

// Momentum
len = input.int(10, "Momentum Length", 1, group = "Dynamic RSI Momentum")
src = input.source(close, "Source", group = "Dynamic RSI Momentum")

min_rsi = input.int(20, "Min RSI", group = "Dynamic RSI Momentum")
max_rsi = input.int(50, "Max RSI", group = "Dynamic RSI Momentum")

upLvl = input.float(70, "OverBought", 0, 100, group = "Dynamic RSI Momentum")
dnLvl = input.float(30, "OverSold", 0, 100, group = "Dynamic RSI Momentum")

// +++++++++++++++++++++
// ++ CALCULATION ++
// +++++++++++++++++++++

// RMA Function
rmaFun(src, len) =>
sma = ta.sma(src, len)
alpha = 1/len
sum = 0.0
sum := na(sum[1]) ? sma : alpha * src + (1 - alpha) * nz(sum[1])

// RSI Function
rsiFun(src, len) =>
100 - 100 / (1 + rmaFun(src - src[1] > 0 ? src - src[1] : 0, len) /
rmaFun(src[1] - src > 0 ? src[1] - src : 0, len))

// Momentum
momVal = src - src[len]

// Calculation Price vs Momentum
corr = ta.correlation(src, momVal, len)
corr := corr > 1 or corr < -1 ? float(na) : corr

rsiLen = 0
rsiLen := int(min_rsi + nz(math.round((1 - corr) * (max_rsi-min_rsi) / 2, 0), 0))

rsiMom = rsiFun(src, rsiLen)


// +++++++++++++++++++++
// ++ STRATEGY ++
// +++++++++++++++++++++

long = ta.crossover(rsiMom, dnLvl)
short = ta.crossunder(rsiMom, upLvl)


// +++> Long <+++++
if long and not na(rsiMom)
strategy.entry("Long", strategy.long)

// +++> Short <+++++
if short and not na(rsiMom)
strategy.entry("Short", strategy.short)

// +++++++++++++++++++++
// ++ PLOT ++
// +++++++++++++++++++++

plot(rsiMom, "Dynamic RSI Momentum", rsiMom < dnLvl ? color.green : rsiMom > upLvl ? color.red : color.yellow)

hline(50, "Mid Line", color.gray)

upperLine = hline(upLvl, "Upper Line", color.gray)
lowerLine = hline(dnLvl, "Lower Line", color.gray)
fill(upperLine, lowerLine, color.new(color.purple, 90), "Background Fill")

Bands and ChannelsBill Williams IndicatorsBreadth Indicators

Script open-source

Dans le plus pur esprit TradingView, l'auteur de ce script l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par nos Règles. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Vous voulez utiliser ce script sur un graphique ?

Clause de non-responsabilité