xmd79

Prime, E & PI Superiority Cycles

Dec 16th, 2022
216
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.86 KB | None | 0 1
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © Eliza123123 & david4342
  3.  
  4. //@version=5
  5. indicator("Prime, E & PI Superiority Cycles", overlay = true, max_lines_count = 200)
  6.  
  7. // Inputs
  8. Prime = input.bool(true, "On/Off", "", inline = "Colour", group = "Prime Frame")
  9. PrimeCol = input.color(color.new(color.olive,0), "", inline = "Colour", group = "Prime Frame")
  10. Euler = input.bool(true, "On/Off", "", inline = "Colour", group = "E Frame")
  11. EulerCol = input.color(color.new(color.green,0), "", inline = "Colour", group = "E frame")
  12. Pi = input.bool(true, "On/Off", "", inline = "Colour", group = "Pi Frame")
  13. PiCol = input.color(color.new(color.maroon,0), "", inline = "Colour", group = "Pi Frame")
  14.  
  15. //---------------------FRAME CREATION CODE-------------------//
  16.  
  17. // Define constants
  18. pi = 3.14159
  19. e = 2.71828
  20.  
  21. // Initialises and assigns values to the Prime Frame, E frame and Pi Frame.
  22. float[] primes = array.from(2.0,3.0,5.0,7.0,11.0,13.0,17.0,19.0,23.0,27.0,29.0,31.0,37.0,41.0,43.0,47.0,53.0,59.0,61.0,67.0,71.0,73.0,79.0,83.0,89.0,97.0)
  23. float[] eLevels = array.from(2.71828, 5.43656, 8.15484, 10.87312, 13.5914, 16.30968, 19.02796, 21.74624, 24.46452, 27.1828, 29.90108, 32.61936, 35.33764,
  24. 38.05592, 40.7742, 43.49248, 46.21076, 48.92904, 51.64732, 54.3656, 57.08388, 59.80216, 62.52044, 65.23872, 67.957, 70.67528, 73.39356000000001, 76.11184,
  25. 78.83012, 81.5484, 84.26668000000001, 86.98496, 89.70324, 92.42152, 95.13980000000001, 97.85808)
  26. float[] piLevels = array.from(3.14159, 6.28318, 9.424769999999999, 12.56636, 15.70795, 18.849539999999998, 21.99113, 25.13272, 28.27431, 31.4159, 34.55749,
  27. 37.699079999999995, 40.840669999999996, 43.98226, 47.12385, 50.26544, 53.40703, 56.54862, 59.69021, 62.8318, 65.97339, 69.11498, 72.25657, 75.39815999999999,
  28. 78.53975, 81.68133999999999, 84.82293, 87.96452, 91.10611, 94.2477, 97.38929)
  29.  
  30. // Function gets scaling for the asset. This is important as the elements from primes, eLevels and piLevels array need to mutiplied by scale to ensure indicator works on all assets
  31. get_scale_func() =>
  32. get_scale = 0.0
  33. if (close >= 10 and close < 100)
  34. get_scale := 1
  35. if (close >= 100 and close < 1000)
  36. get_scale := 10
  37. if (close >= 1000 and close < 10000)
  38. get_scale := 100
  39. if (close >= 1 and close < 10)
  40. get_scale := 0.1
  41. if (close >= 0.1 and close < 1)
  42. get_scale := 0.01
  43. if (close >= 0.01 and close < 0.1)
  44. get_scale := 0.001
  45. if (close >= 0.001 and close < 0.01)
  46. get_scale := 0.0001
  47. if (close >= 0.0001 and close < 0.001)
  48. get_scale := 0.00001
  49. if (close >= 0.00001 and close < 0.0001)
  50. get_scale := 0.000001
  51. if (close > 10000)
  52. get_scale := 1000
  53. get_scale
  54.  
  55. // Calls and assings cale from get_scale_func()
  56. scale = get_scale_func()
  57.  
  58. // Color switch for on/off switches
  59. if Pi
  60. PiCol
  61. else
  62. PiCol := na
  63. if Euler
  64. EulerCol
  65. else
  66. EulerCol := na
  67. if Prime
  68. PrimeCol
  69. else
  70. PrimeCol := na
  71.  
  72. // Function to create frames defined by a constant to be iterated up the chart
  73. create_frame_func(fFrame, showLines, frameCol) =>
  74. a = 1
  75. lw = a % 10 == 0 ? 4 : 1
  76. while a <= (100.0 / (fFrame / scale))
  77. if barstate.islast and showLines
  78. line.new(bar_index[4999], fFrame * a, bar_index, fFrame * a, color = frameCol, width = lw, extend = extend.both)
  79. a += 1
  80.  
  81. // Generates e and pi frame
  82. closest_pi_percent = create_frame_func(3.14159 * scale, true, PiCol) // Pi
  83. closest_e_percent = create_frame_func(2.71828 * scale, true, EulerCol) // Euler's Constant
  84.  
  85. // Generates prime frame
  86. i = 0
  87. while i < array.size(primes)
  88. a = array.get(primes, i)
  89. v = a * scale
  90. line = line.new (bar_index[1], v, bar_index, v, color = PrimeCol, width = 1, extend = extend.both)
  91. i += 1
  92.  
  93. //---------------------END OF FRAME CREATION CODE-------------------//
  94.  
  95. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  96.  
  97. //---------------------SUPERIORITY CYCLE CODE-------------------//
  98.  
  99. // Initialise high and low arrays
  100. float [] highsArray = array.new_float(0)
  101. float [] lowsArray = array.new_float(0)
  102.  
  103. // Add last 11 highs/lows to arrays
  104. for j = 0 to 10
  105. array.push(highsArray, high[j])
  106. array.push(lowsArray, low[j])
  107.  
  108. // Boolean condition to ensure five highs to the left and five highs to the right are all lower than the central high in the array high[5] & counter logic for lows
  109. bool highPiv = array.max(highsArray) == high[5]
  110. bool lowPiv = array.min(lowsArray) == low[5]
  111.  
  112. // Assigns most recent high pivot and low pivot float values
  113. float lastHighPivPrice = ta.valuewhen(highPiv, high[5], 0)
  114. float lastLowPivPrice = ta.valuewhen(lowPiv, low[5], 0)
  115.  
  116. // Function to determine the distance from the last high or low pivot to the nearest level in a given frame
  117. distanceFromStructureToPiv(taFloatValue, float[] y) =>
  118. thisScale = get_scale_func()
  119. get_dist = array.new_float(0)
  120. float minimisedValue = 0.0
  121. float arrayex_var = array.get(y, 0) * thisScale
  122. for k = 1 to array.size(y) - 2
  123. float arrayex_var2 = array.get(y, k) * thisScale
  124. if (math.abs(taFloatValue - arrayex_var2) < math.abs(taFloatValue - arrayex_var))
  125. arrayex_var := arrayex_var2
  126. array.push(get_dist, math.abs(taFloatValue - arrayex_var))
  127. minimisedValue := array.get(get_dist, 0)
  128. minimisedValue
  129.  
  130. // Creates six float values for data comparison each containing 1 minimised value
  131. float highPiv_primeFrame = distanceFromStructureToPiv(lastHighPivPrice, primes), float lowPiv_primeFrame = distanceFromStructureToPiv(lastLowPivPrice, primes)
  132. float highPiv_eFrame = distanceFromStructureToPiv(lastHighPivPrice, eLevels), float lowPiv_eFrame = distanceFromStructureToPiv(lastLowPivPrice, eLevels)
  133. float highPiv_piFrame = distanceFromStructureToPiv(lastHighPivPrice, piLevels), float lowPiv_piFrame = distanceFromStructureToPiv(lastLowPivPrice, piLevels)
  134.  
  135. // Creates array of each frames performance
  136. superiorityFunction(xHigh, xLow, xArray, yHigh, yLow, yArray, zHigh, zLow, zArray) =>
  137. results = array.new_float(0)
  138. xSuperiority = (xHigh + xLow < yHigh + yLow) and (xHigh + xLow < zHigh + zLow)
  139. var xSuperiorityCount = 0
  140. if xSuperiority
  141. xSuperiorityCount := (xSuperiorityCount + 1)
  142. ySuperiority = (yHigh + yLow < xHigh + xLow) and (yHigh + yLow < zHigh + zLow)
  143. var ySuperiorityCount = 0
  144. if ySuperiority
  145. ySuperiorityCount := (ySuperiorityCount + 1)
  146. zSuperiority = (zHigh + zLow < xHigh + xLow) and (zHigh + zLow < yHigh + yLow)
  147. var zSuperiorityCount = 0
  148. if zSuperiority
  149. zSuperiorityCount := (zSuperiorityCount + 1)
  150. array.push(results, xSuperiorityCount / array.size(xArray))
  151. array.push(results, ySuperiorityCount / array.size(yArray))
  152. array.push(results, zSuperiorityCount / array.size(zArray))
  153. results
  154.  
  155. //superiorityFunction() call to create array of frame performances
  156. float [] sfArray = superiorityFunction(highPiv_primeFrame, lowPiv_primeFrame, primes, highPiv_eFrame, lowPiv_eFrame, eLevels, highPiv_piFrame, lowPiv_piFrame, piLevels)
  157.  
  158. // Finds worst performing frame and retrieves index from array
  159. lowest = array.max(sfArray, 0)
  160. index = array.indexof(sfArray, lowest)
  161.  
  162. // bgcolors correspond to which frame to target trades at next.
  163. // ----> if bgcolor is olive target prime frame reversals
  164. // ----> if bgcolor is green target e frame reversals
  165. // ----> if bgcolor is maroon target pi frame reversals
  166. bgcolor(color = index == 0 ? color.new(color.olive, 80) : na)
  167. bgcolor(color = index == 1 ? color.new(color.green, 80) : na)
  168. bgcolor(color = index == 2 ? color.new(color.maroon, 80) : na)
  169.  
  170. // Table showing which frame to target reversals on and the respective scores of each frame.
  171. var dataTable = table.new(position = position.bottom_right, columns = 2, rows = 5, bgcolor = color.black, border_width = 1)
  172. table.cell(table_id = dataTable, column = 0, row = 1, text = "Next target: Prime Superiority (Olive lines on chart)", bgcolor = index == 0 ? color.olive : color.white, text_color = index == 0 ? color.white : #000000)
  173. table.cell(table_id = dataTable, column = 0, row = 2, text = "Next target: E Superiority (Green lines on chart)", bgcolor = index == 1 ? color.green : color.white, text_color = index == 1 ? color.white : #000000)
  174. table.cell(table_id = dataTable, column = 0, row = 3, text = "Next target: Pi Superiority (Maroon Lines on chart)", bgcolor = index == 2 ? color.maroon : color.white, text_color = index == 2 ? color.white : #000000)
  175. table.cell(table_id = dataTable, column = 0, row = 4, text = "[Prime Score, E Score, Pi Score]: " + str.tostring(sfArray), bgcolor = color.white, text_color = #000000)
  176.  
  177. //---------------------END OF SUPERIORITY CYCLE CODE-------------------//
Advertisement
Add Comment
Please, Sign In to add comment