Advertisement
JustUncleL

Sweetspot Gold R4-RN

Jul 18th, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.80 KB | None | 0 0
  1. //@version=3
  2.  
  3. study(title = "Sweetspot Gold R4-RN - by JustUncleL", shorttitle = "SWSPOT R4-RN", overlay = true, precision=5)
  4.  
  5.  
  6. // Original Author: @JustUncleL
  7. // Revision: R4
  8. // Date: 22-Dec-2016
  9. //
  10. //
  11. // Description:
  12. // - This revision upgrades "Sweetspot Gold R3"
  13. // - This works well for all currency pairs I've tested, most commodities, and most stocks.
  14. // - The indicator plots the so called "round price levels" or "00" levels, which end on 00, 50, 25 etc.
  15. // For example, 1.4000, 1.4400, 1.4450.
  16. // - It automatically calculates the levels for each chart time frame and sublevels. Or can manually
  17. // select main level size (in pips)
  18. // - Use this indicator as a guidance to a better mapping of Support/Resistance levels on the chart.
  19. // Next time you draw Support/Resistance lines, if they coincide with round price levels, especially "00",
  20. // you have got a excellent S/R level to work with!
  21. //
  22. // === REVISIONS ===
  23. //
  24. // Revision R4-RN:
  25. // - RN version created to implement one Main level plotting, typically used in Higher Time charts.
  26. // - Lowered limits on Manual levels to 1pip, this helps with exotics and non-currency charts.
  27. // Revision R4:
  28. // - Modified code to improve Automatic mode calculations, so now works better with exotic pairs,
  29. // Commodities, Indices and Stocks.
  30. // - Modified some Automatic level and sublevel selections.
  31. // Revision R3:
  32. // - Added number of sub levels, both auto and manual options.
  33. // - Automaically calculate grid size based on chart resolution and asset.
  34. // - This revision replaces "Sweetspot Gold2", "Sweetspot Gold4" and "Sweetspot Gold10"
  35. //
  36. // Revision R2:
  37. // - Fixed bug with displaying commodities
  38. //
  39. //
  40.  
  41. // === INPUTS ===
  42. uAuto = input(true,title="Use Automatic Levels")
  43. swLevel_ = input(defval = 100,title = "Sweetspot Levels - Pips", minval=1,step=1) * 10
  44. avgLen_ = input(100, minval=1, title = "Average Level, Period Length (Used to centre Drawing)")
  45. // === /INPUTS ===
  46.  
  47. // === FUNCTIONS ===
  48.  
  49. // Function to find number of digits in an integer number, thanks to RS.
  50. f_int_n_digits(_input_value)=>
  51. _value = abs(_input_value)
  52. _n_digits = 0
  53. if _value > 0
  54. _n_digits := 1
  55. if _value >= 10
  56. _n_digits := 2
  57. if _value >= 100
  58. _n_digits := 3
  59. if _value >= 1000
  60. _n_digits := 4
  61. if _value >= 10000
  62. _n_digits := 5
  63. if _value >= 100000
  64. _n_digits := 6
  65. if _value >= 1000000
  66. _n_digits := 7
  67. if _value >= 10000000
  68. _n_digits := 8
  69. if _value >= 100000000
  70. _n_digits := 9
  71. if _value >= 1000000000
  72. _n_digits := 10
  73. _return = _n_digits
  74.  
  75. // === /FUNCTIONS ===
  76.  
  77. // === CONSTANTS and SERIES ===
  78. // Select Levels and Sub-Levels based on Time frame.
  79. swLevel = not uAuto? swLevel_ : ismonthly ? 10000 : isweekly ? 10000 : isdaily ? 5000 : isintraday ? interval>=240 ? 5000 : interval>=1 ? 1000 : 1000 :1000
  80. avgLen = not uAuto? avgLen_ : ismonthly ? 100 : isweekly ? 100 : isdaily ? 200 : isintraday ? interval>=240 ? 200 : interval>=5 ? 200 : interval>=1 ? 100 : 100 :100
  81.  
  82. //
  83. // Calculate an Average for the centre line.
  84. ZZ = sum(hl2,avgLen)/avgLen
  85.  
  86. // How digits in the current price avg.
  87. dg = f_int_n_digits(round(ZZ[1]))
  88.  
  89. // get this symbols point tick value, normally 0.01 for JPY and BATS symbols and 0.00001 for the rest.
  90. point = syminfo.mintick
  91.  
  92. // Dynamically adjust the multiplier to the number of digits left of Decimal and point value.
  93. mul = syminfo.prefix == "BATS" ? dg<=1? 1.0 :
  94. point<0.05 and dg>=2? pow(10,dg-3) :
  95. point<0.5 and dg>=3? pow(10,dg-4) :
  96. point<5.0 and dg>=4? pow(10,dg-5) :
  97. point<50.0 and dg>=5? pow(10,dg-6):
  98. point<500.0 and dg>=6? pow(10,dg-7): 1.0 :
  99. dg<=1? 1.0 :
  100. point<0.00005 and dg>=2? pow(10,dg-1) :
  101. point<0.0005 and dg>=3? pow(10,dg-2) :
  102. point<0.005 and dg>=4? pow(10,dg-3) :
  103. point<0.05 and dg>=5? pow(10,dg-4):
  104. point<0.5 and dg>=6? pow(10,dg-5): 1.0
  105.  
  106.  
  107. // -- debugs
  108. //plotshape(point,location=location.bottom,color=red)
  109. //plotshape(dg,location=location.bottom,color=red)
  110. //plotshape(mul,location=location.bottom,color=red)
  111.  
  112. // Calculate the "00" centre Level and Scale increment
  113. ZZ_000 = floor((ZZ/(point*swLevel*mul)))*point*swLevel*mul
  114. INC = point*swLevel*mul
  115.  
  116. // Calculate Main levels
  117. ZH_100 = ZZ_000 + INC
  118. ZH_200 = ZH_100 + INC
  119. ZH_300 = ZH_200 + INC
  120. ZH_400 = ZH_300 + INC
  121. ZH_500 = ZH_400 + INC
  122. ZH_600 = ZH_500 + INC
  123. ZH_700 = ZH_600 + INC
  124. ZH_800 = ZH_700 + INC
  125. ZH_900 = ZH_800 + INC
  126. ZH1000 = ZH_900 + INC
  127. ZH1100 = ZH1000 + INC
  128. ZH1200 = ZH1100 + INC
  129. ZH1300 = ZH1200 + INC
  130. ZH1400 = ZH1300 + INC
  131. ZH1500 = ZH1400 + INC
  132. ZH1600 = ZH1500 + INC
  133. ZH1700 = ZH1600 + INC
  134. ZH1800 = ZH1700 + INC
  135. ZH1900 = ZH1800 + INC
  136. ZH2000 = ZH1900 + INC
  137. ZH2100 = ZH2000 + INC
  138. ZH2200 = ZH2100 + INC
  139. ZH2300 = ZH2200 + INC
  140. ZH2400 = ZH2300 + INC
  141. ZH2500 = ZH2400 + INC
  142. ZH2600 = ZH2500 + INC
  143. ZH2700 = ZH2600 + INC
  144. ZH2800 = ZH2700 + INC
  145. ZH2900 = ZH2800 + INC
  146. ZH3000 = ZH2900 + INC
  147.  
  148. ZL_100 = ZZ_000 - INC
  149. ZL_200 = ZL_100 - INC
  150. ZL_300 = ZL_200 - INC
  151. ZL_400 = ZL_300 - INC
  152. ZL_500 = ZL_400 - INC
  153. ZL_600 = ZL_500 - INC
  154. ZL_700 = ZL_600 - INC
  155. ZL_800 = ZL_700 - INC
  156. ZL_900 = ZL_800 - INC
  157. ZL1000 = ZL_900 - INC
  158. ZL1100 = ZL1000 - INC
  159. ZL1200 = ZL1100 - INC
  160. ZL1300 = ZL1200 - INC
  161. ZL1400 = ZL1300 - INC
  162. ZL1500 = ZL1400 - INC
  163. ZL1600 = ZL1500 - INC
  164. ZL1700 = ZL1600 - INC
  165. ZL1800 = ZL1700 - INC
  166. ZL1900 = ZL1800 - INC
  167. ZL2000 = ZL1900 - INC
  168. ZL2100 = ZL2000 - INC
  169. ZL2200 = ZL2100 - INC
  170. ZL2300 = ZL2200 - INC
  171. ZL2400 = ZL2300 - INC
  172. ZL2500 = ZL2400 - INC
  173. ZL2600 = ZL2500 - INC
  174. ZL2700 = ZL2600 - INC
  175. ZL2800 = ZL2700 - INC
  176. ZL2900 = ZL2800 - INC
  177. ZL3000 = ZL2900 - INC
  178. //
  179. //
  180. // === /CONSTANTS and SERIES ===
  181.  
  182. // === PLOTTING ===
  183.  
  184. // Plot the main levels
  185. plot( ZH3000, title="ZH3000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  186. plot( ZH2900, title="ZH2900", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  187. plot( ZH2800, title="ZH2800", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  188. plot( ZH2700, title="ZH2700", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  189. plot( ZH2600, title="ZH2600", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  190. plot( ZH2500, title="ZH2500", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  191. plot( ZH2400, title="ZH2400", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  192. plot( ZH2300, title="ZH2300", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  193. plot( ZH2200, title="ZH2200", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  194. plot( ZH2100, title="ZH2100", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  195. plot( ZH2000, title="ZH2000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  196. plot( ZH1900, title="ZH1900", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  197. plot( ZH1800, title="ZH1800", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  198. plot( ZH1700, title="ZH1700", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  199. plot( ZH1600, title="ZH1600", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  200. plot( ZH1500, title="ZH1500", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  201. plot( ZH1400, title="ZH1400", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  202. plot( ZH1300, title="ZH1300", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  203. plot( ZH1200, title="ZH1200", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  204. plot( ZH1100, title="ZH1100", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  205. plot( ZH1000, title="ZH1000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  206. plot( ZH_900, title="ZH_900", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  207. plot( ZH_800, title="ZH_800", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  208. plot( ZH_700, title="ZH_700", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  209. plot( ZH_600, title="ZH_600", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  210. plot( ZH_500, title="ZH_500", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  211. plot( ZH_400, title="ZH_400", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  212. plot( ZH_300, title="ZH_300", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  213. plot( ZH_200, title="ZH_200", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  214. plot( ZH_100, title="ZH_100", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  215. plot( ZZ_000, title="ZZ_000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  216. plot( ZL_100, title="ZL_100", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  217. plot( ZL_200, title="ZL_200", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  218. plot( ZL_300, title="ZL_300", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  219. plot( ZL_400, title="ZL_400", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  220. plot( ZL_500, title="ZL_500", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  221. plot( ZL_600, title="ZL_600", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  222. plot( ZL_700, title="ZL_700", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  223. plot( ZL_800, title="ZL_800", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  224. plot( ZL_900, title="ZL_900", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  225. plot( ZL1000>0?ZL1000:na, title="ZL1000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  226. plot( ZL1100>0?ZL1100:na, title="ZL1100", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  227. plot( ZL1200>0?ZL1200:na, title="ZL1200", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  228. plot( ZL1300>0?ZL1300:na, title="ZL1300", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  229. plot( ZL1400>0?ZL1400:na, title="ZL1400", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  230. plot( ZL1500>0?ZL1500:na, title="ZL1500", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  231. plot( ZL1600>0?ZL1600:na, title="ZL1600", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  232. plot( ZL1700>0?ZL1700:na, title="ZL1700", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  233. plot( ZL1800>0?ZL1800:na, title="ZL1800", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  234. plot( ZL1900>0?ZL1900:na, title="ZL1900", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  235. plot( ZL2000>0?ZL2000:na, title="ZL2000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  236. plot( ZL2100>0?ZL2100:na, title="ZL2100", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  237. plot( ZL2200>0?ZL2200:na, title="ZL2200", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  238. plot( ZL2300>0?ZL2300:na, title="ZL2300", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  239. plot( ZL2400>0?ZL2400:na, title="ZL2400", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  240. plot( ZL2500>0?ZL2500:na, title="ZL2500", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  241. plot( ZL2600>0?ZL2600:na, title="ZL2600", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  242. plot( ZL2700>0?ZL2700:na, title="ZL2700", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  243. plot( ZL2800>0?ZL2800:na, title="ZL2800", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  244. plot( ZL2900>0?ZL2900:na, title="ZL2900", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  245. plot( ZL3000>0?ZL3000:na, title="ZL3000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
  246.  
  247. // === /PLOTTING ===
  248.  
  249. //
  250. //eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement