Advertisement
danucante

Untitled

Oct 25th, 2023
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. //@version=5
  2. indicator('Relative Trend Index (RTI) by Zeiierman', shorttitle= "RTI", overlay=false, precision=0)
  3.  
  4. // Inputs {
  5. trend_data_count = input.int(100, step=4, minval=10, title="Trend Length", inline = "RT", group="Relative Trend Index [RTI]", tooltip="This variable determines the number of data points used in the calculation. \n\nIn short: A high value returns the long-term trend and a low value returns the short-term trend. \n\nIf a user increases the 'Trend Length', the trend will take into account a larger number of data points. This makes the trends smoother and more resistant to sudden changes in the market, as they're based on a broader set of data. It also makes the trends slower to react to recent changes, as they're diluted by older data. \n\nOn the other hand, if a user decreases the 'Trend Length', the trend will take into account fewer data points. This could make the trends more responsive to recent market changes, as they're based on a narrower set of data. It also makes the trends more susceptible to noise and rapid fluctuations, as each new piece of data has a greater impact.")
  6. trend_sensitivity_percentage = input.int(95, step=1,minval=50, maxval=98,title='Sensitivity    ', inline = "RT1", group="Relative Trend Index [RTI]", tooltip="This variable determines the specific indices in the sorted trend arrays that are used for the upper and lower trend. It's used as a percentage of the 'Trend length'. \n\nIf a user increases the 'Sensitivity', the trend will be based on higher and lower positions in the sorted arrays, respectively. This makes the trend less sensitive. \n\nConversely, if a user decreases the 'Sensitivity', the trend will be based on positions closer to the middle of the sorted arrays. This makes the trend more sensitive.")
  7. signal_length = input.int(20, step=1,minval=1, maxval=200,title='Signal Length', inline = "", group="Signal Line", tooltip="Set the Ma period.")
  8. ob = input.float(80, step=1, minval=0, maxval=100, title="", inline = "obos", group="Overbought/Oversold", tooltip="")
  9. os = input.float(20,step=1, minval=0, maxval=100,title="", inline = "obos", group="Overbought/Oversold", tooltip="Set the OB/OS levels.")
  10. //~~~~~~~~~~~~~~~~~~~~~~~}
  11.  
  12. // Relative Trend Index Calculation {
  13. upper_trend = close + ta.stdev(close, 2)
  14. lower_trend = close - ta.stdev(close, 2)
  15.  
  16. upper_array = array.new<float>(0)
  17. lower_array = array.new<float>(0)
  18. for i = 0 to trend_data_count - 1
  19. upper_array.push(upper_trend[i])
  20. lower_array.push(lower_trend[i])
  21. upper_array.sort()
  22. lower_array.sort()
  23.  
  24. upper_index = math.round(trend_sensitivity_percentage / 100 * trend_data_count) - 1
  25. lower_index = math.round((100 - trend_sensitivity_percentage) / 100 * trend_data_count) - 1
  26. UpperTrend = upper_array.get(upper_index)
  27. LowerTrend = lower_array.get(lower_index)
  28. RelativeTrendIndex = ((close - LowerTrend) / (UpperTrend - LowerTrend))*100
  29. //~~~~~~~~~~~~~~~~~~~~~~~}
  30.  
  31. // Plots {
  32. MA_RelativeTrendIndex = ta.ema(RelativeTrendIndex,signal_length)
  33. RT = plot(RelativeTrendIndex, 'Relative Trend Index (RTI)', color=color.new(color.teal, 0))
  34. plot(MA_RelativeTrendIndex, 'Ma Relative Trend Index', color=color.new(#00bcd4, 0))
  35. //~~~~~~~~~~~~~~~~~~~~~~~}
  36.  
  37. // Line plots {
  38. mid = hline(50, 'Mid', color=#606060, linestyle=hline.style_dashed)
  39. overbought = hline(ob, 'Overbought', color=#606060, linestyle=hline.style_dashed)
  40. oversold = hline(os, 'Oversold', color=#606060, linestyle=hline.style_dashed)
  41. //~~~~~~~~~~~~~~~~~~~~~~~}
  42.  
  43. // BG Fill {
  44. fill(overbought, oversold, color=color.new(color.teal, 90), title='Background')
  45. //~~~~~~~~~~~~~~~~~~~~~~~}
  46.  
  47. // Overbought/Oversold Gradient Fill {
  48. midLinePlot = plot(50, color = na, editable = false, display = display.none)
  49. fill(RT, midLinePlot, 100, ob, top_color = color.new(color.green, 0), bottom_color = color.new(color.green, 100), title = "Overbought Gradient Fill")
  50. fill(RT, midLinePlot, os, 0, top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0), title = "Oversold Gradient Fill")
  51. //~~~~~~~~~~~~~~~~~~~~~~~}
  52.  
  53. //Alerts {
  54. RT_OB_Over = ta.crossover(RelativeTrendIndex,ob)
  55. RT_OB_Under = ta.crossunder(RelativeTrendIndex,ob)
  56. RT_OS_Over = ta.crossover(RelativeTrendIndex,os)
  57. RT_OS_Under = ta.crossunder(RelativeTrendIndex,os)
  58. RT_Mid_Over = ta.crossover(RelativeTrendIndex,50)
  59. RT_Mid_Under = ta.crossunder(RelativeTrendIndex,50)
  60. RT_MA_Over = ta.crossover(RelativeTrendIndex,MA_RelativeTrendIndex)
  61. RT_MA_Under = ta.crossunder(RelativeTrendIndex,MA_RelativeTrendIndex)
  62.  
  63. alertcondition(RT_OB_Over, title = "RTI Crossover OB", message = "RTI Crossover OB")
  64. alertcondition(RT_OB_Under, title = "RTI Crossunder OB", message = "RTI Crossunder OB")
  65. alertcondition(RT_OS_Over, title = "RTI Crossover OS", message = "RTI Crossover OS")
  66. alertcondition(RT_OS_Under, title = "RTI Crossunder OS", message = "RTI Crossunder OS")
  67. alertcondition(RT_Mid_Over, title = "RTI Crossover 50", message = "RTI Crossover 50")
  68. alertcondition(RT_Mid_Under,title = "RTI Crossunder 50", message = "RTI Crossunder 50")
  69. alertcondition(RT_MA_Over, title = "RTI Crossover Ma", message = "RTI Crossover Ma")
  70. alertcondition(RT_MA_Under, title = "RTI Crossunder Ma", message = "RTI Crossunder Ma")
  71. //~~~~~~~~~~~~~~~~~~~~~~~}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement