Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // RSI
- timeframersi = '3D'
- ma(source, length, type) =>
- switch type
- "SMA" => ta.sma(source, length)
- "Bollinger Bands" => ta.sma(source, length)
- "EMA" => ta.ema(source, length)
- "SMMA (RMA)" => ta.rma(source, length)
- "WMA" => ta.wma(source, length)
- "VWMA" => ta.vwma(source, length)
- rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
- rsiSourceInput = input.source(close, "Source", group="RSI Settings")
- maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
- maLengthInput = input.int(14, title="MA Length", group="MA Settings")
- bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")
- showDivergence = input.bool(false, title="Show Divergence", group="RSI Settings")
- up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
- down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
- rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
- rsiMA = ma(rsi, maLengthInput, maTypeInput)
- isBB = maTypeInput == "Bollinger Bands"
- RSILong = rsi > rsiMA
- RSIShort = rsi < rsiMA
- RSILONG_cn = request.security(syminfo.tickerid,timeframersi,RSILong)
- RSISHORT_cn = request.security(syminfo.tickerid,timeframersi,RSIShort)
- long_condition = RSILONG_cn
- short_condition = RSISHORT_cn
- if long_condition
- strategy.entry("Long", strategy.long)
- if short_condition
- strategy.entry("Short", strategy.short)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement