Advertisement
xmd79

GET SL&TP [GLOBAL E TRADE]

Jan 7th, 2023
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.47 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. // © Global_E_Trade
  3.  
  4. // __ __ __ __ __ __ __ __ __ __ __ _______ __ __ __
  5. // / | / | / | _ / |/ | / \ / | / | / \ / | / | / \ / \ / | / |
  6. // $$ | $$ | ______ $$ | / \ $$ |$$ |____ ______ $$ \ /$$ | __ __ _______ _$$ |_ $$ \ $$ | ______ _$$ |_ $$$$$$$ | ______ $$ \ $$ | ______ _____ ____ ______ ____$$ |
  7. // $$ |__$$ | / \ $$ |/$ \$$ |$$ \ / \ $$$ \ /$$$ |/ | / | / |/ $$ | $$$ \$$ | / \ / $$ | $$ |__$$ | / \ $$$ \$$ | / \ / \/ \ / \ / $$ |
  8. // $$ $$ |/$$$$$$ |$$ /$$$ $$ |$$$$$$$ |/$$$$$$ |$$$$ /$$$$ |$$ | $$ |/$$$$$$$/ $$$$$$/ $$$$ $$ |/$$$$$$ |$$$$$$/ $$ $$< /$$$$$$ |$$$$ $$ | $$$$$$ |$$$$$$ $$$$ |/$$$$$$ |/$$$$$$$ |
  9. // $$$$$$$$ |$$ $$ |$$ $$/$$ $$ |$$ | $$ |$$ | $$ |$$ $$ $$/$$ |$$ | $$ |$$ \ $$ | __ $$ $$ $$ |$$ | $$ | $$ | __ $$$$$$$ |$$ $$ |$$ $$ $$ | / $$ |$$ | $$ | $$ |$$ $$ |$$ | $$ |
  10. // $$ | $$ |$$$$$$$$/ $$$$/ $$$$ |$$ | $$ |$$ \__$$ |$$ |$$$/ $$ |$$ \__$$ | $$$$$$ | $$ |/ |$$ |$$$$ |$$ \__$$ | $$ |/ |$$ |__$$ |$$$$$$$$/ $$ |$$$$ |/$$$$$$$ |$$ | $$ | $$ |$$$$$$$$/ $$ \__$$ |
  11. // $$ | $$ |$$ |$$$/ $$$ |$$ | $$ |$$ $$/ $$ | $/ $$ |$$ $$/ / $$/ $$ $$/ $$ | $$$ |$$ $$/ $$ $$/ $$ $$/ $$ |$$ | $$$ |$$ $$ |$$ | $$ | $$ |$$ |$$ $$ |
  12. // $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ $$$$$$$/ $$$$/ $$/ $$/ $$$$$$/ $$$$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$$$$/
  13. //
  14. //
  15. //
  16. //@version=5
  17.  
  18. indicator("GET SL&TP [GLOBAL E TRADE]", "GET[GLOBAL E TRADE]", overlay=true, max_lines_count = 500, max_labels_count = 500)
  19. import HeWhoMustNotBeNamed/mZigzag/12 as zg
  20. import HeWhoMustNotBeNamed/enhanced_ta/14 as eta
  21. import HeWhoMustNotBeNamed/arrays/1 as pa
  22. //*********************** Debug method *************************//
  23. i_start = 0
  24. i_page = 100
  25. i_maxLogSize = 1000
  26. i_showHistory = false
  27. i_showBarIndex = false
  28. var DebugArray = array.new_string(0)
  29. var DebugBarArray = array.new_string(0)
  30. add_to_debug_array(arr, val, maxItems) =>
  31. array.unshift(arr, str.tostring(val))
  32. if array.size(arr) > maxItems
  33. array.pop(arr)
  34.  
  35. debug(debugMsg) =>
  36. if barstate.islast or i_showHistory
  37. barTimeString = str.tostring(year, '0000') + '/' + str.tostring(month, '00') + '/' + str.tostring(dayofmonth, '00') + (timeframe.isintraday ? '-' + str.tostring(hour, '00') + ':' + str.tostring(minute, '00') + ':' + str.tostring(second, '00') : '')
  38.  
  39. add_to_debug_array(DebugBarArray, i_showBarIndex ? str.tostring(bar_index) : barTimeString, i_maxLogSize)
  40. add_to_debug_array(DebugArray, debugMsg, i_maxLogSize)
  41. //*********************** Debug method *************************//
  42.  
  43. length = input.int(8, 'Length', group='Zigzag')
  44. oscillatorType = input.string("rsi", title="Oscillator", inline="osc", options=["cci", "cmo", "cog", "mfi", "roc", "rsi"], group='Oscillator')
  45. oscLength = input.int(14, title="", inline="osc", group='Oscillator')
  46. supertrendLength = input.int(5, 'History', inline='st', group='Supertrend')
  47. drawSupertrend = input.bool(false, "Draw Zigzag Supertrend", inline='st2', group='Supertrend')
  48.  
  49. showTable = input.bool(false, 'Detailed Stats', inline='txt', group = 'Stats and Display')
  50. txtSize = input.string(size.tiny, '', [size.tiny, size.small, size.normal, size.large, size.huge], inline='txt', group = 'Stats and Display')
  51. txtColor = input.color(color.white, '', inline='txt', group = 'Stats and Display')
  52.  
  53. showPivotLines = input.bool(true, 'Pivot Lines', inline='pli', group = 'Stats and Display')
  54. showPivotLabel = input.bool(false, 'Pivot Label', inline='pla', group = 'Stats and Display')
  55.  
  56. increment(mtx, row, col, val=1)=>matrix.set(mtx, row, col, matrix.get(mtx, row, col)+val)
  57. gettrendindex(int price, int osc, int trend)=>
  58. trendFactor = trend > 0 ? 0 : 1
  59. priceFactor = math.abs(price) > 1? 1 : 0
  60. oscFactor = math.abs(osc) > 1? 1 : 0
  61. trendFactor*4 + priceFactor*2 + oscFactor
  62.  
  63.  
  64. getSentimentDetails(pDir, oDir, sDir) =>
  65. sentiment = pDir == oDir ? sDir == pDir or sDir * 2 == -pDir ? -sDir : sDir * 4 : sDir == pDir or sDir == -oDir ? 0 : (math.abs(oDir) > math.abs(pDir) ? sDir : -sDir) * (sDir == oDir ? 2 : 3)
  66. sentimentSymbol = sentiment == 4 ? '⬆' : sentiment == -4 ? '⬇' : sentiment == 3 ? '↗' : sentiment == -3 ? '↘' : sentiment == 2 ? '⤴' : sentiment == -2 ? '⤵' : sentiment == 1 ? '⤒' : sentiment == -1 ? '⤓' : '▣'
  67. sentimentColor = sentiment == 4 ? color.green : sentiment == -4 ? color.red : sentiment == 3 ? color.lime : sentiment == -3 ? color.orange : sentiment == 2 ? color.rgb(202, 224, 13, 0) : sentiment == -2 ? color.rgb(250, 128, 114, 0) : color.silver
  68. sentimentLabel = math.abs(sentiment) == 4 ? 'C' : math.abs(sentiment) == 3 ? 'H' : math.abs(sentiment) == 2 ? 'D' : 'I'
  69. [sentimentSymbol, sentimentLabel, sentimentColor]
  70.  
  71.  
  72. getStatus(int trendIndex, int pivotDir)=>
  73. trendFactor = int(trendIndex/4)
  74. remainder = trendIndex % 4
  75. priceFactor = int(remainder/2)+1
  76. oscFactor = (remainder % 2)+1
  77. trendChar = (trendFactor == 0)? 'U' : 'D'
  78. priceChar = pivotDir > 0? (priceFactor == 2? 'HH' : 'LH') : (priceFactor == 2? 'LL' : 'HL')
  79. oscChar = pivotDir > 0? (oscFactor == 2? 'HH' : 'LH') : (oscFactor == 2? 'LL' : 'HL')
  80. trendChar + ' - ' + priceChar + '/'+oscChar
  81.  
  82. draw_zg_line(idx1, idx2, zigzaglines, zigzaglabels, valueMatrix, directionMatrix, ratioMatrix, divergenceMatrix, doubleDivergenceMatrix,
  83. barArray, trendArray, lineColor, lineWidth, lineStyle) =>
  84. if matrix.rows(valueMatrix) > 2
  85. idxLen1 = matrix.rows(valueMatrix)-idx1
  86. idxLen2 = matrix.rows(valueMatrix)-idx2
  87. lastValues = matrix.row(valueMatrix, idxLen1)
  88. llastValues = matrix.row(valueMatrix, idxLen2)
  89.  
  90. lastDirections = matrix.row(directionMatrix, idxLen1)
  91. lastRatios = matrix.row(ratioMatrix, idxLen1)
  92. lastDivergence = matrix.row(divergenceMatrix, idxLen1)
  93. lastDoubleDivergence = matrix.row(doubleDivergenceMatrix, idxLen1)
  94.  
  95. y1 = array.get(lastValues, 0)
  96. y2 = array.get(llastValues, 0)
  97. x1 = array.get(barArray, idxLen1)
  98. x2 = array.get(barArray, idxLen2)
  99. zline = line.new(x1=x1, y1=y1, x2=x2, y2=y2, color=lineColor, width=lineWidth, style=lineStyle)
  100. currentDir = y1 > y2? 1 : -1
  101.  
  102. priceDir = array.get(lastDirections, 0)
  103. oscDir = array.get(lastDirections, 1)
  104. trendDir = array.get(trendArray, idxLen1)
  105. trendIndex = gettrendindex(priceDir, oscDir, trendDir)
  106. trendLabel = getStatus(trendIndex, currentDir)
  107. [sentimentSymbol, sentimentLabel, sentimentColor] = getSentimentDetails(priceDir, oscDir, trendDir)
  108.  
  109. labelStyle = currentDir > 0? label.style_label_down : label.style_label_up
  110. zlabel = showPivotLabel ? label.new(x=x1, y=y1, yloc=yloc.price, color=sentimentColor, style=labelStyle, text=sentimentSymbol + ' ' + trendLabel,
  111. textcolor=color.black, size = size.small, tooltip=sentimentLabel) : na
  112. if array.size(zigzaglines) > 0
  113. lastLine = array.get(zigzaglines, array.size(zigzaglines)-1)
  114. if line.get_x2(lastLine) == x2 and line.get_x1(lastLine) <= x1
  115. pa.pop(zigzaglines)
  116. pa.pop(zigzaglabels)
  117.  
  118. pa.push(zigzaglines, zline, 500)
  119. pa.push(zigzaglabels, zlabel, 500)
  120.  
  121. draw(matrix<float> valueMatrix, matrix<int> directionMatrix, matrix<float> ratioMatrix, matrix<int> divergenceMatrix, matrix<int> doubleDivergenceMatrix, array<int> barArray, array<int> trendArray,
  122. bool newZG, bool doubleZG, color lineColor = color.blue, int lineWidth = 1, string lineStyle = line.style_solid)=>
  123. var zigzaglines = array.new_line(0)
  124. var zigzaglabels = array.new_label(0)
  125. if(newZG)
  126. if doubleZG
  127. draw_zg_line(2, 3, zigzaglines, zigzaglabels, valueMatrix, directionMatrix, ratioMatrix, divergenceMatrix, doubleDivergenceMatrix, barArray, trendArray,
  128. lineColor, lineWidth, lineStyle)
  129.  
  130. if matrix.rows(valueMatrix) >= 2
  131. draw_zg_line(1, 2, zigzaglines, zigzaglabels, valueMatrix, directionMatrix, ratioMatrix, divergenceMatrix, doubleDivergenceMatrix, barArray, trendArray,
  132. lineColor, lineWidth, lineStyle)
  133. [valueMatrix, directionMatrix, ratioMatrix, divergenceMatrix, doubleDivergenceMatrix, barArray, zigzaglines, zigzaglabels]
  134.  
  135.  
  136.  
  137. indicatorHigh = array.new_float()
  138. indicatorLow = array.new_float()
  139. indicatorLabels = array.new_string()
  140.  
  141. [oscHigh, _, _] = eta.oscillator(oscillatorType, oscLength, oscLength, oscLength, high)
  142. [oscLow, _, _] = eta.oscillator(oscillatorType, oscLength, oscLength, oscLength, low)
  143. array.push(indicatorHigh, math.round(oscHigh,2))
  144. array.push(indicatorLow, math.round(oscLow,2))
  145. array.push(indicatorLabels, oscillatorType+str.tostring(oscLength))
  146.  
  147.  
  148. [valueMatrix, directionMatrix, ratioMatrix, divergenceMatrix, doubleDivergenceMatrix, barArray, trendArray, supertrendDir, supertrend, newZG, doubleZG] =
  149. zg.calculate(length, array.from(high, low), indicatorHigh, indicatorLow, supertrendLength = supertrendLength)
  150.  
  151. nextDirection = matrix.rows(directionMatrix) > 0? matrix.row(directionMatrix, matrix.rows(directionMatrix)-1) : array.new_int()
  152. lastDirection = matrix.rows(directionMatrix) > 1? matrix.row(directionMatrix, matrix.rows(directionMatrix)-2) : array.new_int()
  153. llastDirection = matrix.rows(directionMatrix) > 2? matrix.row(directionMatrix, matrix.rows(directionMatrix)-3) : array.new_int()
  154. lllastDirection = matrix.rows(directionMatrix) > 3? matrix.row(directionMatrix, matrix.rows(directionMatrix)-4) : array.new_int()
  155.  
  156. var pivotHighStats = matrix.new<int>(64, 3, 0)
  157. var pivotLowStats = matrix.new<int>(64, 3, 0)
  158.  
  159. var pivotHighRatios = matrix.new<float>(64, 3, 0)
  160. var pivotLowRatios = matrix.new<float>(64, 3, 0)
  161.  
  162. var pivotHighBars = matrix.new<float>(64, 3, 0)
  163. var pivotLowBars = matrix.new<float>(64, 3, 0)
  164.  
  165. currentTotalTrendIndex = 0
  166. nextTotalTrendIndex = 0
  167. currentDir = matrix.rows(directionMatrix) > 0? matrix.get(directionMatrix, matrix.rows(directionMatrix)-1, 0) : 0
  168. if(array.size(lllastDirection) > 0)
  169. priceDirection = array.get(lastDirection, 0)
  170. priceRatio = matrix.get(ratioMatrix, matrix.rows(ratioMatrix)-2, 0)
  171.  
  172. numberOfBars = array.get(barArray, array.size(barArray)-2) - array.get(barArray, array.size(barArray)-3)
  173. currentPriceDirection = array.get(lastDirection, 0)
  174. currentOscDirection = array.get(lastDirection, 1)
  175. currentTrend = array.get(trendArray, array.size(trendArray)-2)
  176.  
  177. nextPriceDirection = array.get(nextDirection, 0)
  178. nextOscDirection = array.get(nextDirection, 1)
  179. nextTrend = array.get(trendArray, array.size(trendArray)-1)
  180.  
  181. lastPriceDirection = array.get(llastDirection, 0)
  182. lastOscDirection = array.get(llastDirection, 1)
  183. lastTrend = array.get(trendArray, array.size(trendArray)-3)
  184.  
  185. llastPriceDirection = array.get(lllastDirection, 0)
  186. llastOscDirection = array.get(lllastDirection, 1)
  187. llastTrend = array.get(trendArray, array.size(trendArray)-4)
  188.  
  189. colLast = math.abs(priceDirection) %2
  190.  
  191. nextTrendIndex = gettrendindex(nextPriceDirection, nextOscDirection, nextTrend)
  192. currentTrendIndex = gettrendindex(currentPriceDirection, currentOscDirection, currentTrend)
  193. lastTrendIndex = gettrendindex(lastPriceDirection, lastOscDirection, lastTrend)
  194. llastTrendIndex = gettrendindex(llastPriceDirection, llastOscDirection, llastTrend)
  195.  
  196. totalIndex = lastTrendIndex*8 + llastTrendIndex
  197. currentTotalTrendIndex := currentTrendIndex*8 + lastTrendIndex
  198. nextTotalTrendIndex := nextTrendIndex*8 + currentTrendIndex
  199.  
  200. matrixToSet = math.sign(priceDirection) > 0? pivotHighStats : pivotLowStats
  201. ratioMatrixToSet = math.sign(priceDirection) > 0? pivotHighRatios : pivotLowRatios
  202. barMatrixToSet = math.sign(priceDirection) > 0? pivotHighBars : pivotLowBars
  203.  
  204. increment(matrixToSet, totalIndex, colLast)
  205. increment(ratioMatrixToSet, totalIndex, colLast, priceRatio)
  206. increment(barMatrixToSet, totalIndex, colLast, numberOfBars)
  207.  
  208. increment(matrixToSet, totalIndex, 2)
  209. increment(ratioMatrixToSet, totalIndex, 2, priceRatio)
  210. increment(barMatrixToSet, totalIndex, 2, numberOfBars)
  211.  
  212.  
  213. var float hhValue = na
  214. var float lhValue = na
  215.  
  216. var float llValue = na
  217. var float hlValue = na
  218.  
  219. var float hhProbability = na
  220. var float llProbability = na
  221.  
  222. var float htRatio = na
  223. var float ltRatio = na
  224. if(array.size(barArray) > 10)
  225. currentBar = array.get(barArray, array.size(barArray)-1)
  226. lastBar = array.get(barArray, array.size(barArray)-2)
  227. currentPrice = matrix.get(valueMatrix, matrix.rows(valueMatrix)-1, 0)
  228. lastPrice = matrix.get(valueMatrix, matrix.rows(valueMatrix)-2, 0)
  229. llastPrice = matrix.get(valueMatrix, matrix.rows(valueMatrix)-3, 0)
  230. startRow = 2
  231. var statsTable = showTable ? table.new(position=position.top_right, columns=10, rows=64+startRow, border_color = color.black, border_width = 2) : na
  232.  
  233. phSortIndices = array.sort_indices(matrix.col(pivotHighStats, 2), order.descending)
  234.  
  235. phColStart = currentDir > 0 ? 0 : 5
  236.  
  237. if(showTable)
  238. table.clear(statsTable, 0, 0, 9, 64+startRow-1)
  239. table.cell(statsTable, phColStart, 0, 'Pivot High Projection', text_color = txtColor, text_size = txtSize, bgcolor = color.maroon)
  240. table.cell(statsTable, phColStart, 1, 'Last Two Pivots', text_color = txtColor, text_size = txtSize, bgcolor = color.maroon)
  241. table.cell(statsTable, phColStart+2, 1, 'HH', text_color = txtColor, text_size = txtSize, bgcolor = color.maroon)
  242. table.cell(statsTable, phColStart+3, 1, 'LH', text_color = txtColor, text_size = txtSize, bgcolor = color.maroon)
  243. table.cell(statsTable, phColStart+4, 1, 'T', text_color = txtColor, text_size = txtSize, bgcolor = color.maroon)
  244. table.merge_cells(statsTable, phColStart, 0, phColStart+4, 0)
  245. table.merge_cells(statsTable, phColStart, 1, phColStart+1, 1)
  246.  
  247. hlr = startRow
  248. for i=0 to 63
  249. si = array.get(phSortIndices, i)
  250. lastTrendIndex = int(si/8)
  251. llastTrendIndex = si%8
  252.  
  253. lastPivotStatus = getStatus(lastTrendIndex, -1)
  254. llastPivotStatus = getStatus(llastTrendIndex, 1)
  255. hhStats = matrix.get(pivotHighStats, si, 0)
  256. lhStats = matrix.get(pivotHighStats, si, 1)
  257. tStats = matrix.get(pivotHighStats, si, 2)
  258.  
  259. hhRatio = math.round(matrix.get(pivotHighRatios, si, 0)/hhStats, 3)
  260. lhRatio = math.round(matrix.get(pivotHighRatios, si, 1)/lhStats, 3)
  261. tRatio = math.round(matrix.get(pivotHighRatios, si, 2)/tStats, 3)
  262.  
  263. hhBars = math.round(matrix.get(pivotHighBars, si, 0)/hhStats)
  264. lhBars = math.round(matrix.get(pivotHighBars, si, 1)/lhStats)
  265. tBars = math.round(matrix.get(pivotHighBars, si, 2)/tStats)
  266. highlight = math.sign(currentDir) < 0 ? nextTotalTrendIndex == si : currentTotalTrendIndex == si
  267.  
  268. hhTooltip = 'Average Ratio - '+str.tostring(hhRatio)+'\n'+'Average Bars - '+str.tostring(hhBars)
  269. lhTooltip = 'Average Ratio - '+str.tostring(lhRatio)+'\n'+'Average Bars - '+str.tostring(lhBars)
  270. tTooltip = 'Average Ratio - '+str.tostring(tRatio)+'\n'+'Average Bars - '+str.tostring(tBars)
  271.  
  272. if(highlight)
  273. var line hhLine = na
  274. var line lhLine = na
  275. var line tLine = na
  276. var label hhLabel = na
  277. var label lhLabel = na
  278. var label tLabel = na
  279.  
  280. line.delete(hhLine)
  281. line.delete(lhLine)
  282. line.delete(tLine)
  283. label.delete(hhLabel)
  284. label.delete(lhLabel)
  285. label.delete(tLabel)
  286.  
  287. x1 = math.sign(currentDir) < 0 ? currentBar : lastBar
  288. hhX2 = x1 + hhBars
  289. lhX2 = x1 + lhBars
  290. tX2 = x1 + tBars
  291.  
  292. y1 = math.sign(currentDir) < 0 ? currentPrice : lastPrice
  293. prev = math.sign(currentDir) < 0 ? lastPrice : llastPrice
  294. hhY2 = math.round_to_mintick(y1 + math.abs(y1-prev)*hhRatio)
  295. lhY2 = math.round_to_mintick(y1 + math.abs(y1-prev)*lhRatio)
  296. tY2 = math.round_to_mintick(y1 + math.abs(y1-prev)*tRatio)
  297. hhLine := line.new(x1, y1, hhX2, hhY2, xloc=xloc.bar_index, color=color.green, style=line.style_arrow_right)
  298. lhLine := line.new(x1, y1, lhX2, lhY2, xloc=xloc.bar_index, color=color.lime, style=line.style_arrow_right)
  299. tLine := line.new(x1, y1, tX2, tY2, xloc=xloc.bar_index, color=color.yellow, style=line.style_arrow_right)
  300.  
  301. hhPercent = str.tostring(hhStats*100/tStats, format.percent)
  302. lhPercent = str.tostring(lhStats*100/tStats, format.percent)
  303. hhText = 'Number of Historical References :'+str.tostring(hhStats)+'/'+str.tostring(tStats)+
  304. '\nProbability of Higher High :'+hhPercent+
  305. '\nAverage Higher High Ratio :'+str.tostring(hhRatio) +
  306. '\nAverage Higher High Bars :'+str.tostring(hhBars)
  307. lhText = 'Number of Historical References :'+str.tostring(lhStats)+'/'+str.tostring(tStats)+
  308. '\nProbability of Lower High :'+lhPercent+
  309. '\nAverage Lower High Ratio :'+str.tostring(lhRatio) +
  310. '\nAverage Lower High Bars :'+str.tostring(lhBars)
  311. tText = 'Number of Historical References :'+str.tostring(tStats)+
  312. '\nAverage Fib Ratio :'+str.tostring(tRatio)+
  313. '\nAverage Bars :'+str.tostring(tBars)
  314. hhLabel := label.new(hhX2, hhY2, str.tostring(hhY2)+ ' - ' +hhPercent, style=label.style_label_lower_left, color=color.new(color.green, 70), textcolor = color.white, size=size.small, tooltip=hhText)
  315. lhLabel := label.new(lhX2, lhY2, str.tostring(lhY2)+ ' - ' +lhPercent, style=label.style_label_upper_left, color=color.new(color.lime, 70), textcolor = color.white, size=size.small, tooltip=lhText)
  316. tLabel := label.new(tX2, tY2, str.tostring(tY2)+ '@'+str.tostring(tRatio), style=label.style_label_left, color=color.new(color.yellow, 70), textcolor = color.white, size=size.small, tooltip=tText)
  317. hhValue := hhY2
  318. lhValue := lhY2
  319. hhProbability := hhStats*100/tStats
  320. htRatio := tRatio
  321.  
  322. if(hhStats != 0 and lhStats != 0) and showTable
  323. table.cell(statsTable, phColStart, hlr, llastPivotStatus, text_color = txtColor, text_size = txtSize, bgcolor = color.new(color.lime, 60))
  324. table.cell(statsTable, phColStart+1, hlr, lastPivotStatus, text_color = txtColor, text_size = txtSize, bgcolor = color.new(color.orange, 60))
  325. table.cell(statsTable, phColStart+2, hlr, str.tostring(hhStats)+' - '+str.tostring(hhRatio), text_color = txtColor, text_size = txtSize, bgcolor = color.new(color.green, highlight ? 50 : 90), tooltip = hhTooltip)
  326. table.cell(statsTable, phColStart+3, hlr, str.tostring(lhStats)+' - '+str.tostring(lhRatio), text_color = txtColor, text_size = txtSize, bgcolor = color.new(color.red, highlight? 50 : 90), tooltip = lhTooltip)
  327. table.cell(statsTable, phColStart+4, hlr, str.tostring(tStats)+' - '+str.tostring(tRatio), text_color = txtColor, text_size = txtSize, bgcolor = color.from_gradient(hhStats/tStats, 0, 1, color.red, color.green), tooltip = tTooltip)
  328. hlr+=1
  329.  
  330.  
  331. plColStart = currentDir < 0 ? 0 : 5
  332. if(showTable)
  333. table.cell(statsTable, plColStart, 0, 'Pivot Low Projection', text_color = txtColor, text_size = txtSize, bgcolor = color.maroon)
  334. table.cell(statsTable, plColStart, 1, 'Last Two Pivots', text_color = txtColor, text_size = txtSize, bgcolor = color.maroon)
  335. table.cell(statsTable, plColStart+2, 1, 'LL', text_color = txtColor, text_size = txtSize, bgcolor = color.maroon)
  336. table.cell(statsTable, plColStart+3, 1, 'HL', text_color = txtColor, text_size = txtSize, bgcolor = color.maroon)
  337. table.cell(statsTable, plColStart+4, 1, 'T', text_color = txtColor, text_size = txtSize, bgcolor = color.maroon)
  338. table.merge_cells(statsTable, plColStart, 0, plColStart+4, 0)
  339. table.merge_cells(statsTable, plColStart, 1, plColStart+1, 1)
  340. plSortIndices = array.sort_indices(matrix.col(pivotLowStats, 2), order.descending)
  341.  
  342. llr = startRow
  343. for i=0 to 63
  344. si = array.get(plSortIndices, i)
  345. lastTrendIndex = int(si/8)
  346. llastTrendIndex = si%8
  347.  
  348. lastPivotStatus = getStatus(lastTrendIndex, 1)
  349. llastPivotStatus = getStatus(llastTrendIndex, -1)
  350. llStats = matrix.get(pivotLowStats, si, 0)
  351. hlStats = matrix.get(pivotLowStats, si, 1)
  352. tStats = matrix.get(pivotLowStats, si, 2)
  353.  
  354. llRatio = math.round(matrix.get(pivotLowRatios, si, 0)/llStats, 3)
  355. hlRatio = math.round(matrix.get(pivotLowRatios, si, 1)/hlStats, 3)
  356. tRatio = math.round(matrix.get(pivotLowRatios, si, 2)/tStats, 3)
  357.  
  358. llBars = math.round(matrix.get(pivotLowBars, si, 0)/llStats)
  359. hlBars = math.round(matrix.get(pivotLowBars, si, 1)/hlStats)
  360. tBars = math.round(matrix.get(pivotLowBars, si, 2)/tStats)
  361.  
  362. highlight = math.sign(currentDir) > 0 ? nextTotalTrendIndex== si : currentTotalTrendIndex == si
  363.  
  364. llTooltip = 'Average Ratio - '+str.tostring(llRatio)+'\n'+'Average Bars - '+str.tostring(llBars)
  365. hlTooltip = 'Average Ratio - '+str.tostring(hlRatio)+'\n'+'Average Bars - '+str.tostring(hlBars)
  366. tTooltip = 'Average Ratio - '+str.tostring(tRatio)+'\n'+'Average Bars - '+str.tostring(tBars)
  367.  
  368. if(highlight)
  369. var line llLine = na
  370. var line hlLine = na
  371. var line tLine = na
  372.  
  373. var label llLabel = na
  374. var label hlLabel = na
  375. var label tLabel = na
  376.  
  377. line.delete(llLine)
  378. line.delete(hlLine)
  379. line.delete(tLine)
  380.  
  381. label.delete(llLabel)
  382. label.delete(hlLabel)
  383. label.delete(tLabel)
  384.  
  385. x1 = math.sign(currentDir) > 0 ? currentBar : lastBar
  386. llX2 = x1 + llBars
  387. hlX2 = x1 + hlBars
  388. tX2 = x1 + tBars
  389.  
  390. y1 = math.sign(currentDir) > 0 ? currentPrice : lastPrice
  391. prev = math.sign(currentDir) > 0 ? lastPrice : llastPrice
  392. llY2 = math.round_to_mintick(y1 - math.abs(y1-prev)*llRatio)
  393. hlY2 = math.round_to_mintick(y1 - math.abs(y1-prev)*hlRatio)
  394. tY2 = math.round_to_mintick(y1 - math.abs(y1-prev)*tRatio)
  395. llLine := line.new(x1, y1, llX2, llY2, xloc=xloc.bar_index, color=color.red, style=line.style_arrow_right)
  396. hlLine := line.new(x1, y1, hlX2, hlY2, xloc=xloc.bar_index, color=color.orange, style=line.style_arrow_right)
  397. tLine := line.new(x1, y1, tX2, tY2, xloc=xloc.bar_index, color=color.yellow, style=line.style_arrow_right)
  398.  
  399. llPercent = str.tostring(llStats*100/tStats, format.percent)
  400. hlPercent = str.tostring(hlStats*100/tStats, format.percent)
  401. llText = 'Number of Historical References :'+str.tostring(llStats)+'/'+str.tostring(tStats)+
  402. '\nProbability of Lower Low :'+llPercent+
  403. '\nAverage Lower Low Ratio :'+str.tostring(llRatio) +
  404. '\nAverage Lower Low Bars :'+str.tostring(llBars)
  405. hlText = 'Number of Historical References :'+str.tostring(hlStats)+'/'+str.tostring(tStats)+
  406. '\nProbability of Higher Low :'+hlPercent+
  407. '\nAverage Higher Low Ratio :'+str.tostring(hlRatio) +
  408. '\nAverage Higher Low Bars :'+str.tostring(hlBars)
  409. tText = 'Number of Historical References :'+str.tostring(tStats)+
  410. '\nAverage Fib Ratio :'+str.tostring(tRatio)+
  411. '\nAverage Bars :'+str.tostring(tBars)
  412. llLabel := label.new(llX2, llY2, str.tostring(llY2)+ ' - ' +llPercent, style=label.style_label_upper_left, color=color.new(color.red, 70), textcolor = color.white, size=size.small, tooltip=llText)
  413. hlLabel := label.new(hlX2, hlY2, str.tostring(hlY2)+ ' - ' +hlPercent, style=label.style_label_lower_left, color=color.new(color.orange, 70), textcolor = color.white, size=size.small, tooltip=hlText)
  414. tLabel := label.new(tX2, tY2, str.tostring(tY2)+ '@'+str.tostring(tRatio), style=label.style_label_left, color=color.new(color.yellow, 70), textcolor = color.white, size=size.small, tooltip=tText)
  415. llValue := llY2
  416. hlValue := hlY2
  417. llProbability := llStats*100/tStats
  418. ltRatio := tRatio
  419.  
  420. if(llStats != 0 and hlStats != 0) and showTable
  421. table.cell(statsTable, plColStart, llr, llastPivotStatus, text_color = txtColor, text_size = txtSize, bgcolor = color.new(color.orange, 60))
  422. table.cell(statsTable, plColStart+1, llr, lastPivotStatus, text_color = txtColor, text_size = txtSize, bgcolor = color.new(color.lime, 60))
  423. table.cell(statsTable, plColStart+2, llr, str.tostring(llStats)+' - '+str.tostring(llRatio), text_color = txtColor, text_size = txtSize, bgcolor = color.new(color.red, highlight? 50 : 90), tooltip=llTooltip)
  424. table.cell(statsTable, plColStart+3, llr, str.tostring(hlStats)+' - '+str.tostring(hlRatio), text_color = txtColor, text_size = txtSize, bgcolor = color.new(color.green, highlight? 50 : 90), tooltip = hlTooltip)
  425. table.cell(statsTable, plColStart+4, llr, str.tostring(tStats)+' - '+str.tostring(tRatio), text_color = txtColor, text_size = txtSize, bgcolor = color.from_gradient(llStats/tStats, 0, 1, color.green, color.red), tooltip = tTooltip)
  426. llr+=1
  427.  
  428.  
  429. if showPivotLines
  430. draw(valueMatrix, directionMatrix, ratioMatrix, divergenceMatrix, doubleDivergenceMatrix, barArray, trendArray, newZG, doubleZG)
  431.  
  432. plot(drawSupertrend? supertrend:na, color=supertrendDir>0? color.green:color.red, style=plot.style_linebr)
  433.  
  434.  
  435. hhp = plot(hhValue, 'Higher High Range', color.new(color.green, 100), 1)
  436. lhp = plot(lhValue, 'Lower High Range', color.new(color.lime, 100), 1)
  437. llp = plot(llValue, 'Lower Low Range', color.new(color.red, 100), 1)
  438. hlp = plot(hlValue, 'Higher Low Range', color.new(color.orange, 100), 1)
  439.  
  440. fill(hhp, lhp, color=color.new(hhProbability > 50 ? color.green : hhProbability < 50? color.red : color.silver, 90))
  441. fill(llp, hlp, color=color.new(llProbability > 50 ? color.red : llProbability < 50? color.green : color.silver, 90))
  442.  
  443. //************************************************************ Print debug message on table ********************************************************/
  444. var debugTable = table.new(position=position.bottom_left, columns=2, rows=i_page + 1, border_width=1)
  445. if array.size(DebugArray) > 0
  446. table.cell(table_id=debugTable, column=0, row=0, text=i_showBarIndex ? 'Bar Index' : 'Bar Time', bgcolor=color.teal, text_color=txtColor, text_size=size.normal)
  447. table.cell(table_id=debugTable, column=1, row=0, text='Debug Message', bgcolor=color.teal, text_color=txtColor, text_size=size.normal)
  448. for i = 0 to math.min(array.size(DebugArray) - 1 - i_start, i_page - 1) by 1
  449. table.cell(table_id=debugTable, column=0, row=i + 1, text=array.get(DebugBarArray, i + i_start), bgcolor=color.black, text_color=txtColor, text_size=size.normal)
  450. table.cell(table_id=debugTable, column=1, row=i + 1, text=array.get(DebugArray, i + i_start), bgcolor=color.black, text_color=txtColor, text_size=size.normal)
  451. //************************************************************ Finish Printing ********************************************************/
  452.  
  453.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement