TeamTaurus

[TT] MACD + RSI + Stock+ MoneyFlow + Demand Index + Chaikin money flow

May 29th, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © TeamTaurus
  3.  
  4. //@version=4
  5. study(title="TTDivergence", format=format.price)
  6. OsC = input(title="Select OsC",defval="RSI",options=["RSI", "MACD", "Stochastic","Money Flow","Demand Index","Chaikin Money flow"])
  7. //Tradingview built-in divergence indicator script used to show Divergence
  8. //Thanks to Tradingview for providing this unique Built-in Divergence Indicator
  9. PlR = input(title="Pivot Lookback Right", defval=2)
  10. PlL = input(title="Pivot Lookback Left", defval=6)
  11. rUpper = input(title="Max of Lookback Range", defval=60)
  12. rLower = input(title="Min of Lookback Range", defval=5)
  13. PBull = input(title="Plot Bullish", defval=true)
  14. PHBull = input(title="Plot Hidden Bullish", defval=false)
  15. plotBear = input(title="Plot Bearish", defval=true)
  16. PHBear = input(title="Plot Hidden Bearish", defval=false)
  17.  
  18. bearColor = color.red
  19. bullColor = color.green
  20. hiddenBullColor = color.new(color.green, 80)
  21. hiddenBearColor = color.new(color.red, 80)
  22. textColor = color.white
  23. noneColor = color.new(color.white, 100)
  24. [macdline,_,_]=macd(close,12,26,9)
  25.  
  26. P = (close - open) / open
  27. DI = 0.0
  28. Spread = 0.0
  29. H = 0.0
  30. L = 0.0
  31.  
  32. if (high > high[1])
  33. H := high
  34. else
  35. H := high[1]
  36. if (low < low[1])
  37. L := low
  38. else
  39. L := low[1]
  40. Spread := H - L
  41. Spread := avg(Spread, 10)
  42. if (Spread == 0)
  43. Spread := 1
  44. K = (3*close) / Spread
  45. P := P * K
  46. BP = 1.0
  47. SP = 1.0
  48. if (close > open)
  49. BP := volume
  50. SP := volume / P
  51. else
  52. BP := volume / P
  53. SP := volume
  54. if (abs(BP) > abs(SP))
  55. DI := 100*SP/BP
  56. else
  57. DI := 100*BP/SP
  58. DI := ema(DI, 10)
  59.  
  60. ad = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume
  61. cmf = (sum(ad, 20) / sum(volume, 20))*100
  62.  
  63. osc = OsC=="RSI" ? rsi(close,14) : OsC=="MACD" ? macdline : OsC=="Stochastic" ?
  64. sma(stoch(close, high, low, 14), 3) : OsC=="Money Flow" ? mfi(hlc3,14) : OsC=="Demand Index" ? DI :
  65. OsC=="Chaikin Money flow" ? cmf : na
  66.  
  67. plot(osc, title="RSI", linewidth=2, color=#8D1699)
  68. hline(50, title="Middle Line", linestyle=hline.style_dotted)
  69. obLevel = hline(60, title="Overbought", linestyle=hline.style_dotted)
  70. osLevel = hline(40, title="Oversold", linestyle=hline.style_dotted)
  71. fill(obLevel, osLevel, title="Background", color=#9915FF, transp=90)
  72.  
  73. plFound = na(pivotlow(osc, PlL, PlR)) ? false : true
  74. phFound = na(pivothigh(osc, PlL, PlR)) ? false : true
  75.  
  76. _inRange(cond) =>
  77. bars = barssince(cond == true)
  78. rLower <= bars and bars <= rUpper
  79.  
  80. oscHL = osc[PlR] > valuewhen(plFound, osc[PlR], 1) and _inRange(plFound[1])
  81.  
  82. // Price: Lower Low
  83. priceLL = low[PlR] < valuewhen(plFound, low[PlR], 1)
  84.  
  85. bullCond = PBull and priceLL and oscHL and plFound
  86.  
  87. plot(
  88. plFound ? osc[PlR] : na,
  89. offset=-PlR,
  90. title="Regular Bullish",
  91. linewidth=2,
  92. color=(bullCond ? bullColor : noneColor),
  93. transp=0
  94. )
  95.  
  96. plotshape(
  97. bullCond ? osc[PlR] : na,
  98. offset=-PlR,
  99. title="Regular Bullish Label",
  100. text=" Bull ",
  101. style=shape.labelup,
  102. location=location.absolute,
  103. color=bullColor,
  104. textcolor=textColor,
  105. transp=0
  106. )
  107.  
  108. oscLL = osc[PlR] < valuewhen(plFound, osc[PlR], 1) and _inRange(plFound[1])
  109.  
  110. priceHL = low[PlR] > valuewhen(plFound, low[PlR], 1)
  111.  
  112. hiddenBullCond = PHBull and priceHL and oscLL and plFound
  113.  
  114. plot(
  115. plFound ? osc[PlR] : na,
  116. offset=-PlR,
  117. title="Hidden Bullish",
  118. linewidth=2,
  119. color=(hiddenBullCond ? hiddenBullColor : noneColor),
  120. transp=0
  121. )
  122.  
  123. plotshape(
  124. hiddenBullCond ? osc[PlR] : na,
  125. offset=-PlR,
  126. title="Hidden Bullish Label",
  127. text=" H Bull ",
  128. style=shape.labelup,
  129. location=location.absolute,
  130. color=bullColor,
  131. textcolor=textColor,
  132. transp=0
  133. )
  134.  
  135. oscLH = osc[PlR] < valuewhen(phFound, osc[PlR], 1) and _inRange(phFound[1])
  136.  
  137. priceHH = high[PlR] > valuewhen(phFound, high[PlR], 1)
  138.  
  139. bearCond = plotBear and priceHH and oscLH and phFound
  140.  
  141. plot(
  142. phFound ? osc[PlR] : na,
  143. offset=-PlR,
  144. title="Regular Bearish",
  145. linewidth=2,
  146. color=(bearCond ? bearColor : noneColor),
  147. transp=0
  148. )
  149.  
  150. plotshape(
  151. bearCond ? osc[PlR] : na,
  152. offset=-PlR,
  153. title="Regular Bearish Label",
  154. text=" Bear ",
  155. style=shape.labeldown,
  156. location=location.absolute,
  157. color=bearColor,
  158. textcolor=textColor,
  159. transp=0
  160. )
  161.  
  162. oscHH = osc[PlR] > valuewhen(phFound, osc[PlR], 1) and _inRange(phFound[1])
  163.  
  164. priceLH = high[PlR] < valuewhen(phFound, high[PlR], 1)
  165.  
  166. hiddenBearCond = PHBear and priceLH and oscHH and phFound
  167.  
  168. plot(
  169. phFound ? osc[PlR] : na,
  170. offset=-PlR,
  171. title="Hidden Bearish",
  172. linewidth=2,
  173. color=(hiddenBearCond ? hiddenBearColor : noneColor),
  174. transp=0
  175. )
  176.  
  177. plotshape(
  178. hiddenBearCond ? osc[PlR] : na,
  179. offset=-PlR,
  180. title="Hidden Bearish Label",
  181. text=" H Bear ",
  182. style=shape.labeldown,
  183. location=location.absolute,
  184. color=bearColor,
  185. textcolor=textColor,
  186. transp=0
  187. )
  188. alertcondition(condition = (bullCond or hiddenBullCond), title = "Bullish Divergence", message = "Bullish Divergence")
  189. alertcondition(condition = (bearCond or hiddenBearCond), title = "Bearish Divergence", message = "Bearish Divergence")
Advertisement
Add Comment
Please, Sign In to add comment