Advertisement
xmd79

Euler Cubes

Jan 3rd, 2023
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.28 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. // © fikira
  3. //@version=5
  4. indicator('Euler Cubes', shorttitle='Cubᵋ', overlay=true)
  5.  
  6. extN = 'extend none'
  7. extL = 'extend left'
  8. extR = 'extend right'
  9. extB = 'extend both'
  10.  
  11. useDt = input.bool(false, title='', group='Year - Month - Day', inline='date')
  12. Year = input.int(2021, title='', group='Year - Month - Day', inline='date')
  13. Month = input.int(5, minval=1, maxval=12, title='', group='Year - Month - Day', inline='date')
  14. Day = input.int(18, minval=1, maxval=31, title='', group='Year - Month - Day', inline='date')
  15.  
  16. Time = timestamp(Year, Month, Day, hour, minute, second)
  17.  
  18. Tdiff = useDt ? math.floor((timenow - Time) / (time_close[1] - time_close[2])) : 0
  19.  
  20. iLbsB = input.int(1, minval=0, title='Bars Back', group='source low', inline='low') + Tdiff + 1
  21. iLsrc = input.source(low, title='', group='source low', inline='low')
  22. iHbsB = input.int(1, minval=0, title='Bars Back', group='source high', inline='high') + Tdiff + 1
  23. iHsrc = input.source(high, title='', group='source high', inline='high')
  24.  
  25. // Euler-Mascheroni constant gamma γ = 0.57721566490153286060651209008240243...
  26. // ('Euler's constant', not to be confused with the constant e=2.718281...)
  27. // golden ratio conjugate constant = 0.6180339887498948 = math.rphi
  28. // the golden ratio constant = 1.6180339887498948 = math.phi
  29. // Euler's number (Leonhard Euler) e = 2,71828182845904523536028747135266249... = math.e
  30. // Archimedes' constant pi π = 3.1415926535897932 = math.pi
  31. // constant of Mitchell Feigenbaum δ ≈ 4.66920160910299067185320382046620161...
  32.  
  33. C_ = input.string('Euler', title='constant', options=['Euler-Mascheroni', 'Golden Ratio conjugate', 'Golden Ratio', 'Euler', 'Pi', 'Feigenbaum'])
  34. C = C_ == 'Euler-Mascheroni' ? 0.57721566490153286060651209008240243 : C_ == 'Golden Ratio conjugate' ? math.rphi : C_ == 'Golden Ratio' ? math.phi : C_ == 'Euler' ? math.e : C_ == 'Pi' ? math.pi : 4.66920160910299067185320382046620161
  35.  
  36. i_e = input(6., title='x times \'e\'') * C / 10
  37. i_deg_ = input.int(0, minval=-90, maxval=90, step=1, title='Degrees')
  38.  
  39. i_ext_ = input.string(extN, options=[extN, extL, extR, extB], title='extend lines')
  40.  
  41. i_eulma = input.bool(false, title='\'Eulma\'', group='Show Euler SMA/EMA', inline='eul')
  42. i_eulema = input.bool(false, title='\'Eulema\'', group='Show Euler SMA/EMA', inline='eul')
  43.  
  44. i_ext = i_ext_ == extN ? extend.none : i_ext_ == extL ? extend.left : i_ext_ == extR ? extend.right : extend.both
  45.  
  46. a_angle = array.new_float()
  47. // https://www.mathcelebrity.com/anglebasic.php?entry=78&pl=cos
  48.  
  49. // sin 90° - sin 61°
  50. array.push(a_angle, 1.)
  51. array.push(a_angle, 0.99985)
  52. array.push(a_angle, 0.99939)
  53. array.push(a_angle, 0.99863)
  54. array.push(a_angle, 0.99756)
  55. array.push(a_angle, 0.99619)
  56. array.push(a_angle, 0.99452)
  57. array.push(a_angle, 0.99255)
  58. array.push(a_angle, 0.99027)
  59. array.push(a_angle, 0.98769)
  60. array.push(a_angle, 0.98481)
  61. array.push(a_angle, 0.98163)
  62. array.push(a_angle, 0.97815)
  63. array.push(a_angle, 0.97437)
  64. array.push(a_angle, 0.9703)
  65. array.push(a_angle, 0.966)
  66. array.push(a_angle, 0.96126)
  67. array.push(a_angle, 0.9563)
  68. array.push(a_angle, 0.95106)
  69. array.push(a_angle, 0.94552)
  70. array.push(a_angle, 0.93969)
  71. array.push(a_angle, 0.93358)
  72. array.push(a_angle, 0.92718)
  73. array.push(a_angle, 0.9205)
  74. array.push(a_angle, 0.91355)
  75. array.push(a_angle, 0.90631)
  76. array.push(a_angle, 0.89879)
  77. array.push(a_angle, 0.891)
  78. array.push(a_angle, 0.88295)
  79. array.push(a_angle, 0.87462)
  80. // sin 60° - sin 31°
  81. array.push(a_angle, 0.866)
  82. array.push(a_angle, 0.85717)
  83. array.push(a_angle, 0.84805)
  84. array.push(a_angle, 0.83867)
  85. array.push(a_angle, 0.82904)
  86. array.push(a_angle, 0.81915)
  87. array.push(a_angle, 0.80902)
  88. array.push(a_angle, 0.79864)
  89. array.push(a_angle, 0.78801)
  90. array.push(a_angle, 0.77715)
  91. array.push(a_angle, 0.76604)
  92. array.push(a_angle, 0.75471)
  93. array.push(a_angle, 0.74314)
  94. array.push(a_angle, 0.73135)
  95. array.push(a_angle, 0.71934)
  96. array.push(a_angle, 0.70711)
  97. array.push(a_angle, 0.69466)
  98. array.push(a_angle, 0.682)
  99. array.push(a_angle, 0.66913)
  100. array.push(a_angle, 0.65606)
  101. array.push(a_angle, 0.64279)
  102. array.push(a_angle, 0.62932)
  103. array.push(a_angle, 0.61566)
  104. array.push(a_angle, 0.60182)
  105. array.push(a_angle, 0.58779)
  106. array.push(a_angle, 0.57358)
  107. array.push(a_angle, 0.55919)
  108. array.push(a_angle, 0.54464)
  109. array.push(a_angle, 0.52992)
  110. array.push(a_angle, 0.51504)
  111. // sin 30° - sin 0°
  112. array.push(a_angle, 0.5)
  113. array.push(a_angle, 0.48481)
  114. array.push(a_angle, 0.46947)
  115. array.push(a_angle, 0.454)
  116. array.push(a_angle, 0.43837)
  117. array.push(a_angle, 0.42262)
  118. array.push(a_angle, 0.40674)
  119. array.push(a_angle, 0.39073)
  120. array.push(a_angle, 0.37461)
  121. array.push(a_angle, 0.35837)
  122. array.push(a_angle, 0.34202)
  123. array.push(a_angle, 0.32557)
  124. array.push(a_angle, 0.30902)
  125. array.push(a_angle, 0.29237)
  126. array.push(a_angle, 0.27564)
  127. array.push(a_angle, 0.25882)
  128. array.push(a_angle, 0.24192)
  129. array.push(a_angle, 0.22495)
  130. array.push(a_angle, 0.20791)
  131. array.push(a_angle, 0.19081)
  132. array.push(a_angle, 0.17365)
  133. array.push(a_angle, 0.15643)
  134. array.push(a_angle, 0.13917)
  135. array.push(a_angle, 0.12187)
  136. array.push(a_angle, 0.10453)
  137. array.push(a_angle, 0.08716)
  138. array.push(a_angle, 0.06976)
  139. array.push(a_angle, 0.05234)
  140. array.push(a_angle, 0.0349)
  141. array.push(a_angle, 0.01745)
  142. array.push(a_angle, 0.)
  143.  
  144. f_time(x) =>
  145. (time - time[1]) * math.round(x)
  146.  
  147. i_deg = math.abs(i_deg_)
  148.  
  149. deg_0_end = array.get(a_angle, i_deg)
  150. deg_end_0 = i_deg_ >= 0 ? array.get(a_angle, array.size(a_angle) - i_deg - 1) : -array.get(a_angle, array.size(a_angle) - i_deg - 1)
  151.  
  152. f_update(mult) =>
  153. xbl = timenow - (time - time[1]) * math.round(iLbsB)
  154. xbr = timenow - (time - time[1])
  155. xtl = timenow - (time - time[1]) * math.round(iLbsB)
  156. xtr = timenow - (time - time[1])
  157. ybl = iLsrc[iLbsB - 1]
  158. ybr = iLsrc[iLbsB - 1]
  159. ytl = iHsrc[iHbsB - 1]
  160. ytr = iHsrc[iHbsB - 1]
  161. Hx = xbr - xbl
  162. Hy = ytl - ybl
  163.  
  164. xbr := xbl + math.round(mult * Hx * deg_0_end)
  165. ybr := ybl + mult * Hy * deg_end_0
  166. xtl -= math.round(mult * Hx * deg_end_0)
  167. ytl := ybl + mult * Hy * deg_0_end
  168. xtr := xtl + math.round(mult * Hx * deg_0_end)
  169. ytr := ytl + mult * Hy * deg_end_0
  170. [xbl, ybl, xbr, ybr, xtl, ytl, xtr, ytr]
  171.  
  172. [xbl, ybl, xbr, ybr, xtl, ytl, xtr, ytr] = f_update(1)
  173. [xbl2, ybl2, xbr2, ybr2, xtl2, ytl2, xtr2, ytr2] = f_update(i_e)
  174. [xbl3, ybl3, xbr3, ybr3, xtl3, ytl3, xtr3, ytr3] = f_update(i_e * i_e)
  175. [xbl4, ybl4, xbr4, ybr4, xtl4, ytl4, xtr4, ytr4] = f_update(i_e * i_e * i_e)
  176. [xbl5, ybl5, xbr5, ybr5, xtl5, ytl5, xtr5, ytr5] = f_update(i_e * i_e * i_e * i_e)
  177.  
  178. f_line(xbl, ybl, xbr, ybr, xtl, ytl, xtr, ytr, xdashed, ydashed, color, ext) =>
  179. l_b = line.new(xbl, ybl, xbr, ybr, xloc=xloc.bar_time, color=color, width=1, extend=extend.none)
  180. line.delete(l_b[1])
  181. l_l = line.new(xbl, ybl, xtl, ytl, xloc=xloc.bar_time, color=color, width=1, extend=extend.none)
  182. line.delete(l_l[1])
  183. l_r = line.new(xbr, ybr, xtr, ytr, xloc=xloc.bar_time, color=color, width=1, extend=extend.none)
  184. line.delete(l_r[1])
  185. l_t = line.new(xtl, ytl, xtr, ytr, xloc=xloc.bar_time, color=color, width=1, extend=ext)
  186. line.delete(l_t[1])
  187. l_ = line.new(xdashed, ydashed, xtr, ytr, xloc=xloc.bar_time, color=color, style=line.style_dotted)
  188. line.delete(l_[1])
  189. if i_ext != extend.none
  190. _l = line.new(xbl, ybl, xbr, ybr, xloc=xloc.bar_time, color=color.white, extend=ext)
  191. line.delete(_l[1])
  192.  
  193. if barstate.islast
  194. f_line(xbl, ybl, xbr, ybr, xtl, ytl, xtr, ytr, xbl, ybl, color.lime, i_ext)
  195. f_line(xbl, ybl, xbr2, ybr2, xtl2, ytl2, xtr2, ytr2, xtr, ytr, color.red, i_ext)
  196. f_line(xbl, ybl, xbr3, ybr3, xtl3, ytl3, xtr3, ytr3, xtr2, ytr2, color.yellow, i_ext)
  197. f_line(xbl, ybl, xbr4, ybr4, xtl4, ytl4, xtr4, ytr4, xtr3, ytr3, color.aqua, i_ext)
  198. f_line(xbl, ybl, xbr5, ybr5, xtl5, ytl5, xtr5, ytr5, xtr4, ytr4, color.fuchsia, i_ext)
  199.  
  200. labL = label.new(bar_index[iLbsB - 1], ybl, yloc=yloc.price, style=label.style_label_up, color=color.lime, size=size.tiny)
  201. label.delete(labL[1])
  202. labH = label.new(bar_index[iHbsB - 1], ytl, yloc=yloc.price, style=label.style_label_down, color=color.red, size=size.tiny)
  203. label.delete(labH[1])
  204.  
  205. lineD = line.new(xbl, ybl, xtl2, ytl2, xloc=xloc.bar_time, extend=extend.none, width=1, color=color.red)
  206. line.delete(lineD[1])
  207.  
  208. //if barstate.islast
  209. // f_line(xbl , ybl, xbr , ybr , xtl , ytl , xtr , ytr, color.lime , extend.none)
  210. // f_line(xbr , ybr, xbr2, ybr2, xtm2, ytm2, xtr2, ytr2, color.red , extend.none)
  211. // f_line(xbr , ybr, xbr3, ybr3, xtm3, ytm3, xtr3, ytr3, color.yellow, extend.none)
  212.  
  213. //ratio = 1.0000000 - (1.0000000 / i_e) // 0.666666
  214. //xbm2 := round(avg(xbl2, xbr2))
  215. //xtm2 := round(xtr2 - ((xtr2 - xtl2)*ratio)) // !!!!!!!!!!!!!!!!!!
  216. //ybm2 := avg(ytl2, ybl2)
  217. //ytm2 := ytr2 - ((ytr2 - ytl2)*ratio) // !!!!!!!!!!!!!!!!!!
  218.  
  219. // Euler SMA - EMA
  220. i_len1 = math.round(C * 10 * 1)
  221. i_len2 = math.round(C * 10 * 2)
  222. i_len3 = math.round(C * 10 * 3)
  223. i_len4 = math.round(C * 10 * 4)
  224. i_len5 = math.round(C * 10 * 5)
  225. i_len6 = math.round(C * 10 * 6)
  226. i_len7 = math.round(C * 10 * 7)
  227. i_len8 = math.round(C * 10 * 8)
  228.  
  229. eulma1 = float(na)
  230. eulma2 = float(na)
  231. eulma3 = float(na)
  232. eulma4 = float(na)
  233. eulma5 = float(na)
  234. eulma6 = float(na)
  235. eulma7 = float(na)
  236. eulma8 = float(na)
  237. eulema1 = float(na)
  238. eulema2 = float(na)
  239. eulema3 = float(na)
  240. eulema4 = float(na)
  241. eulema5 = float(na)
  242. eulema6 = float(na)
  243. eulema7 = float(na)
  244. eulema8 = float(na)
  245.  
  246. if i_eulma
  247. eulma1 := ta.sma(close, i_len1) // 27
  248. eulma2 := ta.sma(close, i_len2) // 54
  249. eulma3 := ta.sma(close, i_len3) // 82
  250. eulma4 := ta.sma(close, i_len4) // 109
  251. eulma5 := ta.sma(close, i_len5) // 136
  252. eulma6 := ta.sma(close, i_len6) // 163
  253. eulma7 := ta.sma(close, i_len7) // 190
  254. eulma8 := ta.sma(close, i_len8) // 217
  255. eulma8
  256.  
  257. if i_eulema
  258. eulema1 := ta.ema(close, i_len1) // 27
  259. eulema2 := ta.ema(close, i_len2) // 54
  260. eulema3 := ta.ema(close, i_len3) // 82
  261. eulema4 := ta.ema(close, i_len4) // 109
  262. eulema5 := ta.ema(close, i_len5) // 136
  263. eulema6 := ta.ema(close, i_len6) // 163
  264. eulema7 := ta.ema(close, i_len7) // 190
  265. eulema8 := ta.ema(close, i_len8) // 217
  266. eulema8
  267.  
  268. plot(eulma1, color=color.new(color.yellow, 0))
  269. plot(eulma2, color=color.new(color.aqua, 0))
  270. plot(eulma3, color=color.new(color.orange, 0))
  271. plot(eulma4, color=color.new(color.white, 0))
  272. plot(eulma5, color=color.new(color.orange, 0))
  273. plot(eulma6, color=color.new(color.fuchsia, 0))
  274. plot(eulma7, color=color.new(color.red, 0))
  275. plot(eulma8, color=color.new(color.maroon, 0), linewidth=2)
  276.  
  277. plot(eulema1, color=color.new(color.yellow, 0), style=plot.style_circles)
  278. plot(eulema2, color=color.new(color.aqua, 0), style=plot.style_circles)
  279. plot(eulema3, color=color.new(color.orange, 0), style=plot.style_circles)
  280. plot(eulema4, color=color.new(color.white, 0), style=plot.style_circles)
  281. plot(eulema5, color=color.new(color.orange, 0), style=plot.style_circles)
  282. plot(eulema6, color=color.new(color.fuchsia, 0), style=plot.style_circles)
  283. plot(eulema7, color=color.new(color.red, 0), style=plot.style_circles)
  284. plot(eulema8, color=color.new(color.maroon, 0), style=plot.style_circles, linewidth=2)
  285.  
  286.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement