커뮤니티

변환 부탁드립니다.

프로필 이미지
다올
2025-07-02 17:38:18
229
글번호 192240
답변완료
적용가능하도록 부탁드립니다. -------------아래부터 복사하세요------------- //@version=6 indicator('TVM CCI', overlay = false, precision = 2) // ───── Input Parameters ───── length_low = input.int(72, "Slow CCI Length") length_high = input.int(36, "Fast CCI Length") refit_interval = input.int(50, "Volatility Refit Interval") vol_period = input.int(20, "Current Volatility Period") vol_smooth_len = input.int(5, "Volatility Smoothing Length") bull_col = input.color(color.green, title="Bullish Color") bear_col = input.color(color.red, title="Bearish Color") // ───── CCI-based Oscillator with Clipping ───── cci_oscillator(src, length) => raw = ta.cci(src, length) clipped = math.max(math.min(raw, 100), -100) normalized = clipped / 200 + 0.5 normalized // ───── Volatility Calculations ───── returns = close / close[1] - 1 vol_current_raw = ta.stdev(returns, vol_period) vol_current_smoothed = ta.sma(vol_current_raw, vol_smooth_len) // ───── Volatility History Management ───── var array<float> vola = array.new<float>() if not na(vol_current_raw) array.push(vola, vol_current_raw) if array.size(vola) > 150 array.shift(vola) // ───── Volatility Clustering ───── cluster(arr) => if array.size(arr) < 10 [na, na] else median = array.median(arr) sum_low = 0.0 count_low = 0 sum_high = 0.0 count_high = 0 for i = 0 to array.size(arr) - 1 val = array.get(arr, i) if val < median sum_low += val count_low += 1 else sum_high += val count_high += 1 low_avg = count_low > 0 ? sum_low / count_low : na high_avg = count_high > 0 ? sum_high / count_high : na [low_avg, high_avg] // ───── Volatility Regime Variables (with type) ───── var float cluster_1 = na var float cluster_2 = na var float last_refit_bar = na var int vol_regime = na if bar_index - last_refit_bar >= refit_interval and array.size(vola) >= 150 [c1, c2] = cluster(vola) if not na(c1) and not na(c2) cluster_1 := na(cluster_1) ? c1 : cluster_1 + 0.1 * (c1 - cluster_1) cluster_2 := na(cluster_2) ? c2 : cluster_2 + 0.1 * (c2 - cluster_2) last_refit_bar := bar_index if cluster_1 > cluster_2 temp = cluster_1 cluster_1 := cluster_2 cluster_2 := temp if not na(vol_current_smoothed) and not na(cluster_1) and not na(cluster_2) mid = (cluster_1 + cluster_2) / 2 vol_regime := vol_current_smoothed < mid ? 0 : 1 // ───── Oscillator S e l e c t i o n ───── osc_low = cci_oscillator(close, length_low) osc_high = cci_oscillator(close, length_high) relevant_osc = vol_regime == 1 ? osc_high : osc_low // ───── Trend Regime Detection ───── var int trend_regime = na trend_regime := relevant_osc > 0.75 ? 1 : relevant_osc < 0.25 ? -1 : 0 // ───── Plots ───── hline(0.5, "Mid", color=color.gray, linestyle=hline.style_dashed) zero = plot(-0.2, display=display.none) top = plot(1.2, display=display.none) plot_osc_low = plot(osc_low, title="Slow CCI", color=osc_low >= 0.5 ? bull_col : bear_col, linewidth=1) plot_osc_high = plot(osc_high, title="Fast CCI", color=osc_high >= 0.5 ? bull_col : bear_col, linewidth=1) fill(plot_osc_low, plot_osc_high, color=osc_low >= 0.5 ? color.new(bull_col, 85) : color.new(bear_col, 85)) bullish_shift = trend_regime == 1 and trend_regime[1] != 1 bearish_shift = trend_regime == -1 and trend_regime[1] != -1 plotshape(bullish_shift ? 1.2 : na, title="Bullish Shift", location=location.absolute, color=color.new(bull_col, 0), style=shape.triangleup, size=size.tiny, offset=-1) plotshape(bearish_shift ? -0.2 : na, title="Bearish Shift", location=location.absolute, color=color.new(bear_col, 0), style=shape.triangledown, size=size.tiny, offset=-1) bg = trend_regime == 1 ? color.new(bull_col, 90) : trend_regime == -1 ? color.new(bear_col, 90) : na fill(top, zero, color=bg) // ───── Trend Table ───── var table regimeTable = table.new(position.top_right, 1, 1) if barstate.islast txt = trend_regime == 1 ? "semi-line" : trend_regime == -1 ? "semi-line" : "Neutral" bgc = trend_regime == 1 ? color.new(bull_col, 20) : trend_regime == -1 ? color.new(bear_col, 20) : color.new(color.gray, 20) table.cell(regimeTable, 0, 0, txt, bgcolor=bgc, text_color=color.white, text_size=size.small)
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-07-03 10:30:55

안녕하세요 예스스탁입니다. input : length_low(72); input : length_high(36); input : refit_interval(50); input : vol_period(20); input : vol_smooth_len(5); input : bull_col(green); input : bear_col(red); // ───── CCI-based Oscillator with Clipping ───── var : raw1(0),clipped1(0),osc_low(0); var : raw2(0),clipped2(0),osc_high(0); raw1 = cci(length_low); clipped1 = max(min(raw1, 100), -100); osc_low = clipped1 / 200 + 0.5; raw2 = cci(length_high); clipped2 = max(min(raw2, 100), -100); osc_high = clipped2 / 200 + 0.5; // ───── Volatility Calculations ───── var : returns(0),vol_current_raw(0),vol_current_smoothed(0); returns = close / close[1] - 1; vol_current_raw = std(returns, vol_period); vol_current_smoothed = ma(vol_current_raw, vol_smooth_len); // ───── Volatility History Management ───── var : i(0),ii(0); Array : vola[150](Nan); if IsNan(vol_current_raw) == False Then { ii = 0; For i = 149 DownTo 1 { vola[i] = vola[i-1]; if IsNan(vola[i]) == true Then ii = i; } vola[0] = vol_current_raw; } var : c1(Nan),c2(Nan),val(0),temp(0); var : median(0),sum_low(0),count_low(0),sum_high(0),count_high(0); if ii < 10 Then { c1 = Nan; c2 = Nan; } Else { median = MedianArray(vola,ii); sum_low = 0.0; count_low = 0; sum_high = 0.0; count_high = 0; for i = 0 to ii - 1 { val = vola[i]; if val < median Then { sum_low = sum_low + val; count_low = count_low + 1; } else { sum_high = sum_high + val; count_high = count_high + 1; } } c1 = iff(count_low > 0 , sum_low / count_low , Nan); c2 = iff(count_high > 0 , sum_high / count_high , Nan); } // ───── Volatility Regime Variables (with type) ───── var : cluster_1(Nan),cluster_2(Nan),last_refit_bar(Nan),vol_regime(Nan); if index - last_refit_bar >= refit_interval and ii >= 149 Then { if IsNan(c1) == False and IsNan(c2) == False Then { cluster_1 = iff(IsNan(cluster_1) == true , c1 , cluster_1 + 0.1 * (c1 - cluster_1)); cluster_2 = iff(IsNan(cluster_2) == true , c2 , cluster_2 + 0.1 * (c2 - cluster_2)); last_refit_bar = index; } if cluster_1 > cluster_2 Then { temp = cluster_1; cluster_1 = cluster_2; cluster_2 = temp; } } var : mid(0),relevant_osc(0),trend_regime(Nan); if IsNan(vol_current_smoothed) == False and IsNan(cluster_1) == False and IsNan(cluster_2) == False Then { mid = (cluster_1 + cluster_2) / 2; vol_regime = iff(vol_current_smoothed < mid , 0 , 1); } // ───── Oscillator S e l e c t i o n ───── relevant_osc = iff(vol_regime == 1 , osc_high , osc_low); // ───── Trend Regime Detection ───── trend_regime = iff(relevant_osc > 0.75 , 1 , iff(relevant_osc < 0.25 , -1 , 0)); // ───── Plots ───── PlotBaseLine1(0.5, "Mid", gray); PlotBaseLine2(-0.2,"-0.2", Gray); PlotBaseLine3(1.2,"1.2",Gray); plot1(osc_low, "Slow CCI", iff(osc_low >= 0.5 , bull_col , bear_col)); plot2(osc_high, "Fast CCI", iff(osc_high >= 0.5 , bull_col , bear_col)); var : tx(0),box(0); if trend_regime == 1 Then { if trend_regime[1] != 1 Then { tx = Text_New_Self(sDate,sTime,1.2,"▲"); Text_SetStyle(tx,2,0); Text_SetColor(tx,bull_col); box = Box_New_Self(sDate,sTime,1.2,NextBarSdate,NextBarStime,-0.2); Box_SetColor(box,bull_col); Box_SetFill(box,true); } Else Box_SetEnd(box,NextBarSdate,NextBarStime,-0.2); } if trend_regime == -1 Then { if trend_regime[1] != -1 Then { tx = Text_New_Self(sDate,sTime,-0.2,"▼"); Text_SetStyle(tx,2,1); Text_SetColor(tx,bear_col); box = Box_New_Self(sDate,sTime,1.2,NextBarSdate,NextBarStime,-0.2); Box_SetColor(box,bear_col); Box_SetFill(box,true); } Else Box_SetEnd(box,NextBarSdate,NextBarStime,-0.2); } 즐거운 하루되세요 > 다올 님이 쓴 글입니다. > 제목 : 변환 부탁드립니다. > 적용가능하도록 부탁드립니다. -------------아래부터 복사하세요------------- //@version=6 indicator('TVM CCI', overlay = false, precision = 2) // ───── Input Parameters ───── length_low = input.int(72, "Slow CCI Length") length_high = input.int(36, "Fast CCI Length") refit_interval = input.int(50, "Volatility Refit Interval") vol_period = input.int(20, "Current Volatility Period") vol_smooth_len = input.int(5, "Volatility Smoothing Length") bull_col = input.color(color.green, title="Bullish Color") bear_col = input.color(color.red, title="Bearish Color") // ───── CCI-based Oscillator with Clipping ───── cci_oscillator(src, length) => raw = ta.cci(src, length) clipped = math.max(math.min(raw, 100), -100) normalized = clipped / 200 + 0.5 normalized // ───── Volatility Calculations ───── returns = close / close[1] - 1 vol_current_raw = ta.stdev(returns, vol_period) vol_current_smoothed = ta.sma(vol_current_raw, vol_smooth_len) // ───── Volatility History Management ───── var array<float> vola = array.new<float>() if not na(vol_current_raw) array.push(vola, vol_current_raw) if array.size(vola) > 150 array.shift(vola) // ───── Volatility Clustering ───── cluster(arr) => if array.size(arr) < 10 [na, na] else median = array.median(arr) sum_low = 0.0 count_low = 0 sum_high = 0.0 count_high = 0 for i = 0 to array.size(arr) - 1 val = array.get(arr, i) if val < median sum_low += val count_low += 1 else sum_high += val count_high += 1 low_avg = count_low > 0 ? sum_low / count_low : na high_avg = count_high > 0 ? sum_high / count_high : na [low_avg, high_avg] // ───── Volatility Regime Variables (with type) ───── var float cluster_1 = na var float cluster_2 = na var float last_refit_bar = na var int vol_regime = na if bar_index - last_refit_bar >= refit_interval and array.size(vola) >= 150 [c1, c2] = cluster(vola) if not na(c1) and not na(c2) cluster_1 := na(cluster_1) ? c1 : cluster_1 + 0.1 * (c1 - cluster_1) cluster_2 := na(cluster_2) ? c2 : cluster_2 + 0.1 * (c2 - cluster_2) last_refit_bar := bar_index if cluster_1 > cluster_2 temp = cluster_1 cluster_1 := cluster_2 cluster_2 := temp if not na(vol_current_smoothed) and not na(cluster_1) and not na(cluster_2) mid = (cluster_1 + cluster_2) / 2 vol_regime := vol_current_smoothed < mid ? 0 : 1 // ───── Oscillator S e l e c t i o n ───── osc_low = cci_oscillator(close, length_low) osc_high = cci_oscillator(close, length_high) relevant_osc = vol_regime == 1 ? osc_high : osc_low // ───── Trend Regime Detection ───── var int trend_regime = na trend_regime := relevant_osc > 0.75 ? 1 : relevant_osc < 0.25 ? -1 : 0 // ───── Plots ───── hline(0.5, "Mid", color=color.gray, linestyle=hline.style_dashed) zero = plot(-0.2, display=display.none) top = plot(1.2, display=display.none) plot_osc_low = plot(osc_low, title="Slow CCI", color=osc_low >= 0.5 ? bull_col : bear_col, linewidth=1) plot_osc_high = plot(osc_high, title="Fast CCI", color=osc_high >= 0.5 ? bull_col : bear_col, linewidth=1) fill(plot_osc_low, plot_osc_high, color=osc_low >= 0.5 ? color.new(bull_col, 85) : color.new(bear_col, 85)) bullish_shift = trend_regime == 1 and trend_regime[1] != 1 bearish_shift = trend_regime == -1 and trend_regime[1] != -1 plotshape(bullish_shift ? 1.2 : na, title="Bullish Shift", location=location.absolute, color=color.new(bull_col, 0), style=shape.triangleup, size=size.tiny, offset=-1) plotshape(bearish_shift ? -0.2 : na, title="Bearish Shift", location=location.absolute, color=color.new(bear_col, 0), style=shape.triangledown, size=size.tiny, offset=-1) bg = trend_regime == 1 ? color.new(bull_col, 90) : trend_regime == -1 ? color.new(bear_col, 90) : na fill(top, zero, color=bg) // ───── Trend Table ───── var table regimeTable = table.new(position.top_right, 1, 1) if barstate.islast txt = trend_regime == 1 ? "semi-line" : trend_regime == -1 ? "semi-line" : "Neutral" bgc = trend_regime == 1 ? color.new(bull_col, 20) : trend_regime == -1 ? color.new(bear_col, 20) : color.new(color.gray, 20) table.cell(regimeTable, 0, 0, txt, bgcolor=bgc, text_color=color.white, text_size=size.small)