커뮤니티

감사합니다 지표 변환 부탁드립니다

프로필 이미지
갈랑교
2025-05-21 09:13:41
302
글번호 191027
답변완료
// INPUT SETTINGS period = input.int(10, "Period", minval=2) color lineUpColor = input(title="Color ↑", defval=#6ba583, inline="lines", group="&#9830;&#65038; lines") color lineDnColor = input(title="↓", defval=#d75442, inline="lines", group="&#9830;&#65038; lines") lw = input.int(2, "Width", [1, 2, 3, 4], inline="lines", group="&#9830;&#65038; lines") bool rangeLines = input.bool(true, "Range Lines", inline = 'rangelines', group = "&#9830;&#65038; lines") color rnglineColor = input(title="", defval=#000000, inline="rangelines", group="&#9830;&#65038; lines") //bool rnglineextend = input.bool(false, "Extend", inline = 'rangelines', group = "lines") delta = input.string('Percent', '&#120607; Format', options = [ 'Percent', 'Absolute'], group = '&#9830;&#65038; labels', inline = 'st') txtsz = input.string("Small", title="Text Size", options=["Tiny", "Small", "Normal", "Large", "Huge"], group = "&#9830;&#65038; labels", inline = 'st') bool cyclelab = input.bool(false, "Display Cycle", "Add Highs/Lows Cycle to the labels", group = "&#9830;&#65038; labels") showtable = input.bool(true, 'Show Stats table', group = '&#9830;&#65038; statistics table') locationtable = input.string('Top Right', 'Location', ['Top Right','Top Left', 'Bottom Right', 'Bottom Left'], group = '&#9830;&#65038; statistics table', inline = 'tbpr') sizetable = input.string('Normal', 'Size', ['Large', 'Normal', 'Small', 'Tiny'], group = '&#9830;&#65038; statistics table', inline = 'tbpr') avgln = input.int(10, "Averaging", minval=2, step=1, tooltip="Number of past occurrences to average", group = '&#9830;&#65038; statistics table') ts = txtsz == "Tiny" ? size.tiny :txtsz == "Small" ? size.small :txtsz == "Normal" ? size.normal:txtsz == "Large" ? size.large : size.huge // Variables { // LAST SWING TYPE var string lastSwingType = "" // SWING HIGHS var float[] swingHighValues = array.new_float(0) var int[] swingHighBarIndexes = array.new_int(0) var label[] swingHighLabels = array.new_label(0) // SWING LOWS var float[] swingLowValues = array.new_float(0) var int[] swingLowBarIndexes = array.new_int(0) var label[] swingLowLabels = array.new_label(0) // LINES var line[] highToHighLines = array.new_line(0) var line[] lowToLowLines = array.new_line(0) var line[] bullishLines = array.new_line(0) var line[] bearishLines = array.new_line(0) // STS var float[] highToHighPriceDiffs = array.new_float(0) var int[] highToHighTimeDiffs = array.new_int(0) var float[] lowToLowPriceDiffs = array.new_float(0) var int[] lowToLowTimeDiffs = array.new_int(0) var float[] bullishPriceDiffs = array.new_float(0) var float[] bullishPrcDiffs = array.new_float(0) var int[] bullishTimeDiffs = array.new_int(0) var float[] bearishPriceDiffs = array.new_float(0) var float[] bearishPrcDiffs = array.new_float(0) var int[] bearishTimeDiffs = array.new_int(0) //} pH = high == ta.highest(high, period) ? high : na pL = low == ta.lowest(low, period) ? low : na // Adds a new swing high point, calculates differences (same-type and cross-type), creates a label, and draws connecting lines{ f_addHighSwingPoint(highValue, barIndex) => // Calculate opposite-type differences (with most recent low) oppPriceDiff = (array.size(swingLowValues) > 0) ? highValue - array.get(swingLowValues, 0) : 0.0 oppPctDiff = (array.size(swingLowValues) > 0) ? oppPriceDiff / array.get(swingLowValues, 0) * 100 : 0.0 oppTimeDiff = (array.size(swingLowBarIndexes) > 0) ? barIndex - array.get(swingLowBarIndexes, 0) : 0 // Calculate same-type differences (with previous high) samePriceDiff = (array.size(swingHighValues) > 0) ? highValue - array.get(swingHighValues, 0) : 0.0 sameTimeDiff = (array.size(swingHighBarIndexes) > 0) ? barIndex - array.get(swingHighBarIndexes, 0) : 0 patternH = "" if array.size(swingHighValues) > 0 patternH := (highValue > array.get(swingHighValues, 0)) ? "&#668;&#668;" : "&#671;&#668;" labelText = "" if array.size(swingLowValues) > 0 textx = delta=="Percent"?(str.tostring(oppPctDiff, format.percent)):str.tostring(oppPriceDiff, "#.##") labelText := str.tostring(patternH) + "₩n+" + textx + "₩n&#9201;" + str.tostring(oppTimeDiff) //"L↑H " + str.tostring(oppPriceDiff, "#.##") if array.size(swingHighValues) > 0 and cyclelab labelText := labelText + "₩n&#668;&#618;&#610;&#668; &#7428;&#655;&#7428;&#671;&#7431;₩n" + "&#9201;" + str.tostring(sameTimeDiff) //+ str.tostring(samePriceDiff, "#.##") // Create label at swing high point newLabel = label.new(barIndex, highValue, labelText, textcolor = #6ba583, style=label.style_label_down, color=color.new(#000000, 100), size=ts, text_formatting = text.format_bold) // Store swing high data array.unshift(swingHighValues, highValue) array.unshift(swingHighBarIndexes, barIndex) array.unshift(swingHighLabels, newLabel) // Draw lin connection betwn cons swing highs // if previous high exists if array.size(swingHighValues) > 1 prevBar = array.get(swingHighBarIndexes, 1) prevValue = array.get(swingHighValues, 1) newLine = rangeLines?line.new(prevBar, prevValue, barIndex, highValue, color=rnglineColor, width=1, style = line.style_solid):na array.unshift(highToHighLines, newLine) // Calculate and store differences for this high-to-high line priceDiff = highValue - prevValue timeDiff = barIndex - prevBar array.unshift(highToHighPriceDiffs, priceDiff) array.unshift(highToHighTimeDiffs, timeDiff) // Draw bullish line if the last swing was // (from a low to this high) if array.size(swingLowValues) > 0 and lastSwingType != "high" prevLowBar = array.get(swingLowBarIndexes, 0) prevLowValue = array.get(swingLowValues, 0) newBullishLine = line.new(prevLowBar, prevLowValue, barIndex, highValue, color=lineUpColor, width=lw, style = line.style_solid) array.unshift(bullishLines, newBullishLine) bullishPdiff = highValue - prevLowValue bullishTdiff = barIndex - prevLowBar array.unshift(bullishPriceDiffs, bullishPdiff) array.unshift(bullishPrcDiffs, oppPctDiff) array.unshift(bullishTimeDiffs, bullishTdiff) //} // 업데이트 the current swing high point // if a new candidate is more extreme, recalculates differences, // 업데이트 the label text, and 업데이트 connecting lines{ f_업데이트HighSwingPoint(highValue, barIndex) => if highValue > array.get(swingHighValues, 0) array.set(swingHighValues, 0, highValue) array.set(swingHighBarIndexes, 0, barIndex) oppPriceDiff = (array.size(swingLowValues) > 0) ? highValue - array.get(swingLowValues, 0) : 0.0 oppPctDiff = (array.size(swingLowValues) > 0) ? oppPriceDiff / array.get(swingLowValues, 0) * 100 : 0.0 oppTimeDiff = (array.size(swingLowBarIndexes) > 0) ? barIndex - array.get(swingLowBarIndexes, 0) : 0 samePriceDiff = (array.size(swingHighValues) > 1) ? highValue - array.get(swingHighValues, 1) : 0.0 sameTimeDiff = (array.size(swingHighBarIndexes) > 1) ? barIndex - array.get(swingHighBarIndexes, 1) : 0 labelText = "" patternH = "" if array.size(swingHighValues) > 1 patternH := (highValue > array.get(swingHighValues, 1)) ? "&#668;&#668;" : "&#671;&#668;" if array.size(swingLowValues) > 0 textx = delta=="Percent"?(str.tostring(oppPctDiff, format.percent)):str.tostring(oppPriceDiff, "#.##") labelText := str.tostring(patternH) + "₩n+"+ textx + "₩n&#9201;" + str.tostring(oppTimeDiff) //+ str.tostring(oppPriceDiff, "#.##") if array.size(swingHighValues) > 1 and cyclelab labelText := labelText + "₩n&#668;&#618;&#610;&#668; &#7428;&#655;&#7428;&#671;&#7431;₩n" + "&#9201;" + str.tostring(sameTimeDiff) //str.tostring(samePriceDiff, "#.##") + // 업데이트 label for current swing high lbl = array.get(swingHighLabels, 0) label.set_xy(lbl, barIndex, highValue) label.set_text(lbl, labelText) // 업데이트 high-to-high connection if it exists if array.size(swingHighValues) > 1 and array.size(highToHighLines) > 0 prevBar = array.get(swingHighBarIndexes, 1) prevValue = array.get(swingHighValues, 1) line.set_xy1(array.get(highToHighLines, 0), array.get(swingHighBarIndexes, 1), array.get(swingHighValues, 1)) line.set_xy2(array.get(highToHighLines, 0), barIndex, highValue) // Upd stored diffs for high-to-high connection array.set(highToHighPriceDiffs, 0, highValue - prevValue) array.set(highToHighTimeDiffs, 0, barIndex - prevBar) // Upd bullish connection if array.size(swingLowValues) > 0 and array.size(bullishLines) > 0 prevLowBar = array.get(swingLowBarIndexes, 0) prevLowValue = array.get(swingLowValues, 0) line.set_xy1(array.get(bullishLines, 0), prevLowBar, prevLowValue) line.set_xy2(array.get(bullishLines, 0), barIndex, highValue) array.set(bullishPriceDiffs, 0, highValue - prevLowValue) array.set(bullishPrcDiffs, 0, (highValue - prevLowValue)/prevLowValue * 100) array.set(bullishTimeDiffs, 0, barIndex - prevLowBar) 0. //} // Adds a new swing low point, calculates differences (same-type and cross-type),creates a label, and draws connecting lines{ f_addLowSwingPoint(lowValue, barIndex) => // Calculate opposite-type differences (with most recent high) oppPriceDiff = (array.size(swingHighValues) > 0) ? lowValue - array.get(swingHighValues, 0) : 0.0 oppPctDiff = (array.size(swingHighValues) > 0) ? oppPriceDiff / array.get(swingHighValues, 0) * 100 : 0.0 oppTimeDiff = (array.size(swingHighBarIndexes) > 0) ? barIndex - array.get(swingHighBarIndexes, 0) : 0 // Calculate same-type differences (with previous low) samePriceDiff = (array.size(swingLowValues) > 0) ? lowValue - array.get(swingLowValues, 0) : 0.0 sameTimeDiff = (array.size(swingLowBarIndexes) > 0) ? barIndex - array.get(swingLowBarIndexes, 0) : 0 labelText = "" patternL = "" if array.size(swingLowValues) > 0 patternL := (lowValue < array.get(swingLowValues, 0)) ? "&#671;&#671;" : "&#668;&#671;" if array.size(swingHighValues) > 0 textx = delta=="Percent"?(str.tostring(oppPctDiff, format.percent)):str.tostring(oppPriceDiff, "#.##") labelText := str.tostring(patternL) + "₩n" + textx + "₩n&#9201;" + str.tostring(oppTimeDiff) //"H↓L "+ str.tostring(oppPriceDiff, "#.##") if array.size(swingLowValues) > 0 and cyclelab labelText := labelText + "₩n&#671;&#7439;&#7457; &#7428;&#655;&#7428;&#671;&#7431;₩n" + "&#9201;" + str.tostring(sameTimeDiff) //+ str.tostring(samePriceDiff, "#.##") // Create label at swing low point newLabel = label.new(barIndex, lowValue, labelText, textcolor = #d75442, style=label.style_label_up, color=color.new(#000000, 100), size=ts, text_formatting = text.format_bold) // Store swing low data array.unshift(swingLowValues, lowValue) array.unshift(swingLowBarIndexes, barIndex) array.unshift(swingLowLabels, newLabel) // connection line betwn consecutive swing lows if array.size(swingLowValues) > 1 prevBar = array.get(swingLowBarIndexes, 1) prevValue = array.get(swingLowValues, 1) newLine = rangeLines?line.new(prevBar, prevValue, barIndex, lowValue, color=rnglineColor, width=1, style = line.style_solid):na array.unshift(lowToLowLines, newLine) // Calculate and store differences for this low-to-low line priceDiff = lowValue - prevValue timeDiff = barIndex - prevBar array.unshift(lowToLowPriceDiffs, priceDiff) array.unshift(lowToLowTimeDiffs, timeDiff) // Draw bearish line if the last swing was of the opposite type (from a high to this low) if array.size(swingHighValues) > 0 and lastSwingType != "low" prevHighBar = array.get(swingHighBarIndexes, 0) prevHighValue = array.get(swingHighValues, 0) newBearishLine = line.new(prevHighBar, prevHighValue, barIndex, lowValue, color=lineDnColor, width=lw, style = line.style_solid) array.unshift(bearishLines, newBearishLine) bearishPdiff = lowValue - prevHighValue bearishTdiff = barIndex - prevHighBar array.unshift(bearishPriceDiffs, bearishPdiff) array.unshift(bearishPrcDiffs, oppPctDiff) array.unshift(bearishTimeDiffs, bearishTdiff) //} // 업데이트 the current swing low point if a new is more extreme, recalculates differences, 업데이트 the lab text, and connecting lines{ f_업데이트LowSwingPoint(lowValue, barIndex) => if lowValue < array.get(swingLowValues, 0) array.set(swingLowValues, 0, lowValue) array.set(swingLowBarIndexes, 0, barIndex) oppPriceDiff = (array.size(swingHighValues) > 0) ? lowValue - array.get(swingHighValues, 0) : 0.0 oppPctDiff = (array.size(swingHighValues) > 0) ? oppPriceDiff / array.get(swingHighValues, 0) * 100 : 0.0 oppTimeDiff = (array.size(swingHighBarIndexes) > 0) ? barIndex - array.get(swingHighBarIndexes, 0) : 0 samePriceDiff = (array.size(swingLowValues) > 1) ? lowValue - array.get(swingLowValues, 1) : 0.0 sameTimeDiff = (array.size(swingLowBarIndexes) > 1) ? barIndex - array.get(swingLowBarIndexes, 1) : 0 labelText = "" patternL = "" if array.size(swingLowValues) > 1 patternL := (lowValue < array.get(swingLowValues, 1)) ? "&#671;&#671;" : "&#668;&#671;" if array.size(swingHighValues) > 0 textx = delta=="Percent"?(str.tostring(oppPctDiff, format.percent)):str.tostring(oppPriceDiff, "#.##") labelText := str.tostring(patternL)+ "₩n"+ textx + "₩n&#9201;" + str.tostring(oppTimeDiff) //"L↑H "+ str.tostring(oppPriceDiff, "#.##") if array.size(swingLowValues) > 1 and cyclelab labelText := labelText + "₩n&#671;&#7439;&#7457; &#7428;&#655;&#7428;&#671;&#7431;₩n" + "&#9201;" + str.tostring(sameTimeDiff) //+ str.tostring(samePriceDiff, "#.##") // 업데이트 label for current swing low lbl = array.get(swingLowLabels, 0) label.set_xy(lbl, barIndex, lowValue) label.set_text(lbl, labelText) // 업데이트 low-to-low connection if it exists if array.size(swingLowValues) > 1 and array.size(lowToLowLines) > 0 prevBar = array.get(swingLowBarIndexes, 1) prevValue = array.get(swingLowValues, 1) line.set_xy1(array.get(lowToLowLines, 0), prevBar, prevValue) line.set_xy2(array.get(lowToLowLines, 0), barIndex, lowValue) array.set(lowToLowPriceDiffs, 0, lowValue - prevValue) array.set(lowToLowTimeDiffs, 0, barIndex - prevBar) // 업데이트 bearish connection if exists if array.size(swingHighValues) > 0 and array.size(bearishLines) > 0 prevHighBar = array.get(swingHighBarIndexes, 0) prevHighValue = array.get(swingHighValues, 0) line.set_xy1(array.get(bearishLines, 0), prevHighBar, prevHighValue) line.set_xy2(array.get(bearishLines, 0), barIndex, lowValue) array.set(bearishPriceDiffs, 0, lowValue - prevHighValue) array.set(bearishPrcDiffs, 0, (lowValue - prevHighValue)/prevHighValue * 100) array.set(bearishTimeDiffs, 0, barIndex - prevHighBar) 0. //} if array.size(highToHighLines) > 0 and array.size(lowToLowLines) > 0 linefill.new(array.get(highToHighLines, 0), array.get(lowToLowLines, 0), color.rgb(0, 0, 0, 95)) // Process pivs { var int direction = 0 direction := (not na(pH) and na(pL)) ? 1 : (not na(pL) and na(pH)) ? -1 : direction bool directionChanged = direction != nz(direction[1]) bool bullish = direction == 1 bool bearish = direction == -1 bool bull = direction[1]==-1 and direction==1 bool bear = direction[1]==1 and direction==-1 if direction==1 if lastSwingType != "high" f_addHighSwingPoint(pH, bar_index) lastSwingType := "high" else f_업데이트HighSwingPoint(pH, bar_index) if direction==-1 if lastSwingType != "low" f_addLowSwingPoint(pL, bar_index) lastSwingType := "low" else f_업데이트LowSwingPoint(pL, bar_index) //} // Function for geometric averaging { f_geometric_avg(_source, _condition, _length) => var float geom_avg = na var float[] valuesArray = array.new_float() if _condition if _source > 0 array.push(valuesArray, _source) while array.size(valuesArray) > _length array.shift(valuesArray) n = array.size(valuesArray) if n > 0 logSum = 0.0 for val in valuesArray logSum += math.log(val) geom_avg := math.exp(logSum / n) else geom_avg := na geom_avg var float sourcebull = na var float sourcebear = na var int sourcebullt = na var int sourcebeart = na if array.size(bullishPriceDiffs)>0 and array.size(bullishPrcDiffs)>0 sourcebull := delta=="Percent"?array.get(bullishPrcDiffs, 0) : array.get(bullishPriceDiffs, 0) sourcebullt:=array.get(bullishTimeDiffs, 0) conditionbull = lastSwingType=="low" and lastSwingType[1]== "high" rma_valuebull = f_geometric_avg(sourcebull, conditionbull, avgln) rma_valuebullt = f_geometric_avg(sourcebullt, conditionbull, avgln) if array.size(bearishPriceDiffs)>0 and array.size(bearishPrcDiffs)>0 sourcebear := delta=="Percent"?array.get(bearishPrcDiffs, 0) : array.get(bearishPriceDiffs, 0) sourcebeart:=array.get(bearishTimeDiffs, 0) conditionbear = lastSwingType=="high" and lastSwingType[1] == "low" rma_valuebear = f_geometric_avg(math.abs(sourcebear), conditionbear, avgln) rma_timebear = f_geometric_avg(sourcebeart, conditionbear, avgln) //} //Table{ var table_loc = locationtable == 'Top Right' ? position.top_right : locationtable == 'Bottom Right' ? position.bottom_right : locationtable == 'Top Center' ? position.top_center : locationtable == 'Top Left' ? position.top_left : position.bottom_left var table_size = sizetable == 'Large' ? size.large : sizetable == 'Normal' ? size.normal : sizetable == 'Small' ? size.small : size.tiny var table = showtable ? table.new(table_loc, 16, 16, #2a2e39, #1e1e1e, 2, #1f232f, 2) : na table_cell(column, row, txt, signal = false) => table.cell(table, column, row, txt, 0, 0, signal ? #ffffff : #ffffff, text_size = table_size) table_cell_bg(column, row, col) => table.cell_set_bgcolor(table, column, row, col) if barstate.islast and showtable table_cell(0, 0, "STATISTICS TABLE") table_cell(0, 1, "&#610;&#7431;&#7439;&#7437;&#7431;&#7451;&#640;&#618;&#7428;₩n&#7424;&#7456;&#7431;&#640;&#7424;&#610;&#618;&#628;&#610;") table_cell(1, 1, "&#120723; &#7448;&#640;&#618;&#7428;&#7431;") table_cell(2, 1, "&#120723; &#7451;&#618;&#7437;&#7431;") table_cell(0, 2, '&#7452;&#7448;&#7451;&#640;&#7431;&#628;&#7429;') table_cell(0, 3, '&#7429;&#7439;&#7457;&#628;&#7451;&#640;&#7431;&#628;&#7429;') table_cell(1, 2, "+"+str.tostring(rma_valuebull, delta=="Percent"?format.percent:format.mintick)) table_cell(1, 3, "-"+str.tostring(rma_valuebear, delta=="Percent"?format.percent:format.mintick)) table_cell(2, 2, str.tostring(rma_valuebullt, format.mintick)) table_cell(2, 3, str.tostring(rma_timebear, format.mintick)) table.cell_set_text_font_family(table, 0,0, font.family_monospace) table.cell_set_text_formatting(table, 1, 1, text.format_bold) table.cell_set_text_formatting(table, 2, 1, text.format_bold) table.cell_set_text_formatting(table, 0, 2, text.format_bold) table.cell_set_text_formatting(table, 0, 3, text.format_bold) table.cell_set_text_color(table, 0, 1, color.gray) table.cell_set_text_size(table, 0, 1, size.small) table.merge_cells(table, 0,0,2,0) //}
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-05-21 14:28:02

안녕하세요 예스스탁입니다. 올려주신 내용은 변환해 보는데 시간이 많이 소모됩니다. 업무상 일정시간 이상 요구되는 내용은 답변이 어렵습니다. 도움을 드리지 못해 죄송합니다. 즐거운 하루되세요 > 갈랑교 님이 쓴 글입니다. > 제목 : 감사합니다 지표 변환 부탁드립니다 > // INPUT SETTINGS period = input.int(10, "Period", minval=2) color lineUpColor = input(title="Color ↑", defval=#6ba583, inline="lines", group="&#9830;&#65038; lines") color lineDnColor = input(title="↓", defval=#d75442, inline="lines", group="&#9830;&#65038; lines") lw = input.int(2, "Width", [1, 2, 3, 4], inline="lines", group="&#9830;&#65038; lines") bool rangeLines = input.bool(true, "Range Lines", inline = 'rangelines', group = "&#9830;&#65038; lines") color rnglineColor = input(title="", defval=#000000, inline="rangelines", group="&#9830;&#65038; lines") //bool rnglineextend = input.bool(false, "Extend", inline = 'rangelines', group = "lines") delta = input.string('Percent', '&#120607; Format', options = [ 'Percent', 'Absolute'], group = '&#9830;&#65038; labels', inline = 'st') txtsz = input.string("Small", title="Text Size", options=["Tiny", "Small", "Normal", "Large", "Huge"], group = "&#9830;&#65038; labels", inline = 'st') bool cyclelab = input.bool(false, "Display Cycle", "Add Highs/Lows Cycle to the labels", group = "&#9830;&#65038; labels") showtable = input.bool(true, 'Show Stats table', group = '&#9830;&#65038; statistics table') locationtable = input.string('Top Right', 'Location', ['Top Right','Top Left', 'Bottom Right', 'Bottom Left'], group = '&#9830;&#65038; statistics table', inline = 'tbpr') sizetable = input.string('Normal', 'Size', ['Large', 'Normal', 'Small', 'Tiny'], group = '&#9830;&#65038; statistics table', inline = 'tbpr') avgln = input.int(10, "Averaging", minval=2, step=1, tooltip="Number of past occurrences to average", group = '&#9830;&#65038; statistics table') ts = txtsz == "Tiny" ? size.tiny :txtsz == "Small" ? size.small :txtsz == "Normal" ? size.normal:txtsz == "Large" ? size.large : size.huge // Variables { // LAST SWING TYPE var string lastSwingType = "" // SWING HIGHS var float[] swingHighValues = array.new_float(0) var int[] swingHighBarIndexes = array.new_int(0) var label[] swingHighLabels = array.new_label(0) // SWING LOWS var float[] swingLowValues = array.new_float(0) var int[] swingLowBarIndexes = array.new_int(0) var label[] swingLowLabels = array.new_label(0) // LINES var line[] highToHighLines = array.new_line(0) var line[] lowToLowLines = array.new_line(0) var line[] bullishLines = array.new_line(0) var line[] bearishLines = array.new_line(0) // STS var float[] highToHighPriceDiffs = array.new_float(0) var int[] highToHighTimeDiffs = array.new_int(0) var float[] lowToLowPriceDiffs = array.new_float(0) var int[] lowToLowTimeDiffs = array.new_int(0) var float[] bullishPriceDiffs = array.new_float(0) var float[] bullishPrcDiffs = array.new_float(0) var int[] bullishTimeDiffs = array.new_int(0) var float[] bearishPriceDiffs = array.new_float(0) var float[] bearishPrcDiffs = array.new_float(0) var int[] bearishTimeDiffs = array.new_int(0) //} pH = high == ta.highest(high, period) ? high : na pL = low == ta.lowest(low, period) ? low : na // Adds a new swing high point, calculates differences (same-type and cross-type), creates a label, and draws connecting lines{ f_addHighSwingPoint(highValue, barIndex) => // Calculate opposite-type differences (with most recent low) oppPriceDiff = (array.size(swingLowValues) > 0) ? highValue - array.get(swingLowValues, 0) : 0.0 oppPctDiff = (array.size(swingLowValues) > 0) ? oppPriceDiff / array.get(swingLowValues, 0) * 100 : 0.0 oppTimeDiff = (array.size(swingLowBarIndexes) > 0) ? barIndex - array.get(swingLowBarIndexes, 0) : 0 // Calculate same-type differences (with previous high) samePriceDiff = (array.size(swingHighValues) > 0) ? highValue - array.get(swingHighValues, 0) : 0.0 sameTimeDiff = (array.size(swingHighBarIndexes) > 0) ? barIndex - array.get(swingHighBarIndexes, 0) : 0 patternH = "" if array.size(swingHighValues) > 0 patternH := (highValue > array.get(swingHighValues, 0)) ? "&#668;&#668;" : "&#671;&#668;" labelText = "" if array.size(swingLowValues) > 0 textx = delta=="Percent"?(str.tostring(oppPctDiff, format.percent)):str.tostring(oppPriceDiff, "#.##") labelText := str.tostring(patternH) + "₩n+" + textx + "₩n&#9201;" + str.tostring(oppTimeDiff) //"L↑H " + str.tostring(oppPriceDiff, "#.##") if array.size(swingHighValues) > 0 and cyclelab labelText := labelText + "₩n&#668;&#618;&#610;&#668; &#7428;&#655;&#7428;&#671;&#7431;₩n" + "&#9201;" + str.tostring(sameTimeDiff) //+ str.tostring(samePriceDiff, "#.##") // Create label at swing high point newLabel = label.new(barIndex, highValue, labelText, textcolor = #6ba583, style=label.style_label_down, color=color.new(#000000, 100), size=ts, text_formatting = text.format_bold) // Store swing high data array.unshift(swingHighValues, highValue) array.unshift(swingHighBarIndexes, barIndex) array.unshift(swingHighLabels, newLabel) // Draw lin connection betwn cons swing highs // if previous high exists if array.size(swingHighValues) > 1 prevBar = array.get(swingHighBarIndexes, 1) prevValue = array.get(swingHighValues, 1) newLine = rangeLines?line.new(prevBar, prevValue, barIndex, highValue, color=rnglineColor, width=1, style = line.style_solid):na array.unshift(highToHighLines, newLine) // Calculate and store differences for this high-to-high line priceDiff = highValue - prevValue timeDiff = barIndex - prevBar array.unshift(highToHighPriceDiffs, priceDiff) array.unshift(highToHighTimeDiffs, timeDiff) // Draw bullish line if the last swing was // (from a low to this high) if array.size(swingLowValues) > 0 and lastSwingType != "high" prevLowBar = array.get(swingLowBarIndexes, 0) prevLowValue = array.get(swingLowValues, 0) newBullishLine = line.new(prevLowBar, prevLowValue, barIndex, highValue, color=lineUpColor, width=lw, style = line.style_solid) array.unshift(bullishLines, newBullishLine) bullishPdiff = highValue - prevLowValue bullishTdiff = barIndex - prevLowBar array.unshift(bullishPriceDiffs, bullishPdiff) array.unshift(bullishPrcDiffs, oppPctDiff) array.unshift(bullishTimeDiffs, bullishTdiff) //} // 업데이트 the current swing high point // if a new candidate is more extreme, recalculates differences, // 업데이트 the label text, and 업데이트 connecting lines{ f_업데이트HighSwingPoint(highValue, barIndex) => if highValue > array.get(swingHighValues, 0) array.set(swingHighValues, 0, highValue) array.set(swingHighBarIndexes, 0, barIndex) oppPriceDiff = (array.size(swingLowValues) > 0) ? highValue - array.get(swingLowValues, 0) : 0.0 oppPctDiff = (array.size(swingLowValues) > 0) ? oppPriceDiff / array.get(swingLowValues, 0) * 100 : 0.0 oppTimeDiff = (array.size(swingLowBarIndexes) > 0) ? barIndex - array.get(swingLowBarIndexes, 0) : 0 samePriceDiff = (array.size(swingHighValues) > 1) ? highValue - array.get(swingHighValues, 1) : 0.0 sameTimeDiff = (array.size(swingHighBarIndexes) > 1) ? barIndex - array.get(swingHighBarIndexes, 1) : 0 labelText = "" patternH = "" if array.size(swingHighValues) > 1 patternH := (highValue > array.get(swingHighValues, 1)) ? "&#668;&#668;" : "&#671;&#668;" if array.size(swingLowValues) > 0 textx = delta=="Percent"?(str.tostring(oppPctDiff, format.percent)):str.tostring(oppPriceDiff, "#.##") labelText := str.tostring(patternH) + "₩n+"+ textx + "₩n&#9201;" + str.tostring(oppTimeDiff) //+ str.tostring(oppPriceDiff, "#.##") if array.size(swingHighValues) > 1 and cyclelab labelText := labelText + "₩n&#668;&#618;&#610;&#668; &#7428;&#655;&#7428;&#671;&#7431;₩n" + "&#9201;" + str.tostring(sameTimeDiff) //str.tostring(samePriceDiff, "#.##") + // 업데이트 label for current swing high lbl = array.get(swingHighLabels, 0) label.set_xy(lbl, barIndex, highValue) label.set_text(lbl, labelText) // 업데이트 high-to-high connection if it exists if array.size(swingHighValues) > 1 and array.size(highToHighLines) > 0 prevBar = array.get(swingHighBarIndexes, 1) prevValue = array.get(swingHighValues, 1) line.set_xy1(array.get(highToHighLines, 0), array.get(swingHighBarIndexes, 1), array.get(swingHighValues, 1)) line.set_xy2(array.get(highToHighLines, 0), barIndex, highValue) // Upd stored diffs for high-to-high connection array.set(highToHighPriceDiffs, 0, highValue - prevValue) array.set(highToHighTimeDiffs, 0, barIndex - prevBar) // Upd bullish connection if array.size(swingLowValues) > 0 and array.size(bullishLines) > 0 prevLowBar = array.get(swingLowBarIndexes, 0) prevLowValue = array.get(swingLowValues, 0) line.set_xy1(array.get(bullishLines, 0), prevLowBar, prevLowValue) line.set_xy2(array.get(bullishLines, 0), barIndex, highValue) array.set(bullishPriceDiffs, 0, highValue - prevLowValue) array.set(bullishPrcDiffs, 0, (highValue - prevLowValue)/prevLowValue * 100) array.set(bullishTimeDiffs, 0, barIndex - prevLowBar) 0. //} // Adds a new swing low point, calculates differences (same-type and cross-type),creates a label, and draws connecting lines{ f_addLowSwingPoint(lowValue, barIndex) => // Calculate opposite-type differences (with most recent high) oppPriceDiff = (array.size(swingHighValues) > 0) ? lowValue - array.get(swingHighValues, 0) : 0.0 oppPctDiff = (array.size(swingHighValues) > 0) ? oppPriceDiff / array.get(swingHighValues, 0) * 100 : 0.0 oppTimeDiff = (array.size(swingHighBarIndexes) > 0) ? barIndex - array.get(swingHighBarIndexes, 0) : 0 // Calculate same-type differences (with previous low) samePriceDiff = (array.size(swingLowValues) > 0) ? lowValue - array.get(swingLowValues, 0) : 0.0 sameTimeDiff = (array.size(swingLowBarIndexes) > 0) ? barIndex - array.get(swingLowBarIndexes, 0) : 0 labelText = "" patternL = "" if array.size(swingLowValues) > 0 patternL := (lowValue < array.get(swingLowValues, 0)) ? "&#671;&#671;" : "&#668;&#671;" if array.size(swingHighValues) > 0 textx = delta=="Percent"?(str.tostring(oppPctDiff, format.percent)):str.tostring(oppPriceDiff, "#.##") labelText := str.tostring(patternL) + "₩n" + textx + "₩n&#9201;" + str.tostring(oppTimeDiff) //"H↓L "+ str.tostring(oppPriceDiff, "#.##") if array.size(swingLowValues) > 0 and cyclelab labelText := labelText + "₩n&#671;&#7439;&#7457; &#7428;&#655;&#7428;&#671;&#7431;₩n" + "&#9201;" + str.tostring(sameTimeDiff) //+ str.tostring(samePriceDiff, "#.##") // Create label at swing low point newLabel = label.new(barIndex, lowValue, labelText, textcolor = #d75442, style=label.style_label_up, color=color.new(#000000, 100), size=ts, text_formatting = text.format_bold) // Store swing low data array.unshift(swingLowValues, lowValue) array.unshift(swingLowBarIndexes, barIndex) array.unshift(swingLowLabels, newLabel) // connection line betwn consecutive swing lows if array.size(swingLowValues) > 1 prevBar = array.get(swingLowBarIndexes, 1) prevValue = array.get(swingLowValues, 1) newLine = rangeLines?line.new(prevBar, prevValue, barIndex, lowValue, color=rnglineColor, width=1, style = line.style_solid):na array.unshift(lowToLowLines, newLine) // Calculate and store differences for this low-to-low line priceDiff = lowValue - prevValue timeDiff = barIndex - prevBar array.unshift(lowToLowPriceDiffs, priceDiff) array.unshift(lowToLowTimeDiffs, timeDiff) // Draw bearish line if the last swing was of the opposite type (from a high to this low) if array.size(swingHighValues) > 0 and lastSwingType != "low" prevHighBar = array.get(swingHighBarIndexes, 0) prevHighValue = array.get(swingHighValues, 0) newBearishLine = line.new(prevHighBar, prevHighValue, barIndex, lowValue, color=lineDnColor, width=lw, style = line.style_solid) array.unshift(bearishLines, newBearishLine) bearishPdiff = lowValue - prevHighValue bearishTdiff = barIndex - prevHighBar array.unshift(bearishPriceDiffs, bearishPdiff) array.unshift(bearishPrcDiffs, oppPctDiff) array.unshift(bearishTimeDiffs, bearishTdiff) //} // 업데이트 the current swing low point if a new is more extreme, recalculates differences, 업데이트 the lab text, and connecting lines{ f_업데이트LowSwingPoint(lowValue, barIndex) => if lowValue < array.get(swingLowValues, 0) array.set(swingLowValues, 0, lowValue) array.set(swingLowBarIndexes, 0, barIndex) oppPriceDiff = (array.size(swingHighValues) > 0) ? lowValue - array.get(swingHighValues, 0) : 0.0 oppPctDiff = (array.size(swingHighValues) > 0) ? oppPriceDiff / array.get(swingHighValues, 0) * 100 : 0.0 oppTimeDiff = (array.size(swingHighBarIndexes) > 0) ? barIndex - array.get(swingHighBarIndexes, 0) : 0 samePriceDiff = (array.size(swingLowValues) > 1) ? lowValue - array.get(swingLowValues, 1) : 0.0 sameTimeDiff = (array.size(swingLowBarIndexes) > 1) ? barIndex - array.get(swingLowBarIndexes, 1) : 0 labelText = "" patternL = "" if array.size(swingLowValues) > 1 patternL := (lowValue < array.get(swingLowValues, 1)) ? "&#671;&#671;" : "&#668;&#671;" if array.size(swingHighValues) > 0 textx = delta=="Percent"?(str.tostring(oppPctDiff, format.percent)):str.tostring(oppPriceDiff, "#.##") labelText := str.tostring(patternL)+ "₩n"+ textx + "₩n&#9201;" + str.tostring(oppTimeDiff) //"L↑H "+ str.tostring(oppPriceDiff, "#.##") if array.size(swingLowValues) > 1 and cyclelab labelText := labelText + "₩n&#671;&#7439;&#7457; &#7428;&#655;&#7428;&#671;&#7431;₩n" + "&#9201;" + str.tostring(sameTimeDiff) //+ str.tostring(samePriceDiff, "#.##") // 업데이트 label for current swing low lbl = array.get(swingLowLabels, 0) label.set_xy(lbl, barIndex, lowValue) label.set_text(lbl, labelText) // 업데이트 low-to-low connection if it exists if array.size(swingLowValues) > 1 and array.size(lowToLowLines) > 0 prevBar = array.get(swingLowBarIndexes, 1) prevValue = array.get(swingLowValues, 1) line.set_xy1(array.get(lowToLowLines, 0), prevBar, prevValue) line.set_xy2(array.get(lowToLowLines, 0), barIndex, lowValue) array.set(lowToLowPriceDiffs, 0, lowValue - prevValue) array.set(lowToLowTimeDiffs, 0, barIndex - prevBar) // 업데이트 bearish connection if exists if array.size(swingHighValues) > 0 and array.size(bearishLines) > 0 prevHighBar = array.get(swingHighBarIndexes, 0) prevHighValue = array.get(swingHighValues, 0) line.set_xy1(array.get(bearishLines, 0), prevHighBar, prevHighValue) line.set_xy2(array.get(bearishLines, 0), barIndex, lowValue) array.set(bearishPriceDiffs, 0, lowValue - prevHighValue) array.set(bearishPrcDiffs, 0, (lowValue - prevHighValue)/prevHighValue * 100) array.set(bearishTimeDiffs, 0, barIndex - prevHighBar) 0. //} if array.size(highToHighLines) > 0 and array.size(lowToLowLines) > 0 linefill.new(array.get(highToHighLines, 0), array.get(lowToLowLines, 0), color.rgb(0, 0, 0, 95)) // Process pivs { var int direction = 0 direction := (not na(pH) and na(pL)) ? 1 : (not na(pL) and na(pH)) ? -1 : direction bool directionChanged = direction != nz(direction[1]) bool bullish = direction == 1 bool bearish = direction == -1 bool bull = direction[1]==-1 and direction==1 bool bear = direction[1]==1 and direction==-1 if direction==1 if lastSwingType != "high" f_addHighSwingPoint(pH, bar_index) lastSwingType := "high" else f_업데이트HighSwingPoint(pH, bar_index) if direction==-1 if lastSwingType != "low" f_addLowSwingPoint(pL, bar_index) lastSwingType := "low" else f_업데이트LowSwingPoint(pL, bar_index) //} // Function for geometric averaging { f_geometric_avg(_source, _condition, _length) => var float geom_avg = na var float[] valuesArray = array.new_float() if _condition if _source > 0 array.push(valuesArray, _source) while array.size(valuesArray) > _length array.shift(valuesArray) n = array.size(valuesArray) if n > 0 logSum = 0.0 for val in valuesArray logSum += math.log(val) geom_avg := math.exp(logSum / n) else geom_avg := na geom_avg var float sourcebull = na var float sourcebear = na var int sourcebullt = na var int sourcebeart = na if array.size(bullishPriceDiffs)>0 and array.size(bullishPrcDiffs)>0 sourcebull := delta=="Percent"?array.get(bullishPrcDiffs, 0) : array.get(bullishPriceDiffs, 0) sourcebullt:=array.get(bullishTimeDiffs, 0) conditionbull = lastSwingType=="low" and lastSwingType[1]== "high" rma_valuebull = f_geometric_avg(sourcebull, conditionbull, avgln) rma_valuebullt = f_geometric_avg(sourcebullt, conditionbull, avgln) if array.size(bearishPriceDiffs)>0 and array.size(bearishPrcDiffs)>0 sourcebear := delta=="Percent"?array.get(bearishPrcDiffs, 0) : array.get(bearishPriceDiffs, 0) sourcebeart:=array.get(bearishTimeDiffs, 0) conditionbear = lastSwingType=="high" and lastSwingType[1] == "low" rma_valuebear = f_geometric_avg(math.abs(sourcebear), conditionbear, avgln) rma_timebear = f_geometric_avg(sourcebeart, conditionbear, avgln) //} //Table{ var table_loc = locationtable == 'Top Right' ? position.top_right : locationtable == 'Bottom Right' ? position.bottom_right : locationtable == 'Top Center' ? position.top_center : locationtable == 'Top Left' ? position.top_left : position.bottom_left var table_size = sizetable == 'Large' ? size.large : sizetable == 'Normal' ? size.normal : sizetable == 'Small' ? size.small : size.tiny var table = showtable ? table.new(table_loc, 16, 16, #2a2e39, #1e1e1e, 2, #1f232f, 2) : na table_cell(column, row, txt, signal = false) => table.cell(table, column, row, txt, 0, 0, signal ? #ffffff : #ffffff, text_size = table_size) table_cell_bg(column, row, col) => table.cell_set_bgcolor(table, column, row, col) if barstate.islast and showtable table_cell(0, 0, "STATISTICS TABLE") table_cell(0, 1, "&#610;&#7431;&#7439;&#7437;&#7431;&#7451;&#640;&#618;&#7428;₩n&#7424;&#7456;&#7431;&#640;&#7424;&#610;&#618;&#628;&#610;") table_cell(1, 1, "&#120723; &#7448;&#640;&#618;&#7428;&#7431;") table_cell(2, 1, "&#120723; &#7451;&#618;&#7437;&#7431;") table_cell(0, 2, '&#7452;&#7448;&#7451;&#640;&#7431;&#628;&#7429;') table_cell(0, 3, '&#7429;&#7439;&#7457;&#628;&#7451;&#640;&#7431;&#628;&#7429;') table_cell(1, 2, "+"+str.tostring(rma_valuebull, delta=="Percent"?format.percent:format.mintick)) table_cell(1, 3, "-"+str.tostring(rma_valuebear, delta=="Percent"?format.percent:format.mintick)) table_cell(2, 2, str.tostring(rma_valuebullt, format.mintick)) table_cell(2, 3, str.tostring(rma_timebear, format.mintick)) table.cell_set_text_font_family(table, 0,0, font.family_monospace) table.cell_set_text_formatting(table, 1, 1, text.format_bold) table.cell_set_text_formatting(table, 2, 1, text.format_bold) table.cell_set_text_formatting(table, 0, 2, text.format_bold) table.cell_set_text_formatting(table, 0, 3, text.format_bold) table.cell_set_text_color(table, 0, 1, color.gray) table.cell_set_text_size(table, 0, 1, size.small) table.merge_cells(table, 0,0,2,0) //}