Advertisement
xmd79

Bjorgum TSI

Jan 13th, 2023
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.21 KB | None | 0 0
  1. // ________________
  2. // ___ __ )_____(_)___________________ ____ ________ ___
  3. // __ __ |____ /_ __ \_ ___/_ __ `/ / / /_ __ `__ \
  4. // _ /_/ /____ / / /_/ / / _ /_/ // /_/ /_ / / / / /
  5. // /_____/ ___ / \____//_/ _\__, / \__,_/ /_/ /_/ /_/
  6. // /___/ /____/
  7.  
  8. //@Bjorgum on Stocktwits
  9. //@version=5
  10.  
  11. indicator ( "Bjorgum TSI", "BJ TSI", precision=4 , timeframe="", timeframe_gaps=true)
  12.  
  13. // ================================== //
  14. // ---------> User Input <----------- //
  15. // ================================== //
  16.  
  17. strat = input.string ("Fast" , "Select a Speed" , group="TSI Speed Control", options= ["Fast", "Slow"])
  18.  
  19. tsiBull = input.color (color.new(#17ff00,0) , "" , group= "TSI Value Line" , inline= "1")
  20. tsiMid = input.color (color.new(#9598a1,0) , "" , group= "TSI Value Line" , inline= "1")
  21. tsiBear = input.color (color.new(#f3ff00,0) , "" , group= "TSI Value Line" , inline= "1")
  22.  
  23. tslBull = input.color (color.new(#64b5f6,0) , "" , group= "TSI Signal Line" , inline= "2")
  24. tslBear = input.color (color.new(#d32f2f,0) , "" , group= "TSI Signal Line" , inline= "2")
  25.  
  26. fillBull = input.color (color.new(#64b5f6,88), "" , group= "Fill Color" , inline= "3")
  27. fillBear = input.color (color.new(#d32f2f,88), "" , group= "Fill Color" , inline= "3")
  28.  
  29. oBot = input.color (color.new(#ff0000,65), "" , group= "Ob/Os Line Color" , inline= "4")
  30. oSold = input.color (color.new(#64b5f6,65), "" , group= "Ob/Os Line Color" , inline= "4")
  31. oZero = input.color (color.new(#b2b5be,65), "" , group= "Ob/Os Line Color" , inline= "4")
  32.  
  33. obBar = input.color (color.new(#ff0000,0), "" , group= "Bar Color" , inline= "5")
  34. neBar = input.color (color.new(#ffffff,0), "" , group= "Bar Color" , inline= "5")
  35. osBar = input.color (color.new(#17ff00,0), "" , group= "Bar Color" , inline= "5")
  36.  
  37. longf = input.int (25 , "Long Length" , group= "TSI Fast Settings")
  38. shortf = input.int (5 , "Short Length" , group= "TSI Fast Settings")
  39. signalf = input.int (14 , "Signal Length" , group= "TSI Fast Settings")
  40.  
  41. longs = input.int (25 , "Long Length" , group= "TSI Slow Settings")
  42. shorts = input.int (13 , "Short Length" , group= "TSI Slow Settings")
  43. signals = input.int (13 , "Signal Length" , group= "TSI Slow Settings")
  44.  
  45. oBotVal = input.int (30 , "Ob Value" , group= "Overbought/Oversold Lines")
  46. oSoldVal = input.int (-30 , "Os Value" , group= "Overbought/Oversold Lines")
  47. lines = input.bool (false , "Show Ob/Os Lines", group= "Overbought/Oversold Lines")
  48. midLine = input.bool (false , "Show Zero Line" , group= "Overbought/Oversold Lines")
  49. tsixVis = input.bool (false , "Ob/Os Curl Color", group= "Overbought/Oversold Lines")
  50. midCol = input.bool (true , "Show White Bars" , group= "Overbought/Oversold Lines")
  51.  
  52. // ================================== //,
  53. // ---> Functional Declarations <---- //
  54. // ================================== //
  55.  
  56. _doubleSmooth(src, longvar, shortvar) =>
  57. fist_smooth = ta.ema(src, longvar)
  58. ta.ema(fist_smooth, shortvar)
  59.  
  60. // ================================== //
  61. // ----> Variable Calculations <----- //
  62. // ================================== //
  63.  
  64. tsifast = strat == "Fast"
  65. tsislow = strat == "Slow"
  66.  
  67. shortvar = tsifast ? shortf : tsislow ? shorts : na
  68. longvar = tsifast ? longf : tsislow ? longs : na
  69. signalvar = tsifast ? signalf : tsislow ? signals : na
  70.  
  71. pc = ta.change (close)
  72. dSmoothPc = _doubleSmooth (pc, longvar, shortvar)
  73. dSmoothAbs = _doubleSmooth (math.abs(pc), longvar, shortvar)
  74. tsi = 100 * (dSmoothPc/ dSmoothAbs)
  75. tsl = ta.ema (tsi, signalvar)
  76.  
  77. // ================================== //
  78. // ----> Conditional Parameters <---- //
  79. // ================================== //
  80.  
  81. data = tsi > tsi[1] and tsi < tsl
  82. dtat = tsi < tsi[1] and tsi > tsl
  83.  
  84. lot1 = tsl >= tsl[1]
  85. lot2 = tsl < tsl[1]
  86.  
  87. data1 = tsi >= tsl
  88. data2 = tsi < tsl
  89.  
  90. obcol = tsi > oBotVal and tsi < tsi[1] and tsi[1] > tsl[1]
  91. oscol = tsi < oSoldVal and tsi > tsi[1] and tsi[1] < tsl[1]
  92.  
  93. buy = ta.crossover (tsi, tsl)
  94. sell = ta.crossunder (tsi, tsl)
  95. cross = ta.cross (tsi, tsl)
  96.  
  97. tsixup = ta.crossover (tsi, oBotVal)
  98. tsixdwn = ta.crossunder (tsi, oSoldVal)
  99.  
  100. myCol = data ? tsiBull : dtat ? tsiBear : tsiMid
  101. jercol = obcol ? obBar : oscol ? osBar : midCol ? neBar : na
  102. lotCol = lot1 ? tslBull : lot2 ? tslBear : na
  103. fillCol = data1 ? fillBull: data2 ? fillBear: na
  104.  
  105. // ================================== //
  106. // ------> Graphical Display <------- //
  107. // ================================== //
  108.  
  109. p1 = plot(tsi , "TSI Value Line" , myCol)
  110. p2 = plot(tsl , "TSI Signal Line" , lotCol)
  111. p3 = plot(oBotVal , "Overbought" , lines ? oBot : na)
  112. p4 = plot(oSoldVal, "Oversold" , lines ? oSold: na)
  113. p5 = plot(0 , "Zero" , midLine ? oZero: na)
  114.  
  115. fill (p1, p2, title="Fill Color" , color= fillCol)
  116. barcolor (tsixVis ? jercol : na)
  117.  
  118. // ================================== //
  119. // -----> Alert Functionality <------ //
  120. // ================================== //
  121.  
  122. alertcondition(buy , 'TSI cross up' , 'TSI crossed up on {{interval}} chart. Price is {{close}}')
  123. alertcondition(sell , 'TSI cross down' , 'TSI crossed down on {{interval}} chart. Price is {{close}}')
  124. alertcondition(cross , 'TSI cross' , 'TSI crossed on {{interval}} chart. Price is {{close}}')
  125. alertcondition(data , 'TSI Curl Up' , 'TSI curled up on {{interval}} chart. Price is {{close}}')
  126. alertcondition(dtat , 'TSI Curl Down' , 'TSI curled down on {{interval}} chart. Price is {{close}}')
  127. alertcondition(tsixup , 'TSI Overbought' , 'TSI moved in to overbought on {{interval}} chart. Price is {{close}}')
  128. alertcondition(tsixdwn, 'TSI Oversold' , 'TSI moved in to oversold on {{interval}} chart. Price is {{close}}')
  129. alertcondition(obcol , 'TSI Curl Overbought', 'TSI Curled Down In Overbought on {{interval}} chart. Price is {{close}}')
  130. alertcondition(oscol , 'TSI Curl Oversold' , 'TSI Curled Up In Oversold on {{interval}} chart. Price is {{close}}')
  131.  
  132.  
  133. // ____ __ _ ____
  134. // ( __)( ( \( \
  135. // ) _) / / ) D (
  136. // (____)\_)__)(____/
  137.  
  138.  
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement