SHARE
TWEET

Untitled

a guest Nov 16th, 2019 111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //@version=4
  2. study(title="Zulu - Indi Combo v6", shorttitle="CV6", overlay=true)
  3. //
  4. //
  5. // Rhapsodyy's Combo Indicator v6
  6. //
  7. //  So to get around the indicator limit built within trading view i've combined
  8. //  a bunch of the things i use to save on the indicator count.
  9. //
  10. //  I should think there's neater ways to write some of the code and there may be old code ive
  11. //  left in and havn't cleaned up but everything should work as intended.
  12. //
  13. //  Items Included:
  14. //
  15. //  Simple Moving Averages (SMA):
  16. //  These can be changed to any figures or colors you may prefer to use.
  17. //  And can be individually or as a whole group turned on and off through settings.
  18. //  10  - Purple - #8A2BE2
  19. //  30  - Cyan - #00FFFF
  20. //  50  - Olive - #556B2F
  21. //  80  - Gold - #DAA520
  22. //  200 - Maroon - #800000
  23. //
  24. //
  25. //  Exponential Moving Averages (EMA):
  26. //  These can be changed to any figures you may prefer to use.
  27. //  And can be individually or as a whole group turned on and off through settings.
  28. //  21  - Blue - #4682B4
  29. //  50  - Green - #00FF00
  30. //  89  - Yellow - #FFFF00
  31. //  200 - Orange - #FF7F00
  32. //  377 - Red - #FF0000
  33. //
  34. //
  35. //  EMA Ribbon:
  36. //  These can be changed to any figures or colors you may prefer to use.
  37. //  And can be individually or as a whole group turned on and off through settings.
  38. //
  39. //  20 - #ffff00
  40. //  25 - #f2d90d
  41. //  30 - #f2c60d
  42. //  35 - #fbae04
  43. //  40 - f27d0d
  44. //  45 - #fd6202
  45. //  50 - #f5470a
  46. //  55 - #ff0000
  47. //
  48. //  Bollinger Bands - With Included Buy and Sell Signals Following the Below Strategy
  49. //
  50. //
  51. // Description:
  52. // ============
  53. // This indicator is an implementation of the Bollinger Band and EMA system.
  54. // Id say have a look at it on the chart and see how it performs on different timeframes
  55. // 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.
  56. //
  57. //
  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. //
  85. // HINTS: Best trades tend to occur when price reversing bounce off outer band and
  86. // and outside Optional Bollinger Squeeze indication.
  87. //
  88. // References:
  89. // -----------
  90. // - https://www.forexstrategiesresources.com/scalping-forex-strategies-iii/337-bollinger-bands-and-chaos-awesome-scalping-system
  91. // - "Squeeze Momentum Indicator [LazyBear]"
  92. //
  93. //Inputs - Toggle on/off individual components.
  94. showSMA1 = input(title="SMA 1 - 10/50/80/200", type=input.bool, defval=true)
  95. showEMA1 = input(title="EMA 1 - 21/50/89/200/377", type=input.bool, defval=true)
  96. showBBEMA = input(title="Show BBEMA", type=input.bool, defval=true)
  97. showEMAR = input(title="EMAR", type=input.bool, defval=false)
  98. showPivHL = input(title="Pivots H/L", type=input.bool, defval=false)
  99. //
  100. //
  101. //Bollinger Band - Basis Line & Fast Ema Strategy with buy and sell signals.
  102. //Still to do: Tidy up code?
  103.  
  104. // Bollinger Bands Inputs
  105. bb_use_ema = input(false, title="Use EMA for Bollinger Band")
  106. bb_length = input(20, minval=1, title="Bollinger Length")
  107. bb_source = input(close, title="Bollinger Source")
  108. bb_mult = input(2.0, title="Base Multiplier", minval=0.5, maxval=10)
  109. // EMA inputs
  110. fast_ma_len = input(3, title="Fast EMA length", minval=2)
  111. // Awesome Inputs
  112. nLengthSlow = input(34, minval=1, title="Awesome Length Slow")
  113. nLengthFast = input(5, minval=1, title="Awesome Length Fast")
  114. // === SERIES ===
  115. // Breakout Indicator Inputs
  116. ema_1 = ema(bb_source, bb_length)
  117. sma_1 = sma(bb_source, bb_length)
  118. bb_basis = bb_use_ema ? ema_1 : sma_1
  119. fast_ma = ema(bb_source, fast_ma_len)
  120. // Deviation
  121. // * I'm sure there's a way I could write some of this cleaner, but meh.
  122. dev = stdev(bb_source, bb_length)
  123. bb_dev_inner = bb_mult * dev
  124. // Upper bands
  125. inner_high = bb_basis + bb_dev_inner
  126. // Lower Bands
  127. inner_low = bb_basis - bb_dev_inner
  128. // Calculate Awesome Oscillator
  129. xSMA1_hl2 = sma(hl2, nLengthFast)
  130. xSMA2_hl2 = sma(hl2, nLengthSlow)
  131. xSMA1_SMA2 = xSMA1_hl2 - xSMA2_hl2
  132. // Calculate direction of AO
  133. AO = xSMA1_SMA2 >= 0 ? xSMA1_SMA2 > xSMA1_SMA2[1] ? 1 : 2 :
  134.    xSMA1_SMA2 > xSMA1_SMA2[1] ? -1 : -2
  135. // === PLOTTING ===
  136. // plot BB upper bands
  137. ubi = plot(series=showBBEMA ? inner_high : na, title="Upper Band Inner", color=#20B2AA, transp=10, linewidth=1)
  138. // plot BB basis
  139. plot(series=showBBEMA ? bb_basis : na, title="Basis Line", color=#8B4513, transp=10, linewidth=1)
  140. // plot BB lower bands
  141. lbi = plot(series=showBBEMA ? inner_low : na, title="Lower Band Inner", color=#20B2AA, transp=10, linewidth=1)
  142. // center BB channel fill
  143. fill(ubi, lbi, title="Center Channel Fill", color=color.silver, transp=98)
  144. // plot fast ma
  145. plot(series=showBBEMA ? fast_ma : na, title="Fast EMA", color=#A52A2A, transp=10, linewidth=1)
  146. // Calc breakouts
  147. break_down = crossunder(fast_ma, bb_basis) and close < bb_basis
  148. break_up = crossover(fast_ma, bb_basis) and close > bb_basis
  149. break_All = crossunder(fast_ma, bb_basis) and close < bb_basis or
  150.    crossover(fast_ma, bb_basis) and close > bb_basis
  151. // Show Break Alerts
  152. plotshape(series=showBBEMA ? break_down : na, title="Breakout Down", style=shape.arrowdown, location=location.abovebar, size=size.auto, text="Sell", color=color.red, transp=0)
  153. plotshape(series=showBBEMA ? break_up : na, title="Breakout Up", style=shape.arrowup, location=location.belowbar, size=size.auto, text="Buy", color=color.green, transp=0)
  154. // Send alert to TV alarm sub-system
  155. alertcondition(break_down or break_up, title="BBEMA_Alert", message="BBEMA_Alert")
  156. alertcondition(break_up, title="BBEMA: Break Up", message="BBEMA: Break Up")
  157. alertcondition(break_down, title="BBEMA: Break Down", message="BBEMA: Break Down")
  158. //
  159. //
  160. // Still to do for all EMA/SMA: Print Label of EMA/SMA value at end of line.
  161. // Print cross on certain crosses on certain time frames?
  162. // Alert conditions for those crosses
  163. //
  164. //SMA 1 - 20/50/80/100/200
  165.  
  166. MA1 = input(10, minval=1, title="SMA 1 - 10")
  167. MA2 = input(30, minval=1, title="SMA 1 - 30")
  168. MA3 = input(50, minval=1, title="SMA 1 - 50")
  169. MA4 = input(80, minval=1, title="SMA 1 - 80")
  170. MA5 = input(200, minval=1, title="SMA 1 - 100")
  171. //
  172. xPrice = input(close, title="Source")
  173. //
  174. xMA1 = sma(xPrice, MA1)
  175. xMA2 = sma(xPrice, MA2)
  176. xMA3 = sma(xPrice, MA3)
  177. xMA4 = sma(xPrice, MA4)
  178. xMA5 = sma(xPrice, MA5)
  179. //
  180. plot(xMA1, color=iff(showSMA1, #8A2BE2, na), transp=0, linewidth=1, style=plot.style_line, title="SMA 1 - 10")
  181. plot(xMA2, color=iff(showSMA1, #00FFFF, na), transp=25, linewidth=1, style=plot.style_line, title="SMA 1 - 30")
  182. plot(xMA3, color=iff(showSMA1, #556B2F, na), transp=0, linewidth=1, style=plot.style_line, title="SMA 1 - 50")
  183. plot(xMA4, color=iff(showSMA1, #DAA520, na), transp=0, linewidth=1, style=plot.style_line, title="SMA 1 - 80")
  184. plot(xMA5, color=iff(showSMA1, #800000, na), transp=0, linewidth=1, style=plot.style_line, title="SMA 1 - 200")
  185. //
  186. //
  187. //EMA1 //
  188.  
  189. EMA1 = input(21, minval=1, title="EMA 1 - 21")
  190. EMA2 = input(50, minval=1, title="EMA 1 - 50")
  191. EMA3 = input(89, minval=1, title="EMA 1 - 89")
  192. EMA4 = input(200, minval=1, title="EMA 1 - 200")
  193. EMA5 = input(377, minval=1, title="EMA 1 - 377")
  194. //
  195. xPrice6 = input(close, title="Source")
  196. //
  197. xEMA1 = ema(xPrice6, EMA1)
  198. xEMA2 = ema(xPrice6, EMA2)
  199. xEMA3 = ema(xPrice6, EMA3)
  200. xEMA4 = ema(xPrice6, EMA4)
  201. xEMA5 = ema(xPrice6, EMA5)
  202. //
  203. plot(xEMA1, color=iff(showEMA1, #4682B4, na), transp=10, linewidth=1, style=plot.style_line, title="EMA 1 - 21")
  204. plot(xEMA2, color=iff(showEMA1, color.lime, na), transp=10, linewidth=1, style=plot.style_line, title="EMA 1 - 50")
  205. plot(xEMA3, color=iff(showEMA1, color.yellow, na), transp=10, linewidth=1, style=plot.style_line, title="EMA 1 - 89")
  206. plot(xEMA4, color=iff(showEMA1, color.orange, na), transp=10, linewidth=1, style=plot.style_line, title="EMA 1 - 200")
  207. plot(xEMA5, color=iff(showEMA1, color.red, na), transp=20, linewidth=1, style=plot.style_line, title="EMA 1 - 377")
  208. //
  209. //
  210. //EMA Ribbon
  211.  
  212. EMA10 = input(20, minval=1, title="EMAR - 20")
  213. EMA11 = input(25, minval=1, title="EMAR - 25")
  214. EMA12 = input(30, minval=1, title="EMAR - 30")
  215. EMA13 = input(35, minval=1, title="EMAR - 35")
  216. EMA14 = input(40, minval=1, title="EMAR - 40")
  217. EMA15 = input(45, minval=1, title="EMAR - 45")
  218. EMA16 = input(50, minval=1, title="EMAR - 50")
  219. EMA17 = input(55, minval=1, title="EMAR - 55")
  220. //
  221. xPrice7 = input(close, title="Source")
  222. //
  223. xEMA10 = ema(xPrice7, EMA10)
  224. xEMA11 = ema(xPrice7, EMA11)
  225. xEMA12 = ema(xPrice7, EMA12)
  226. xEMA13 = ema(xPrice7, EMA13)
  227. xEMA14 = ema(xPrice7, EMA14)
  228. xEMA15 = ema(xPrice7, EMA15)
  229. xEMA16 = ema(xPrice7, EMA16)
  230. xEMA17 = ema(xPrice7, EMA17)
  231. //
  232. plot(xEMA10, color=iff(showEMAR, #ffff00, na), transp=10, linewidth=1, style=plot.style_line, title="EMAR - 20")
  233. plot(xEMA11, color=iff(showEMAR, #f2d90d, na), transp=10, linewidth=1, style=plot.style_line, title="EMAR - 25")
  234. plot(xEMA12, color=iff(showEMAR, #f2c60d, na), transp=10, linewidth=1, style=plot.style_line, title="EMAR - 30")
  235. plot(xEMA13, color=iff(showEMAR, #fbae04, na), transp=10, linewidth=1, style=plot.style_line, title="EMAR - 35")
  236. plot(xEMA14, color=iff(showEMAR, #f27d0d, na), transp=20, linewidth=1, style=plot.style_line, title="EMAR - 40")
  237. plot(xEMA15, color=iff(showEMAR, #fd6202, na), transp=10, linewidth=1, style=plot.style_line, title="EMAR - 45")
  238. plot(xEMA16, color=iff(showEMAR, #f5470a, na), transp=10, linewidth=1, style=plot.style_line, title="EMAR - 50")
  239. plot(xEMA17, color=iff(showEMAR, #ff0000, na), transp=20, linewidth=1, style=plot.style_line, title="EMAR - 55")
  240. //
  241. //
  242. //Pivots High / Low
  243. //Still to do:
  244.  
  245. lenH = input(title="Pivot High", type=input.integer, defval=10, minval=1)
  246. lenL = input(title="Pivot Low", type=input.integer, defval=10, minval=1)
  247.  
  248. ph = pivothigh(high, lenH, lenH)
  249. if ph and showPivHL
  250.     label.new(bar_index[lenH], ph, tostring(ph), style = label.style_labeldown, yloc = yloc.abovebar, color = #f0ffcc, size = size.small)
  251. pl = pivotlow(low, lenL, lenL)
  252. if pl and showPivHL
  253.     label.new(bar_index[lenL], pl, tostring(pl), style = label.style_labelup, yloc = yloc.belowbar, color = #f0ffcc, size = size.small)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top