Advertisement
warriorofbtc

Untitled

Nov 14th, 2023
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. // RSI
  2. timeframersi = '3D'
  3. ma(source, length, type) =>
  4. switch type
  5. "SMA" => ta.sma(source, length)
  6. "Bollinger Bands" => ta.sma(source, length)
  7. "EMA" => ta.ema(source, length)
  8. "SMMA (RMA)" => ta.rma(source, length)
  9. "WMA" => ta.wma(source, length)
  10. "VWMA" => ta.vwma(source, length)
  11. rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
  12. rsiSourceInput = input.source(close, "Source", group="RSI Settings")
  13. maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
  14. maLengthInput = input.int(14, title="MA Length", group="MA Settings")
  15. bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")
  16. showDivergence = input.bool(false, title="Show Divergence", group="RSI Settings")
  17.  
  18. up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
  19. down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
  20. rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
  21. rsiMA = ma(rsi, maLengthInput, maTypeInput)
  22. isBB = maTypeInput == "Bollinger Bands"
  23.  
  24.  
  25. RSILong = rsi > rsiMA
  26. RSIShort = rsi < rsiMA
  27.  
  28. RSILONG_cn = request.security(syminfo.tickerid,timeframersi,RSILong)
  29. RSISHORT_cn = request.security(syminfo.tickerid,timeframersi,RSIShort)
  30.  
  31. long_condition = RSILONG_cn
  32. short_condition = RSISHORT_cn
  33.  
  34. if long_condition
  35. strategy.entry("Long", strategy.long)
  36.  
  37. if short_condition
  38. strategy.entry("Short", strategy.short)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement