Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.90 KB | None | 0 0
  1. //@version=4
  2. // Rhapsodyy's Combo Indicator v12
  3.  
  4. // So to get around the indicator limit built within trading view i've combined
  5. // a bunch of the things i use to save on the indicator count. If you have any suggestions feel free to pass them on.
  6. //
  7. //
  8. // I should think there's neater ways to write some of the code and there may be old code ive
  9. // left in and havn't cleaned up but everything should work as intended.
  10. // Donations if you should so feel inclined: 3Ec8FaLMr2surCWNkTaZWs4jH7UijX8CHT//
  11. //
  12. // Items Included : SMA's & EMA's with Painted Labels / Bollinger Bands / Pivots H/L / EMA Ribbon
  13. // 50EMA/200EMA & 10SMA/21EMA Golden & Death Crosses on Current Timeframe & Alerts
  14. // Daily 50EMA/200EMA & 10SMA/21EMA Golden & Death Crosses overlayed onto Current Timeframe & Alerts
  15. // Buy and Sell Signals for Bollinger Basis Line & Fast EMA Strategy
  16. // Buy and Sell Signals for Golden Shower EMA Behaviour Strategy - FOR 4h TIMEFRAME! For most viable results.
  17. //
  18. // Have listed color codes also.
  19. //
  20. // Simple Moving Averages (SMA):
  21. // These can be changed to any figures or colors you may prefer to use.
  22. // And can be individually or as a whole group turned on and off through settings.
  23. // 10 - Purple - #8A2BE2
  24. // 30 - Cyan - #00FFFF
  25. // 50 - Olive - #556B2F
  26. // 80 - Gold - #DAA520
  27. // 200 - Maroon - #800000
  28. //
  29. // Exponential Moving Averages (EMA):
  30. // These can be changed to any figures you may prefer to use.
  31. // And can be individually or as a whole group turned on and off through settings.
  32. // 21 - Blue - #4682B4
  33. // 50 - Green - #00FF00
  34. // 89 - Yellow - #FFFF00
  35. // 200 - Orange - #FF7F00
  36. // 377 - Red - #FF0000
  37. //
  38. // EMA Ribbon:
  39. // These can be changed to any figures or colors you may prefer to use.
  40. // And can be individually or as a whole group turned on and off through settings.
  41. //
  42. // 20 - #ffff00
  43. // 25 - #f2d90d
  44. // 30 - #f2c60d
  45. // 35 - #fbae04
  46. // 40 - f27d0d
  47. // 45 - #fd6202
  48. // 50 - #f5470a
  49. // 55 - #ff0000
  50. //
  51. // Bollinger Bands - With Included Buy and Sell Signals Following the Below Strategy
  52. //
  53. // Description:
  54. // ============
  55. // This indicator is an implementation of the Bollinger Band and EMA system.
  56. // Id say have a look at it on the chart and see how it performs on different timeframes
  57. // and you'll start to get the idea how it works. Then i start to include signals from MA/EMA's to look for targets or other factors.
  58. //
  59. // Here's the strategy:
  60. // --------------------
  61. // Going LONG:
  62. // Enter a long position when the black 3 EMA has crossed up through the Bollinger red
  63. // middle band MA.This is indicated by "Buy" alert.
  64. //
  65. // Going SHORT:
  66. // Enter a short position when the black 3 EMA has crossed down through the Bollinger red
  67. // middle band MA.This is indicated by the "Sell" Alert.
  68. //
  69. // Stop Loss Ideas:
  70. // The Low (Long) or High (Short) of the candle that printed a buy or sell signal, or the previous candle.
  71. // This could depend on how tight the price action was and how much risk you wanted to take.
  72. // Possible to make a Trailing Stop loss? Or move Stop loss up if first targets hit?
  73. //
  74. // Take Profit Ideas:
  75. // Basic % target, this may be more viable on higher time frames.
  76. // After a signal, targeting a MA/EMA, BB Band.
  77. // As entry and exit signals wont catch exact tops and bottoms, being able to refine the exit signal to fire
  78. // of another input than this Bollinger Strat may be more beneficial.
  79. //
  80. // Increasing Position Size:
  81. // Example: On a Long Entry If candle following signal decreased in price but remained above stop loss at close,
  82. // Could increase position size.
  83. //
  84. // 4hr Golden Shower Strategy
  85. // Based on EMA Behaviour - ONLY to be used on the 4hr for most reliable signals. Credit to CryptoMF
  86. //
  87. // References:
  88. // -----------
  89. // - https://www.forexstrategiesresources.com/scalping-forex-strategies-iii/337-bollinger-bands-and-chaos-awesome-scalping-system
  90. // - "Squeeze Momentum Indicator [LazyBear]"
  91.  
  92. study(title="RhapsCombo v12", shorttitle="RCv12", overlay=true)
  93.  
  94. showSMA1 = input(title="SMA's- 10/30/50/80/200", defval=false)
  95. showEMA1 = input(title="EMA's - 21/50/89/200/377", defval=true)
  96. showTFGDX = input(title='Current TF 50/200 EMA G&D X', defval=false)
  97. showTFGDX2 = input(title='Current TF 10SMA/21EMA G&D X', defval=false)
  98. showDGDX = input(title='Daily 10SMA/21EMA G&D X', defval=false)
  99. showDGDX2 = input(title='Daily 50EMA/200EMA G&D X', defval=false)
  100. showSMA1Labels = input(title="SMA Labels", defval=true)
  101. showEMA1Labels = input(title="EMA Labels", defval=true)
  102. showEMAR = input(title="EMA Ribbon", defval=false)
  103. showPivHL = input(title="Pivots H/L", defval=false)
  104. showBBEMA = input(title="Bollinger Bands", defval=false)
  105. showBBEMABS = input(title="B.Bands Buy/Sell", defval=false)
  106. show4HGS = input(title="4hr Golden Shower Buy/Sell",defval=false)
  107.  
  108.  
  109. //Simple Moving Averages: 10/30/50/80/200
  110. sma10 = sma(close, 10)
  111. sma30 = sma(close, 30)
  112. sma50 = sma(close, 50)
  113. sma80 = sma(close, 80)
  114. sma200 = sma(close, 200)
  115. plot(showSMA1 == true ? sma10 : na, color=#8A2BE2, transp=0, linewidth=1, title='SMA 10')
  116. plot(showSMA1 == true ? sma30 : na, color=#00FFFF, transp=0, linewidth=1, title='SMA 30')
  117. plot(showSMA1 == true ? sma50 : na, color=#556B2F, transp=0, linewidth=1, title='SMA 50')
  118. plot(showSMA1 == true ? sma80 : na, color=#DAA520, transp=0, linewidth=1, title='SMA 80')
  119. plot(showSMA1 == true ? sma200 : na, color=#800000, transp=0, linewidth=1, title='SMA 200')
  120.  
  121. // SMA Labels
  122. plotshape(showSMA1 == true and showSMA1Labels == true ? sma10 : na, style=shape.diamond, location=location.absolute, show_last=1, color=#8A2BE2, transp=0, text="SMA 10\n**Example**", title='SMA 10', offset=10)
  123. plotshape(showSMA1 == true and showSMA1Labels == true ? sma30 : na, style=shape.diamond, location=location.absolute, show_last=1, color=#00FFFF, transp=0, text='SMA 30', title='SMA 30', offset=10)
  124. plotshape(showSMA1 == true and showSMA1Labels == true ? sma50 : na, style=shape.diamond, location=location.absolute, show_last=1, color=#556B2F, transp=0, text='SMA 50', title='SMA 50', offset=10)
  125. plotshape(showSMA1 == true and showSMA1Labels == true ? sma80 : na, style=shape.diamond, location=location.absolute, show_last=1, color=#DAA520, transp=0, text='SMA 80', title='SMA 80', offset=10)
  126. plotshape(showSMA1 == true and showSMA1Labels == true ? sma200 : na, style=shape.diamond, location=location.absolute, show_last=1, color=#800000, transp=0, text='SMA 200', title='SMA 200', offset=10)
  127.  
  128. //Exponential Moving Averages: 21/50/89/200/377
  129. ema21 = ema(close, 21)
  130. ema50 = ema(close, 50)
  131. ema89 = ema(close, 89)
  132. ema200 = ema(close, 200)
  133. ema377 = ema(close, 377)
  134. plot(showEMA1 == true ? ema21 : na, color=#4682B4, transp=0, linewidth=1, title='EMA 21')
  135. plot(showEMA1 == true ? ema50 : na, color=#00FF00, transp=0, linewidth=1, title='EMA 50')
  136. plot(showEMA1 == true ? ema89 : na, color=#FFFF00, transp=0, linewidth=1, title='EMA 89')
  137. plot(showEMA1 == true ? ema200 : na, color=#FF7F00, transp=0, linewidth=1, title='EMA 200')
  138. plot(showEMA1 == true ? ema377 : na, color=#FF0000, transp=0, linewidth=1, title='EMA 377')
  139.  
  140. //EMA Labels
  141. plotshape(showEMA1 == true and showEMA1Labels == true ? ema21 : na, style=shape.diamond, location=location.absolute, show_last=1, color=#4682B4, transp=0, text='EMA 21', title='EMA 21', offset=10)
  142. plotshape(showEMA1 == true and showEMA1Labels == true ? ema50 : na, style=shape.diamond, location=location.absolute, show_last=1, color=#00FF00, transp=0, text='EMA 50', title='EMA 50', offset=10)
  143. plotshape(showEMA1 == true and showEMA1Labels == true ? ema89 : na, style=shape.diamond, location=location.absolute, show_last=1, color=#FFFF00, transp=0, text='EMA 89', title='EMA 89', offset=10)
  144. plotshape(showEMA1 == true and showEMA1Labels == true ? ema200 : na, style=shape.diamond, location=location.absolute, show_last=1, color=#FF7F00, transp=0, text='EMA 200', title='EMA 200', offset=10)
  145. plotshape(showEMA1 == true and showEMA1Labels == true ? ema377 : na, style=shape.diamond, location=location.absolute, show_last=1, color=#FF0000, transp=0, text='EMA 377', title='EMA 377', offset=10)
  146.  
  147. //Current TF Golden & Death Cross: 50EMA & 200EMA
  148. goldenx = crossover(ema50, ema200) and not timeframe.isweekly and not timeframe.ismonthly
  149. deathx = crossunder(ema50, ema200) and not timeframe.isweekly and not timeframe.ismonthly
  150. plotshape(showTFGDX == true ? goldenx : na, style=shape.xcross, location=location.belowbar, color=#00ff00, transp=0, text='GX EMA\n50/200', title='50/200 EMA Golden X', show_last=500, size=size.small)
  151. plotshape(showTFGDX == true ? deathx : na, style=shape.xcross, location=location.abovebar, color=#ff9200, transp=0, text='DX EMA\n50/200', title='50/200 EMA Death X', show_last=500, size=size.small)
  152. alertcondition(goldenx, title='50/200 EMA Golden X', message='50/200 EMA Golden X')
  153. alertcondition(deathx, title='50/200 EMA Death X', message='50/200 EMA Death X')
  154.  
  155. //Current TF Golden & Death Cross: 10SMA & 21 EMA
  156. goldenx2 = crossover(sma10, ema21) and not timeframe.isweekly and not timeframe.ismonthly
  157. deathx2 = crossunder(sma10, ema21) and not timeframe.isweekly and not timeframe.ismonthly
  158. plotshape(showTFGDX2 == true ? goldenx2 : na, style=shape.xcross, location=location.belowbar, color=#00ff00, transp=0, text='GX SEMA\n10/21', title='10SMA/21EMA Golden X', show_last=500, size=size.small)
  159. plotshape(showTFGDX2 == true ? deathx2 : na, style=shape.xcross, location=location.abovebar, color=#ff9200, transp=0, text='DX SEMA\n10/21', title='SMA10/EMA21 Death X', show_last=500, size=size.small)
  160. alertcondition(goldenx2, title='SMA10/EMA21 Golden X', message='SMA10/EMA21 Golden X')
  161. alertcondition(deathx2, title='SMA10/EMA21 Death X', message='SMA10/EMA21 Death X')
  162.  
  163. //Daily Golden & Death Cross: 10SMA & 21 EMA#00ff00
  164. sma10_1d = security(syminfo.tickerid, 'D', sma10)
  165. ema21_1d = security(syminfo.tickerid, 'D', ema21)
  166. sgoldenx_1d = crossover(sma10_1d, ema21_1d) and not timeframe.isweekly and not timeframe.ismonthly
  167. sdeathx_1d = crossunder(sma10_1d, ema21_1d) and not timeframe.isweekly and not timeframe.ismonthly
  168. plotshape(showDGDX == true ? sgoldenx_1d : na, style=shape.xcross, location=location.belowbar, color=#ffe500, transp=0, text='1DGX\n10/21', title='1D 10SMA/21EMA Golden X', show_last=300, size=size.normal)
  169. plotshape(showDGDX == true ? sdeathx_1d : na, style=shape.xcross, location=location.abovebar, color=#ff0000, transp=0, text='1DDX\n10/21', title='1D 10SMA/21EMA Death X', show_last=300, size=size.normal)
  170. alertcondition(sgoldenx_1d, title='1D 10SMA/21EMA Golden X', message='1D 10SMA/21EMA Golden X')
  171. alertcondition(sdeathx_1d, title='1D 10SMA/21EMA Death X', message='1D 10SMA/21EMA Death X')
  172.  
  173. //Daily Golden & Death Cross: 50EMA & 200EMA
  174. ema50_1d = security(syminfo.tickerid, 'D', sma50)
  175. ema200_1d = security(syminfo.tickerid, 'D', ema200)
  176. sgoldenx_1db = crossover(ema50_1d, ema200_1d) and not timeframe.isweekly and not timeframe.ismonthly
  177. sdeathx_1db = crossunder(ema50_1d, ema200_1d) and not timeframe.isweekly and not timeframe.ismonthly
  178. plotshape(showDGDX2 == true ? sgoldenx_1db : na, style=shape.xcross, location=location.belowbar, color=#ffe500, transp=0, text='1DGX EMA\n50/200', title='1D 50EMA/200EMA Golden X', show_last=300, size=size.normal)
  179. plotshape(showDGDX2 == true ? sdeathx_1db : na, style=shape.xcross, location=location.abovebar, color=#ff0000, transp=0, text='1DDX EMA\n50/200', title='1D 50EMA/200EMA Death X', show_last=300, size=size.normal)
  180. alertcondition(sgoldenx_1db, title='1D 10SMA/21EMA Golden X', message='1D 10SMA/21EMA Golden X')
  181. alertcondition(sdeathx_1db, title='1D 10SMA/21EMA Death X', message='1D 10SMA/21EMA Death X')
  182.  
  183. //Exponential Moving Average Ribbon: 20/25/30/35/40/45/50/55
  184. emar20 = ema(close, 20)
  185. emar25 = ema(close, 25)
  186. emar30 = ema(close, 30)
  187. emar35 = ema(close, 35)
  188. emar40 = ema(close, 40)
  189. emar45 = ema(close, 45)
  190. emar50 = ema(close, 50)
  191. emar55 = ema(close, 55)
  192. plot(showEMAR == true ? emar20 : na, color=#ffff00, transp=0, linewidth=1, title='EMAR 20')
  193. plot(showEMAR == true ? emar25 : na, color=#f2d90d, transp=0, linewidth=1, title='EMAR 25')
  194. plot(showEMAR == true ? emar30 : na, color=#f2c60d, transp=0, linewidth=1, title='EMAR 30')
  195. plot(showEMAR == true ? emar35 : na, color=#fbae04, transp=0, linewidth=1, title='EMAR 35')
  196. plot(showEMAR == true ? emar40 : na, color=#f27d0d, transp=0, linewidth=1, title='EMAR 40')
  197. plot(showEMAR == true ? emar45 : na, color=#fd6202, transp=0, linewidth=1, title='EMAR 45')
  198. plot(showEMAR == true ? emar50 : na, color=#f5470a, transp=0, linewidth=1, title='EMAR 50')
  199. plot(showEMAR == true ? emar55 : na, color=#ff0000, transp=0, linewidth=1, title='EMAR 55')
  200.  
  201. //Pivots High/Low
  202. lenH = input(title="Pivot High", type=input.integer, defval=10, minval=1)
  203. lenL = input(title="Pivot Low", type=input.integer, defval=10, minval=1)
  204.  
  205. ph = pivothigh(high, lenH, lenH)
  206. if ph and showPivHL
  207. label.new(bar_index[lenH], ph, tostring(ph), style = label.style_labeldown, yloc = yloc.abovebar, color = #f0ffcc, size = size.small)
  208. pl = pivotlow(low, lenL, lenL)
  209. if pl and showPivHL
  210. label.new(bar_index[lenL], pl, tostring(pl), style = label.style_labelup, yloc = yloc.belowbar, color = #f0ffcc, size = size.small)
  211.  
  212. //Bollinger Bands & Buy/Sell Signals
  213. // Bollinger Bands Inputs
  214. bb_use_ema = input(false, title="Use EMA for Bollinger Band")
  215. bb_length = input(20, minval=1, title="Bollinger Length")
  216. bb_source = input(close, title="Bollinger Source")
  217. bb_mult = input(2.0, title="Bollinger Base Multiplier", minval=0.5, maxval=10)
  218. // EMA inputs
  219. fast_ma_len = input(3, title="Fast EMA length", minval=2)
  220. // Awesome Inputs
  221. nLengthSlow = input(34, minval=1, title="Awesome Length Slow")
  222. nLengthFast = input(5, minval=1, title="Awesome Length Fast")
  223. // === SERIES ===
  224. // Breakout Indicator Inputs
  225. ema_1 = ema(bb_source, bb_length)
  226. sma_1 = sma(bb_source, bb_length)
  227. bb_basis = bb_use_ema ? ema_1 : sma_1
  228. fast_ma = ema(bb_source, fast_ma_len)
  229. // Deviation
  230. // * I'm sure there's a way I could write some of this cleaner, but meh.
  231. dev = stdev(bb_source, bb_length)
  232. bb_dev_inner = bb_mult * dev
  233. // Upper bands
  234. inner_high = bb_basis + bb_dev_inner
  235. // Lower Bands
  236. inner_low = bb_basis - bb_dev_inner
  237. // Calculate Awesome Oscillator
  238. xSMA1_hl2 = sma(hl2, nLengthFast)
  239. xSMA2_hl2 = sma(hl2, nLengthSlow)
  240. xSMA1_SMA2 = xSMA1_hl2 - xSMA2_hl2
  241. // Calculate direction of AO
  242. AO = xSMA1_SMA2 >= 0 ? xSMA1_SMA2 > xSMA1_SMA2[1] ? 1 : 2 :
  243. xSMA1_SMA2 > xSMA1_SMA2[1] ? -1 : -2
  244. // === PLOTTING ===
  245. // plot BB upper bands
  246. ubi = plot(series=showBBEMA ? inner_high : na, title="Upper Band Inner", color=#20B2AA, transp=10, linewidth=1)
  247. // plot BB basis
  248. plot(series=showBBEMA ? bb_basis : na, title="Basis Line", color=#8B4513, transp=10, linewidth=1)
  249. // plot BB lower bands
  250. lbi = plot(series=showBBEMA ? inner_low : na, title="Lower Band Inner", color=#20B2AA, transp=10, linewidth=1)
  251. // center BB channel fill
  252. fill(ubi, lbi, title="Center Channel Fill", color=color.silver, transp=98)
  253. // plot fast ma
  254. plot(series=showBBEMA ? fast_ma : na, title="Fast EMA", color=#A52A2A, transp=10, linewidth=1)
  255. // Calc breakouts
  256. break_down = crossunder(fast_ma, bb_basis) and close < bb_basis
  257. break_up = crossover(fast_ma, bb_basis) and close > bb_basis
  258. break_All = crossunder(fast_ma, bb_basis) and close < bb_basis or
  259. crossover(fast_ma, bb_basis) and close > bb_basis
  260. // Show Break Alerts
  261. plotshape(series=showBBEMABS ? break_down : na, title="Breakout Down", style=shape.arrowdown, location=location.abovebar, size=size.auto, text="Sell", color=color.red, transp=0)
  262. plotshape(series=showBBEMABS ? break_up : na, title="Breakout Up", style=shape.arrowup, location=location.belowbar, size=size.auto, text="Buy", color=color.green, transp=0)
  263. // Send alert to TV alarm sub-system
  264. alertcondition(break_down or break_up, title="BBEMA_Alert", message="BBEMA_Alert")
  265. alertcondition(break_up, title="BBEMA: Break Up", message="BBEMA: Break Up")
  266. alertcondition(break_down, title="BBEMA: Break Down", message="BBEMA: Break Down")
  267.  
  268.  
  269. //Golden Shower 4hr Buy/Sell
  270. // Credit to CryptoMF
  271. // Get inputs and stuff
  272.  
  273. emaLength = input(defval=21, title="Golden.S EMA Length", minval=1)
  274. trendLength = input(defval=120, title="Golden.S Trend Length", minval=1)
  275. trigger = input(defval=10, title="Golden.S Sensitivity", minval=1)
  276.  
  277. // Calc dat moving everage
  278. close4h = security(syminfo.tickerid, '240', close)
  279. ema = ema(close4h, emaLength)
  280. trend = ema(close4h, trendLength)
  281.  
  282. // Calculate candle types
  283. wasLongEntryCandle() =>
  284. rising(ema[1], trigger) and close[1] > trend
  285. wasShortEntryCandle() =>
  286. falling(ema[1], trigger) and close[1] < trend
  287. wasLongExitCandle() =>
  288. falling(ema[1], trigger) and close[1] > trend
  289. wasShortExitCandle() =>
  290. rising(ema[1], trigger) and close[1] < trend
  291.  
  292. isLongEntryCandle() =>
  293. rising(ema, trigger) and close > trend and barssince(wasLongEntryCandle()) > 5
  294. isShortEntryCandle() =>
  295. falling(ema, trigger) and close < trend and barssince(wasShortEntryCandle()) > 5
  296. isLongExitCandle() =>
  297. falling(ema, trigger) and close > trend and not wasLongExitCandle() and
  298. not wasShortEntryCandle()
  299. isShortExitCandle() =>
  300. rising(ema, trigger) and close < trend and not wasShortExitCandle() and
  301. not wasLongEntryCandle()
  302.  
  303. isLong() =>
  304. barssince(wasLongEntryCandle()) < barssince(wasLongExitCandle()) and
  305. barssince(wasLongEntryCandle()) < barssince(wasShortExitCandle()) and
  306. barssince(wasLongEntryCandle()) < barssince(wasShortEntryCandle())
  307. isShort() =>
  308. barssince(wasShortEntryCandle()) < barssince(wasLongExitCandle()) and
  309. barssince(wasShortEntryCandle()) < barssince(wasShortExitCandle()) and
  310. barssince(wasShortEntryCandle()) < barssince(wasLongEntryCandle())
  311. isFlat() =>
  312. not(isLong() or isShort())
  313.  
  314. // Determine long and short entries and exits
  315. longEntry = (isFlat() or isShort()) and isLongEntryCandle()
  316. shortEntry = (isFlat() or isLong()) and isShortEntryCandle()
  317. longExit = isLong() and isLongExitCandle()
  318. shortExit = isShort() and isShortExitCandle()
  319.  
  320. // Some manual plots done on chart without using strategy engine
  321. plotshape(show4HGS == true ? longEntry : na, location=location.belowbar, style=shape.arrowup, text='Long Entry', color=color.lime, textcolor=color.lime, transp=0)
  322. plotshape(show4HGS == true ? shortEntry : na, style=shape.arrowdown, text='Short Entry', color=color.red, textcolor=#ff001a, transp=0)
  323. plotshape(show4HGS == true ? longExit : na, style=shape.arrowdown, text='Long Exit', color=color.fuchsia, textcolor=color.fuchsia, transp=0)
  324. plotshape(show4HGS == true ? shortExit : na, location=location.belowbar, style=shape.arrowup, text='Short Exit', color=color.fuchsia, textcolor=color.fuchsia, transp=0)
  325.  
  326. // Trade Alert
  327. alertcondition(longEntry, title="Long Entry", message="Golden Shower: Open Long Position")
  328. alertcondition(longExit, title="Long Exit", message="Golden Shower: Exit Long Position")
  329. alertcondition(shortEntry, title="Short Entry", message="Golden Shower: Open Short Position")
  330. alertcondition(shortExit, title="Short Exit", message="Golden Shower: Exit Short Position")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement