xmd79

Chart Game Daily Pivot & Fibo Range With Ultimate Indicator

Oct 12th, 2021
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.41 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. // © tanmay159
  3.  
  4. //@version=4
  5. study(title="Chart Game Daily Pivot & Fibo Range With Ultimate Indicator", shorttitle="Ultimate Pivot", overlay=true)
  6.  
  7.  
  8. daily_cpr = input (title="Select Days", type= input.integer , defval=1, minval=0)
  9. FPeriod = input('D', title="Day/Week/Month", options=["D", "W", "M", "Y"])
  10. adjust = input (title="1-Today 2-Tomorrow", type= input.integer, defval=1, minval=0)
  11. up_fibo = input(title="Upper Fibo levels", type=input.bool, defval=false)
  12. down_fibo = input(title="Lower Fibo levels", type=input.bool, defval=false)
  13. up_pivots = input(title="Upper Pivot levels", type=input.bool, defval=false)
  14. down_pivots = input(title="Lower Pivot levels", type=input.bool, defval=false)
  15. inner_zones = input(title="Inner zones", type=input.bool, defval=true)
  16. minor_zones1 = input(title="Minor +ve SR zones", type=input.bool, defval=false)
  17. minor_zones2 = input(title="Minor -ve SR zones", type=input.bool, defval=false)
  18. High_probable = input(title="High_probable", type=input.bool, defval=false)
  19. //Outside_fibo = input(title="Fibo levels", type=input.bool, defval=false)
  20. //small_fibo = input(title="Minor fibo levels", type=input.bool, defval=false)
  21. //Outside_pivots = input(title="Pivot levels", type=input.bool, defval=false)
  22.  
  23. new_bar(res) => change(time(res)) != 0
  24. new_period(condition, src) =>
  25. result = 0.0
  26. result := condition ? src : result[1]
  27. result
  28.  
  29. Fhigh = security(syminfo.tickerid, FPeriod, high[adjust], lookahead = barmerge.lookahead_on)
  30. Flow = security(syminfo.tickerid, FPeriod, low[adjust], lookahead = barmerge.lookahead_on)
  31. Fclose = security(syminfo.tickerid, FPeriod, close[adjust], lookahead = barmerge.lookahead_on)
  32. Fopen = security(syminfo.tickerid, FPeriod, open[0], lookahead = barmerge.lookahead_on)
  33.  
  34. pivot = (Fhigh + Flow + Fclose) / 3.0
  35. bc = (Fhigh + Flow) / 2.0
  36. tc = (pivot - bc) + pivot
  37. R1 = (2*pivot) - Flow
  38. S1 = (2*pivot) - Fhigh
  39. R2 = pivot + ( Fhigh - Flow)
  40. S2 = pivot - ( Fhigh - Flow)
  41. R3 = Fhigh + (2*(pivot - Flow))
  42. S3 = Flow - (2*(Fhigh - pivot ))
  43. R4 = R3 + (R2 - R1)
  44. S4 = S3 - (S1 - S2)
  45. PH = Fhigh
  46. PL = Flow
  47. PO = Fopen
  48. P_HALF = (Fhigh + Flow) / 2
  49.  
  50. F1618 = (Fhigh-Flow)*1.618+Flow
  51. F2618 = (Fhigh-Flow)*2.618+Flow
  52. F3618 = (Fhigh-Flow)*3.618+Flow
  53. FE618 = (Fhigh-Flow)*(-0.618)+Flow
  54. FE1618 = (Fhigh-Flow)*(-1.618)+Flow
  55. FE2618 = (Fhigh-Flow)*(-2.618)+Flow
  56.  
  57. F1382 = (Fhigh-Flow)*1.382+Flow
  58. F2000 = (Fhigh-Flow)*2.000+Flow
  59. F3000 = (Fhigh-Flow)*3.000+Flow
  60.  
  61. FE382 = (Fhigh-Flow)*(-0.382)+Flow
  62. FE1000 = (Fhigh-Flow)*(-1.000)+Flow
  63. FE2000 = (Fhigh-Flow)*(-2.000)+Flow
  64.  
  65. one_day = 1000 * 60 * 60 * 24
  66. new_day = daily_cpr > 0 and timenow - time < one_day * daily_cpr and new_bar(FPeriod)
  67. dpp_ = new_period(new_day, pivot)
  68. dtc_ = new_period(new_day, tc)
  69. dbc_ = new_period(new_day, bc)
  70. dR1_ = new_period(new_day, R1)
  71. dS1_ = new_period(new_day, S1)
  72. dR2_ = new_period(new_day, R2)
  73. dS2_ = new_period(new_day, S2)
  74. dR3_ = new_period(new_day, R3)
  75. dS3_ = new_period(new_day, S3)
  76. dR4_ = new_period(new_day, R4)
  77. dS4_ = new_period(new_day, S4)
  78. dPH_ = new_period(new_day, PH)
  79. dPL_ = new_period(new_day, PL)
  80. dPO_ = new_period(new_day, PO)
  81. dP_HALF_ = new_period(new_day, P_HALF)
  82. d16_ = new_period(new_day, F1618)
  83. d26_ = new_period(new_day, F2618)
  84. d36_ = new_period(new_day, F3618)
  85. dE06_ = new_period(new_day, FE618)
  86. dE16_ = new_period(new_day, FE1618)
  87. dE26_ = new_period(new_day, FE2618)
  88. d13_ = new_period(new_day, F1382)
  89. d20_ = new_period(new_day, F2000)
  90. d30_ = new_period(new_day, F3000)
  91. dE03_ = new_period(new_day, FE382)
  92. dE10_ = new_period(new_day, FE1000)
  93. dE20_ = new_period(new_day, FE2000)
  94.  
  95. plotR2=plot(up_pivots and dR2_ ? dR2_ : na, title='R2', title="Daily TC", style= plot.style_line , color=#800080, linewidth=1)
  96. label_R2 = label.new(bar_index, up_pivots and dR2_ ? dR2_ : na, text="R2", style=label.style_none)
  97. label.delete(label_R2[1])
  98. plotS2=plot(down_pivots and dS2_ ? dS2_ : na, title='S2', title="Daily TC", style= plot.style_line , color=#008069, linewidth=1)
  99. label_S2 = label.new(bar_index, down_pivots and dS2_ ? dS2_ : na, text="S2", style=label.style_none)
  100. label.delete(label_S2[1])
  101.  
  102. plotR3=plot(up_pivots and dR3_ ? dR3_ : na, title='R3', title="Daily TC", style= plot.style_line , color=#800080, linewidth=1)
  103. label_R3 = label.new(bar_index, up_pivots and dR3_ ? dR3_ : na, text="R3", style=label.style_none)
  104. label.delete(label_R3[1])
  105. plotS3=plot(down_pivots and dS3_ ? dS3_ : na, title='S3', title="Daily TC", style= plot.style_line , color=#008069, linewidth=1)
  106. label_S3 = label.new(bar_index, down_pivots and dS3_ ? dS3_ : na, text="S3", style=label.style_none)
  107. label.delete(label_S3[1])
  108.  
  109. plotR4=plot(up_pivots and dR4_ ? dR4_ : na, title='R4', title="Daily TC", style= plot.style_line , color=#800080, linewidth=1)
  110. label_R4 = label.new(bar_index, up_pivots and dR4_ ? dR4_ : na, text="R4", style=label.style_none)
  111. label.delete(label_R4[1])
  112. plotS4=plot(down_pivots and dS4_ ? dS4_ : na, title='S4', title="Daily TC", style= plot.style_line , color=#008069, linewidth=1)
  113. label_S4 = label.new(bar_index, down_pivots and dS4_ ? dS4_ : na, text="S4", style=label.style_none)
  114. label.delete(label_S4[1])
  115.  
  116. plot(up_fibo and d16_ ? d16_ : na, title='1.618', title="Fibo 1.618", style= plot.style_cross , color=#ff9800, linewidth=1)
  117. label_f1 = label.new(bar_index, up_fibo and d16_ ? d16_ : na, text="1.618%", style=label.style_none)
  118. label.delete(label_f1[1])
  119. plot(down_fibo and dE06_ ? dE06_ : na , title='-0.618', title="Fibo -0.618", style= plot.style_cross , color=#ff9800, linewidth=1)
  120. label_ef1 = label.new(bar_index, down_fibo and dE06_ ? dE06_ : na, text="-0.618%", style=label.style_none)
  121. label.delete(label_ef1[1])
  122.  
  123. plot(up_fibo and d26_ ? d26_ : na, title='2.618', title="Fibo 2.618", style= plot.style_cross , color=color.green, linewidth=1)
  124. label_f2 = label.new(bar_index, up_fibo and d26_ ? d26_ : na, text="2.618%", style=label.style_none)
  125. label.delete(label_f2[1])
  126. plot(down_fibo and dE16_ ? dE16_ : na, title='-1.618', title="Fibo -1.618", style= plot.style_cross , color=color.green, linewidth=1)
  127. label_ef2 = label.new(bar_index, down_fibo and dE16_ ? dE16_ : na, text="-1.618%", style=label.style_none)
  128. label.delete(label_ef2[1])
  129.  
  130. plot(up_fibo and d36_ ? d36_ : na , title='3.618', title="Fibo 3.618", style= plot.style_cross , color=#787b86, linewidth=1)
  131. label_f3 = label.new(bar_index, up_fibo and d36_ ? d36_ : na, text="3.618%", style=label.style_none)
  132. label.delete(label_f3[1])
  133. plot(down_fibo and dE26_ ? dE26_ : na , title='-2.618', title="Fibo -1.618", style= plot.style_cross , color=#787b86, linewidth=1)
  134. label_ef3 = label.new(bar_index, down_fibo and dE26_ ? dE26_ : na, text="-1.618%", style=label.style_none)
  135. label.delete(label_ef3[1])
  136.  
  137. plot(up_fibo and d13_ ? d13_ : na, title='1.382', title="Fibo 1.382", style= plot.style_cross , color=color.green, linewidth=1)
  138. label_f4 = label.new(bar_index, up_fibo and d13_ ? d13_ : na, text="1.382%", style=label.style_none)
  139. label.delete(label_f4[1])
  140. plot(down_fibo and dE03_ ? dE03_ : na , title='-0.382', title="Fibo -0.382", style= plot.style_cross , color=color.green, linewidth=1)
  141. label_ef4 = label.new(bar_index, down_fibo and dE03_ ? dE03_ : na, text="-0.382%", style=label.style_none)
  142. label.delete(label_ef4[1])
  143.  
  144. plot(up_fibo and d20_ ? d20_ : na, title='2.000', title="Fibo 2.000", style= plot.style_cross , color=color.green, linewidth=1)
  145. label_f5 = label.new(bar_index, up_fibo and d20_ ? d20_ : na, text="2.000%", style=label.style_none)
  146. label.delete(label_f5[1])
  147. plot(down_fibo and dE10_ ? dE10_ : na , title='-1.000', title="Fibo -1.000", style= plot.style_cross , color=color.green, linewidth=1)
  148. label_ef5 = label.new(bar_index, down_fibo and dE10_ ? dE10_ : na, text="-1.000%", style=label.style_none)
  149. label.delete(label_ef5[1])
  150.  
  151. plot(up_fibo and d30_ ? d30_ : na, title='3.000', title="Fibo 3.000", style= plot.style_cross , color=#787b86, linewidth=1)
  152. label_f6 = label.new(bar_index, up_fibo and d30_ ? d30_ : na, text="3.000%", style=label.style_none)
  153. label.delete(label_f6[1])
  154. plot(down_fibo and dE20_ ? dE20_ : na , title='-2.000', title="Fibo -2.000", style= plot.style_cross , color=#787b86, linewidth=1)
  155. label_ef6 = label.new(bar_index, down_fibo and dE20_ ? dE20_ : na, text="-2.000%", style=label.style_none)
  156. label.delete(label_ef6[1])
  157.  
  158. //minor zones
  159. plotaR2=plot(minor_zones1 and dR2_ ? dR2_ : na, title='R2', color=#52BE80, style= plot.style_cross, linewidth=0)
  160. plota1382=plot(minor_zones1 and d13_ ? d13_ : na, title='1.382%', color=#3498DB, style= plot.style_cross, linewidth=0)
  161. plotaR3=plot(minor_zones1 and dR3_ ? dR3_ : na, title='R3', color=#52BE80, style= plot.style_cross, linewidth=0)
  162. plota2=plot(minor_zones1 and d20_ ? d20_ : na, title='2.000%', color=#3498DB, style= plot.style_cross, linewidth=0)
  163. plotaR4=plot(minor_zones1 and dR4_ ? dR4_ : na, title='R4', color=#52BE80, style= plot.style_cross, linewidth=0)
  164. plota2618=plot(minor_zones1 and d26_ ? d26_ : na, title='2.618%', color=#3498DB, style= plot.style_cross, linewidth=0)
  165. plota1618=plot(minor_zones1 and d16_ ? d16_ : na, title='1.618%', color=#3498DB, style= plot.style_cross, linewidth=0)
  166. plotaS2=plot(minor_zones2 and dS2_ ? dS2_ : na, title='S2', color=#E74C3C, style= plot.style_cross, linewidth=0)
  167. plotae0382=plot(minor_zones2 and dE03_ ? dE03_ : na, title='-0.382%', color=#D4AC0D, style= plot.style_cross, linewidth=0)
  168. plotaS3=plot(minor_zones2 and dS3_ ? dS3_ : na, title='S3', color=#E74C3C, style= plot.style_cross, linewidth=0)
  169. plotae1=plot(minor_zones2 and dE10_ ? dE10_ : na, title='-1.000%', color=#D4AC0D, style= plot.style_cross, linewidth=0)
  170. plotaS4=plot(minor_zones2 and dS4_ ? dS4_ : na, title='S4', color=#E74C3C, style= plot.style_cross, linewidth=0)
  171. plotae1618=plot(minor_zones2 and dE16_ ? dE16_ : na, title='-1.618%', color=#D4AC0D, style= plot.style_cross, linewidth=0)
  172. plotae0618=plot(minor_zones2 and dE06_ ? dE06_ : na, title='-0.618%', color=#D4AC0D, style= plot.style_cross, linewidth=0)
  173.  
  174. fill(plotaR2, plota1382, color=#D8FFF0, transp=94)
  175. fill(plotaR3, plota2, color=#D8FFF0, transp=94)
  176. fill(plotaR4, plota2618, color=#D8FFF0, transp=94)
  177. fill(plotaS2, plotae0382, color=#D8FFF0, transp=94)
  178. fill(plotaS3, plotae1, color=#D8FFF0, transp=94)
  179. fill(plotaS4, plotae1618, color=#D8FFF0, transp=94)
  180.  
  181. //No trade zone
  182. plotbR1=plot(inner_zones and dR1_ ? dR1_ : na, title='R1', color=#FF0000, style= plot.style_line, linewidth=0)
  183. plotbS1=plot(inner_zones and dS1_ ? dS1_ : na, title='S1', color=#00FF00, style= plot.style_line, linewidth=0)
  184. plotbPDH=plot(inner_zones and dPH_ ? dPH_ : na, title='Previous High', color=#048617, style= plot.style_line, linewidth=1)
  185. plotbPDL=plot(inner_zones and dPL_ ? dPL_ : na, title='Previous Low', color=#C4061F, style= plot.style_line, linewidth=1)
  186. plotbTC=plot(inner_zones and dtc_ ? dtc_ : na, title='TC', color=#FF0000, style= plot.style_cross, linewidth=0)
  187. plotbpp=plot(inner_zones and dpp_ ? dpp_ : na, title='PP', color=#10d4ed, style= plot.style_line, linewidth=1)
  188. plotbBC=plot(inner_zones and dbc_ ? dbc_ : na, title='BC', color=#FF0000, style= plot.style_cross, linewidth=0)
  189. fill(plotbR1, plotbPDH, color=#00FF00, transp=95)
  190. fill(plotbS1, plotbPDL, color=#FF0000, transp=95)
  191. fill(plotbTC, plotbBC, color=#00FFFF, transp=95)
  192.  
  193.  
  194. // High_probable
  195. plotbPDHh=plot(High_probable and dPH_ ? dPH_ : na, title='Previous High', color=#048617, style= plot.style_circles, linewidth=2)
  196. plotbPDLh=plot(High_probable and dPL_ ? dPL_ : na, title='Previous Low', color=#C4061F, style= plot.style_circles, linewidth=2)
  197. plotbpph=plot(High_probable and dP_HALF_ ? dP_HALF_ : na, title='HALF', color=#363A45, style= plot.style_circles, linewidth=1)
  198. plotbpoh=plot(High_probable and dPO_ ? dPO_ : na, title='PO', color=color.yellow, style= plot.style_circles, linewidth=1)
  199.  
  200. // Camarilla
  201. is_cm = input(title="Camarilla", type=input.bool, defval=true)
  202. mode =input(title = "HTF Method", defval = 'User Defined', options=['Auto', 'User Defined'], tooltip = "Choose Of the method to Select the Timeframe")
  203. HTFm = input('D', title = "Time Frame (if HTF Method=User Defined)", type=input.resolution, tooltip = "Manual Timeframe Selection")
  204. showlast = input(title = "Show Only Last Period", defval = true, tooltip = "Shows only Today levels bar by bar")
  205. showlabels = input(title = "Show Labels", defval = true, tooltip = "Shows labels on plotted pivots")
  206. cturnon = input(title = "Turn On Camarilla", defval = true, tooltip = "Turn Camarilla ON")
  207.  
  208. //auto higher time frame
  209. HTFo =timeframe.period == '1' ? '30' :
  210. timeframe.period == '3' ? '60' :
  211. timeframe.period == '5' ? '60' :
  212. timeframe.period == '15' ? '240' :
  213. timeframe.period == '30' ? 'D' :
  214. timeframe.period == '45' ? 'D' :
  215. timeframe.period == '60' ? 'D' :
  216. timeframe.period == '240' ? 'W' :
  217. timeframe.period == 'D' ? '12M' :
  218. timeframe.period == 'W' ? '12M' :
  219. '6M'
  220.  
  221. HTF = mode == 'Auto' ? HTFo : HTFm
  222.  
  223. hhtf = security(syminfo.tickerid, HTF, high[1], lookahead = barmerge.lookahead_on)
  224. lhtf = security(syminfo.tickerid, HTF, low[1], lookahead = barmerge.lookahead_on)
  225. chtf = security(syminfo.tickerid, HTF, close[1], lookahead = barmerge.lookahead_on)
  226.  
  227. rng = hhtf - lhtf
  228.  
  229. // is this last bar for HTF?
  230. islast = showlast ? security(syminfo.tickerid, HTF, barstate.islast, lookahead = true) : true
  231.  
  232.  
  233. linestyleL = plot.style_circles
  234. // Calculation Camarilla
  235. H4 = chtf + rng * 1.1/2
  236. H3 = chtf + rng * 1.1/4
  237. H2 = chtf + rng * 1.1/6
  238. H1 = chtf + rng * 1.1/12
  239. L1 = chtf - rng * 1.1/12
  240. L2 = chtf - rng * 1.1/6
  241. L3 = chtf - rng * 1.1/4
  242. L4 = chtf - rng * 1.1/2
  243. L5 = L4 - 1.168 * (L3 - L4) //L5 = chtf - (H5 - chtf)
  244. H5 = H4 + 1.168 * (H4 - H3) //H5 = (hhtf / lhtf) * chtf
  245. H6 = (hhtf/lhtf) * chtf //H6 = H5 + 1.168 * (H5 - H4)
  246. L6 = chtf - (H6 - chtf) //L6 = chtf - (H6 - chtf)
  247. SLbull = (H4 + H3) / 2
  248. SLbear = (L4 + L3) / 2
  249. mid = (H3 + L3) / 2
  250.  
  251.  
  252. // Color Settings
  253. plot(islast and cturnon ? mid :na,"Mid-H3-L3",color=color.new(#9598a1 ,40), linewidth = 1, style = linestyleL)
  254. plot(islast and cturnon ? SLbull : na,"SLBull H3-H4",color=color.new(#ff0000 , 40), linewidth = 1, style = linestyleL)
  255. plot(islast and cturnon ? SLbear : na, "SLBear L3-L4",color=color.new(#ff0000,40), linewidth = 1, style = linestyleL)
  256.  
  257. // Label for S/R
  258. mndr = time - time[1]
  259. mndr := change(mndr) > 0 ? mndr[1] : mndr
  260.  
  261. Round_it(valu)=>
  262. a = 0
  263. num = syminfo.mintick
  264. s = valu
  265. if na(s)
  266. s := syminfo.mintick
  267. if num < 1
  268. for i = 1 to 20
  269. num := num * 10
  270. if num > 1
  271. break
  272. a := a +1
  273.  
  274. for x = 1 to a
  275. s := s * 10
  276. s := round(s)
  277. for x = 1 to a
  278. s := s / 10
  279. s := s < syminfo.mintick ? syminfo.mintick : s
  280. s
  281.  
  282. // Labels
  283. if showlabels and cturnon
  284. var label s3label = na, var label s4label = na, var label s5label = na, var label s6label = na
  285. var label r3label = na, var label r4label = na, var label r5label = na, var label r6label = na
  286.  
  287. label.delete(s3label), label.delete(s4label), label.delete(s5label), label.delete(s6label)
  288. label.delete(r3label), label.delete(r4label), label.delete(r5label), label.delete(r6label)
  289. s3label := label.new(x = time + mndr * 20, y = L3, text = "......br • " + tostring(Round_it(L3)), color = color.new(color.lime,100), textcolor=color.teal, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
  290. s4label := label.new(x = time + mndr * 20, y = L4, text = "......bd • " + tostring(Round_it(L4)), color = color.new(color.lime,100), textcolor=color.teal, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
  291. s5label := label.new(x = time + mndr * 20, y = L5, text = "......t • " + tostring(Round_it(L5)), color = color.new(color.lime,100), textcolor=color.black, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
  292. s6label := label.new(x = time + mndr * 20, y = L6, text = "......t • " + tostring(Round_it(L6)), color = color.new(color.lime,100), textcolor=color.black, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
  293. r3label := label.new(x = time + mndr * 20, y = H3, text = "......sr • " + tostring(Round_it(H3)), color = color.new(color.lime,100), textcolor=color.maroon, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
  294. r4label := label.new(x = time + mndr * 20, y = H4, text = "......bd • " + tostring(Round_it(H4)), color = color.new(color.lime,100), textcolor=color.maroon, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
  295. r5label := label.new(x = time + mndr * 20, y = H5, text = "......t • " + tostring(Round_it(H5)), color = color.new(color.lime,100), textcolor=color.black, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
  296. r6label := label.new(x = time + mndr * 20, y = H6, text = "......t • " + tostring(Round_it(H6)), color = color.new(color.lime,100), textcolor=color.black, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
  297.  
  298.  
  299. // Exponential Moving Averages
  300. is_EMAs = input(title="Display the EMAs?", type=input.bool, defval=false)
  301. var float ema111 = na
  302. var float ema200 = na
  303. var float ema800 = na
  304. if is_EMAs
  305. ema111 := ema(close, 111)
  306. ema200 := ema(close, 200)
  307. ema800 := ema(close, 800)
  308. plot(ema111, color=color.silver,linewidth=1, title='111 EMA')
  309. plot(ema200, color=color.olive,linewidth=1, title='200 EMA')
  310. plot(ema800, color=color.blue,linewidth=1, title='800 EMA')
  311.  
  312. //Moving average
  313. Moving_Average1 = input(title="Moving_Average_1", type=input.bool, defval=false)
  314. ma_len1 = input(8, minval=1, title="Moving_Average1")
  315. ma_out1 = ema(close, ma_len1)
  316. plot(Moving_Average1 and ma_out1 ? ma_out1 : na, title="EMA1", color=close >= ma_out1 ? #4CAF50 : #FF5252, linewidth = 2, transp=50)
  317.  
  318. Moving_Average2 = input(title="Moving_Average_2", type=input.bool, defval=false)
  319. ma_len2 = input(27, minval=1, title="Moving_Average2")
  320. ma_out2 = ema(close, ma_len2)
  321. plot(Moving_Average2 and ma_out2 ? ma_out2 : na, title="EMA2", color=close >= ma_out2 ? #07b80e : #dc0202, linewidth = 2, transp=0)
  322.  
  323.  
  324. //vwap
  325. Vwap_get = input(title="Vwap", type=input.bool, defval=false)
  326. //plot(Vwap_get and vwap ? vwap : na, title="vwap", color=#00606D, linewidth = 1, transp=0)
  327. plot(Vwap_get and vwap ? vwap : na, title="vwap", color=close >= vwap ? #4CAF50 : #FF5252, linewidth = 2, transp=0)
  328. //mvwap
  329. mvwap_get = input(title="Mvwap", type=input.bool, defval=false)
  330. mvwap_len = input(50, minval=1, title="mvwap length")
  331. mvwap = ema(vwap,mvwap_len)
  332. plot(mvwap_get and mvwap ? mvwap : na, title="mvwap", color=#AB1200, linewidth = 1, transp=0)
  333.  
  334. // Bollinger Bands
  335. is_bb = input(title="Bollinger Bands", type=input.bool, defval=true)
  336. length = input(20, minval=1)
  337. src = input(close, title="Source")
  338. mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
  339. basis = sma(src, length)
  340. dev = mult * stdev(src, length)
  341. upper = basis + dev
  342. lower = basis - dev
  343. offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
  344. plot(basis, "BB Basis", color=#872323, offset = offset)
  345. ip1 = plot(upper, "BB Upper", color=#00897B, offset = offset)
  346. ip2 = plot(lower, "BB Lower", color=#00897B, offset = offset)
  347. fill(ip1, ip2, title = "BB Background", color=color.rgb(33, 150, 243, 95))
  348.  
  349. // SSL Period
  350. is_ssl = input(title="SSL Period", type=input.bool, defval=true)
  351. len = input(10, "SSL Period") //Period of SMA
  352. sma_high = sma(high,len) //SMA of HIGH with period "len"
  353. sma_low = sma(low,len) //SMA of LOW with period "len"
  354. hlv = 0 //Init the "High-Low Value"
  355. ioffset = input(1,"SSL Offset") //Option to offset MA values back
  356.  
  357. //if close is above MA of high, green line on top
  358. //if close is below MA of low, green line on bottom
  359. hlv := close > sma_high[1] ? 1 : close < sma_low[1] ? -1 : hlv[1]
  360. ssld = hlv == -1 ? sma_high[ioffset] : sma_low[ioffset]
  361. sslu = hlv == -1 ? sma_low[ioffset] : sma_high[ioffset]
  362.  
  363. //Plotting
  364. plot(ssld,"SSL Down",color.red,1)
  365.  
  366. ATRTsl = input(false,"Trailing SL", tooltip = "Trailing SL")
  367. // ATR Trailing SL
  368. nATRPeriod = input(5)
  369. nATRMultip = input(3.5)
  370. xATR = atr(nATRPeriod)
  371. nLoss = nATRMultip * xATR
  372. xATRTrailingStop = 0.0
  373. xATRTrailingStop :=iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss),
  374. iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss),
  375. iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))
  376. col=close < xATRTrailingStop[1] ? color.silver : color.black
  377. plot(ATRTsl ? xATRTrailingStop[1]: na, color=col, title="ATR Trailing Stop")
  378.  
  379.  
  380. vsr = input(false, title="Show Volume Based S&R", tooltip = "Shows Volume Based Support and Resistance on Stocks and Futures")
  381.  
  382. ////////////Volume Based Support Resistance
  383. Vlength = input(20, minval=1, group = "Volume S/R Settings")
  384. Vchange = volume/volume[1] - 1
  385. stdev = stdev(Vchange, Vlength)
  386. difference = Vchange / stdev[1]
  387. Treshold = input(5)
  388. zero = 0
  389. signal = abs(difference)
  390. vstylee = plot.style_circles
  391.  
  392. leveluphi = valuewhen(signal > Treshold,high[1],0)
  393. leveluplo = valuewhen(signal > Treshold,low[1],0)
  394.  
  395. //plot(UpperTreshold, color=black)
  396. p1=plot(vsr and leveluphi ? leveluphi : na, title="S/R LevelHi",style=vstylee,color=color.blue)
  397. p2=plot(vsr and leveluplo ? leveluplo : na,title="S/R Levello",style=vstylee,color=color.blue)
  398. fill(p1,p2,color=color.new(color.black,50),title="S/R Background")
Advertisement
Add Comment
Please, Sign In to add comment