Advertisement
Davilae177

M_C_B 2020

Feb 14th, 2020 (edited)
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.15 KB | None | 0 0
  1. //@version=4
  2.  
  3. study(title="M C B ", shorttitle="M C B ")
  4.  
  5. // FUNCTIONS {
  6.  
  7. // MA Selector
  8. ma(matype, src, length) =>
  9. if matype == "RMA"
  10. rma(src, length)
  11. else
  12. if matype == "SMA"
  13. sma(src, length)
  14. else
  15. if matype == "EMA"
  16. ema(src, length)
  17. else
  18. if matype == "WMA"
  19. wma(src, length)
  20. else
  21. src
  22.  
  23. // } FUNCTIONS
  24.  
  25.  
  26. // PARAMETERS {
  27.  
  28. // WaveTrend Channel Length
  29. n1 = input(7, "WT Channel Length")
  30. // WaveTrend Average Length
  31. n2 = input(14, "WT Average Length")
  32.  
  33. // WaveTrend MA Params
  34. wtMA = input(defval="EMA", title="WT MA Type", options=["RMA", "SMA", "EMA", "WMA"])
  35. wtMA1 = input(defval="EMA", title="WT MA Type 1", options=["RMA", "SMA", "EMA", "WMA"])
  36. wtMA2 = input(defval="WMA", title="WT MA Type 2", options=["RMA", "SMA", "EMA", "WMA"])
  37. wtMA3 = input(defval="SMA", title="WT MA Type 3", options=["RMA", "SMA", "EMA", "WMA"])
  38. wtMA4 = input(defval="EMA", title="WT MA Type 4", options=["RMA", "SMA", "EMA", "WMA"])
  39. wtMA5 = input(defval="WMA", title="WT MA Type 5", options=["RMA", "SMA", "EMA", "WMA"])
  40.  
  41. // WaveTrend Overbought & Oversold lines
  42. obLevel = input(53, "WT Overbought Level 1")
  43. obLevel2 = input(60, "WT Overbought Level 2")
  44. obLevel3 = input(38.2, "WT Overbought Level 3 (fib)")
  45. obLevel4 = input(61.8, "WT Overbought Level 4 (fib)")
  46. osLevel = input(-53, "WT Oversold Level 1")
  47. osLevel2 = input(-60, "WT Oversold Level 2")
  48. osLevel3 = input(-80, "WT Oversold Level 3")
  49. osLevel4 = input(-38.2, "WT Oversold Level 4 (fib")
  50. osLevel5 = input(61.8, "WT Oversold Level 5 (fib")
  51.  
  52. // WaveTrend MA Source
  53. AP=input(hlc3, "source",type=input.source)
  54. useHA=input(true,"Use heikin ashi candles?")
  55. ha_AP=security(heikinashi(syminfo.tickerid), timeframe.period, AP)
  56. ap = useHA?ha_AP:AP
  57. //ap = input(ohlc4, "WaveTrend MA Source")
  58.  
  59. // WaveTrend MA Length
  60. sp = input(3, "WaveTrend MA Length 1")
  61. sp1 = input(8, "WaveTrend MA Length 2")
  62. sp2 = input(13, "WaveTrend MA Length 3")
  63.  
  64. // RSI Divergence detector ranges
  65. bearish_div_rsi = input(60, "Min Bearish RSI", input.integer, minval=50, maxval=100)
  66. bullish_div_rsi = input(30, "Max Bullish RSI", input.integer, minval=0, maxval=50)
  67.  
  68. // RSI+MFI Period
  69. rsiMFIperiod = input(72, "RSI+MFI Period")
  70.  
  71. //RSI+MFI Area multiplier
  72. rsiMFIMultiplier = input(100, "RSI+MFI Area multiplier")
  73.  
  74. // Colors
  75. colorRed = #ff0000
  76. colorPurple = #da00ff
  77. colorGreen = #03ff00
  78. colorOrange = color.orange
  79.  
  80.  
  81. // Divergence WT
  82. WTDivOBLevel = input(55)
  83. WTDivOSLevel = input(-60)
  84.  
  85. // Divergence RSI
  86. RSIDivOBLevel = input(60)
  87. RSIDivOSLevel = input(40)
  88.  
  89. // } PARAMETERS
  90.  
  91.  
  92. // CALCULATE INDICATORS {
  93.  
  94. // RSI + MFI Area
  95. candleValue = (close - open) / (high - low)
  96. MVC = vwma(candleValue, rsiMFIperiod)
  97. color_area = MVC > 0 ? color.green : color.red
  98.  
  99. // RSI
  100. up = rma(max(change(close), 0), 14)
  101. down = rma(-min(change(close), 0), 14)
  102. rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
  103. rsiColor = rsi < bullish_div_rsi ? color.green : rsi > bearish_div_rsi ? color.red : color.purple
  104.  
  105. out = ema(rsi,14)
  106. plot(out, color=color.yellow)
  107.  
  108. // Calculates WaveTrend
  109. //useHA=input(true,"Use heikin ashi candles?")
  110. //ha_AP=security(heikinashi(tickerid), period, AP)
  111. //ap = useHA?ha_AP:AP
  112. esa = ma(wtMA, ap, n1)
  113. de = ma(wtMA1, abs(ap - esa), n1)
  114. ci = (ap - esa) / (0.015 * de)
  115. tci = ma(wtMA2, ci, n2)
  116. wt1 = tci
  117. wt2 = ma(wtMA3, wt1, sp)
  118. wt3 = ma(wtMA4, wt1, sp1)
  119. wt4 = ma(wtMA5, wt1, sp2)
  120.  
  121. // VWAP
  122. vwap_area = wt1 - wt2
  123.  
  124. // WaveTrend Conditions
  125. WTCross = cross(wt1, wt2)
  126. WTCrossUp = wt2 - wt1 <= 0
  127. WTCrossDown = wt2 - wt1 >= 0
  128. WTOverSold = wt2 <= osLevel
  129. WTOverBought = wt2 >= obLevel
  130. WTGoldBuy = wt2 <= osLevel3
  131.  
  132. // Godmode
  133. extended = wt2<-75 ? wt2-5 : na//? wt2+5 : wt2>75 ? wt2-5 : na
  134. extended2 = wt2<20// ? wt2+5 : wt2>80 ? wt2-5 : na
  135. extended3 = wt2>85 ? wt2+5 : na// ? wt2+5 : wt2>85 ? wt2-5 : na
  136.  
  137. bgcolor(color=extended ? #008C8C : na, transp=90)
  138. //bgcolor(color=extended2 ? yellow : na, transp=90)
  139. bgcolor(color=extended3 ? #B20000 : na, transp=80)
  140.  
  141. //DIVERGENCE
  142. f_top_fractal(_src) => _src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and _src[2] > _src[0]
  143. f_bot_fractal(_src) => _src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and _src[2] < _src[0]
  144. f_fractalize(_src) => f_top_fractal(_src) ? 1 : f_bot_fractal(_src) ? -1 : 0
  145.  
  146. //DIVERGENCE WAVETREND
  147. WTFractal_top = f_fractalize(wt2) > 0 and wt2[2] >= WTDivOBLevel ? wt2[2] : na
  148. WTFractal_bot = f_fractalize(wt2) < 0 and wt2[2] <= WTDivOSLevel ? wt2[2] : na
  149.  
  150. WTHigh_prev = valuewhen(WTFractal_top, wt2[2], 0)[2]
  151. WTHigh_price = valuewhen(WTFractal_top, high[2], 0)[2]
  152. WTLow_prev = valuewhen(WTFractal_bot, wt2[2], 0)[2]
  153. WTLow_price = valuewhen(WTFractal_bot, low[2], 0)[2]
  154.  
  155. WTRegular_bearish_div = WTFractal_top and high[2] > WTHigh_price and wt2[2] < WTHigh_prev
  156. WTRegular_bullish_div = WTFractal_bot and low[2] < WTLow_price and wt2[2] > WTLow_prev
  157.  
  158. bearWTSignal = WTRegular_bearish_div and WTCrossDown
  159. bullWTSignal = WTRegular_bullish_div and WTCrossUp
  160.  
  161. WTCol1 = bearWTSignal ? color.red : na
  162. WTCol2 = bullWTSignal ? #00FF00EB : na
  163.  
  164. //DIVERGENCE RSI
  165. RSIFractal_top = f_fractalize(rsi) > 0 and rsi[2] >= RSIDivOBLevel ? rsi[2] : na
  166. RSIFractal_bot = f_fractalize(rsi) < 0 and rsi[2] <= RSIDivOSLevel ? rsi[2] : na
  167.  
  168. RSIHigh_prev = valuewhen(RSIFractal_top, rsi[2], 0)[2]
  169. RSIHigh_price = valuewhen(RSIFractal_top, high[2], 0)[2]
  170. RSILow_prev = valuewhen(RSIFractal_bot, rsi[2], 0)[2]
  171. RSILow_price = valuewhen(RSIFractal_bot, low[2], 0)[2]
  172.  
  173. bearRSISignal = RSIFractal_top and high[2] > RSIHigh_price and rsi[2] < RSIHigh_prev
  174. bullRSISignal = RSIFractal_bot and low[2] < RSILow_price and rsi[2] > RSILow_prev
  175.  
  176. RSICol1 = bearRSISignal ? #ff0000: na
  177. RSICol2 = bullRSISignal ? #00FF00EB : na
  178.  
  179. // Small Circles WT Cross
  180. signalColor = wt2 - wt1 > 0 ? color.red : color.lime
  181.  
  182. // Buy signal
  183. buySignal = WTCross and WTCrossUp and WTOverSold
  184. bigBuySignal = cross(wt1[2], wt2[2]) and WTCrossUp and (bullRSISignal or bullWTSignal)
  185. buySignalColor = bigBuySignal ? colorPurple : buySignal ? colorGreen : na
  186. plotBuy = bigBuySignal ? bigBuySignal : buySignal
  187.  
  188. // Sell signal
  189. sellSignal = WTCross and WTCrossDown and WTOverBought
  190. bigSellSignal = cross(wt1[2], wt2[2]) and WTCrossDown and (bearRSISignal or bearWTSignal)
  191. sellSignalColor = bigSellSignal ? colorPurple : sellSignal ? colorRed : na
  192. plotSell = bigSellSignal ? bigSellSignal : sellSignal
  193.  
  194. // Gold Buy
  195. plotWTGoldBuy = WTCross and WTCrossUp and WTGoldBuy
  196.  
  197. // } CALCULATE INDICATORS
  198.  
  199.  
  200. // DRAW {
  201. // 0 Line
  202. plot(0, title="0 Line", color=color.gray)
  203.  
  204. // Draw Overbought & Oversold lines
  205. plot(obLevel, title="Over Bought Level 1", color=color.gray, linewidth=2, style=plot.style_stepline, transp=15)
  206. plot(obLevel2, title="Over Bought Level 2", color=color.gray, style=plot.style_cross, transp=60)
  207. plot(osLevel, title="Over Sold Level 1", color=color.gray, linewidth=2, style=plot.style_stepline, transp=15)
  208. plot(osLevel2, title="Over Sold Level 2", color=color.gray, style=plot.style_cross, transp=60)
  209. plot(obLevel3, title="Overbought Level 3", color=#00FFAA, style=plot.style_line, transp=70)
  210. plot(obLevel4, title="Overbought Level 4", color=#00FFFF, style=plot.style_line, transp=70)
  211. plot(osLevel4, title="Oversold Level 4", color=#00FFAA, style=plot.style_line, transp=70)
  212. plot(osLevel5, title="Oversold Level 5", color=#00FFFF, style=plot.style_line, transp=70)
  213.  
  214. // DIVERGENCES
  215. plot(series = WTFractal_top ? wt2[2] : na, title='Bearish Divergence', color=WTCol1, linewidth=2, transp=40)
  216. plot(series = WTFractal_bot ? wt2[2] : na, title='Bullish Divergence', color=WTCol2, linewidth=2, transp=40)
  217. plot(series = RSIFractal_top ? rsi[2] : na, title='Bearish Divergence', color=RSICol1, linewidth=2, transp=40)
  218. plot(series = RSIFractal_bot ? rsi[2] : na, title='Bullish Divergence', color=RSICol2, linewidth=2, transp=40)
  219.  
  220. // RSI
  221. plot(rsi, title="RSI", color=rsiColor, linewidth=1, transp=35)
  222.  
  223. // RSI + MFI AREA
  224. RSIMFIplot = plot(MVC * rsiMFIMultiplier, title="RSI+MFI Area", color=color_area, transp=35)
  225. fill(RSIMFIplot, plot(0), color_area, transp=35)
  226.  
  227. // RSI + MFI BAR
  228. rsimfiBarTopLine = plot(-85, title="RSI+MFI Bar TOP Line", color=color.black, transp=60)
  229. rsimfiBarBottomLine = plot(-95, title="RSI+MFI Bar BOTTOM Line", color=color.black, transp=60)
  230. fill(rsimfiBarTopLine, rsimfiBarBottomLine, color=color_area)
  231.  
  232. // WT Area 1
  233. plot(wt1, style=plot.style_area, title="WT Wave 1", color=#0ae6ff, transp=10)
  234. // WT Area 2
  235. plot(wt2, style=plot.style_area, title="WT Wave 2", color=#0042ff, transp=10)
  236. // WT line 3 (Yewel pink)
  237. plot(wt3, style=plot.style_line, title="WT Wave 3", color=#D900D9, transp=0, linewidth=2)
  238. // WT line 4 (Yewel yellow)
  239. plot(wt4, style=plot.style_line, title="WT Wave 4", color=#FFFF00, transp=0, linewidth=2)
  240.  
  241.  
  242. // VWAP
  243. plot(vwap_area, title="VWAP", color=color.yellow, style=plot.style_area, transp=35)
  244.  
  245. plot(WTCross ? wt2 : na, title="Buy and sell signals", color=signalColor, style=plot.style_circles, linewidth=3, transp=55) // CIRCULOS PEQUEÑOS
  246. plot(plotBuy ? -90 : na, title="Big buy signal", color=buySignalColor, style=plot.style_circles, linewidth=4, transp=0) // SEÑAL DE COMPRA CIRCULO VERDE GRANDE
  247. plot(plotSell ? 90 : na, title="Big short signal", color=sellSignalColor, style=plot.style_circles, linewidth=4, transp=15) // SEÑAL DE VENTA CIRCULO ROJO GRANDE
  248. plot(plotWTGoldBuy ? -110 : na, title="Big short signal", color=color.orange, style=plot.style_circles, linewidth=4, transp=15) // SEÑAL DE VENTA CIRCULO ROJO GRANDE
  249.  
  250. // } DRAW
  251.  
  252. // ALERTS {
  253.  
  254. // BUY
  255. alertcondition(plotBuy != 0, "Buy Signal (Big green circle)", "Green circle WaveTrend Oversold")
  256. alertcondition(bigBuySignal != 0, "Buy Signal (Big green circle + Div)", "Buy signal & WT Bullish Divergence & WT Overbought ")
  257. alertcondition(plotWTGoldBuy != 0, "GOLD Buy Signal (Big GOLDEN circle)", "Green & GOLD circle WaveTrend Overbought")
  258.  
  259. // SELL
  260. alertcondition(plotSell != 0, "Sell Signal (Big red circle)", "Red Circle WaveTrend Overbought")
  261. alertcondition(bigSellSignal != 0, "Sell Signal (Big red circle + Div)", "Buy signal & WT Bearish Divergence & WT Overbought ")
  262.  
  263.  
  264. // } ALERTS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement