커뮤니티

수식변환 부탁드립니다.

프로필 이미지
이글루
2025-06-05 18:20:20
313
글번호 191467
답변완료
안녕하세요 수식변환 부탁드립니다. //@version=6 indicator("카르마RSI", overlay=true, max_bars_back = 500) // 채널 설정 int length = input.int(150, "채널 길이", group = "CHANNEL") float channel_width = input.float(1.5, "채널 폭", step = 0.1, group = "CHANNEL") bool mid_disp = input.bool(true, "50선", inline = "s", group = "CHANNEL") bool fill_band = input.bool(true, "백그라운드", inline = "s", group = "CHANNEL") color col_up = input.color(#a7abb9, "라인 색상:ㅤㅤ상단", group = "CHANNEL", inline = "Col") color col_mid = input.color(color.gray, "중앙", group = "CHANNEL", inline = "Col") color col_low = input.color(#a7abb9, "하단", group = "CHANNEL", inline = "Col") // RSI 설정 int lengtht = input.int(14, "길이", inline = "rsi", group = "RSI") color osc_col_base = input.color(color.rgb(161, 0, 182), "", inline = "rsi", group = "RSI") int rsiOpacity = input.int(70, "RSI 선 투명도 (0~100)", minval=0, maxval=100, group="RSI") int upper_threshold = input.int(70, "Scale", group = "RSI", inline = "rsi1") bool show_threshold_labels = input.bool(true, "기준선 라벨 표시", group = "RSI") bool sig_disp = input.bool(true, "Signal Line", inline = "sig") int length_sig = input.int(14, "", inline = "sig") color sig_line = input.color(color.rgb(255, 0, 0), "", inline = "sig") // 채널 구조 f_log_regression(src, length) => float sumX = 0.0, sumY = 0.0, sumXSqr = 0.0, sumXY = 0.0 for i = 0 to length - 1 val = math.log(src[i]) per = i + 1.0 sumX += per sumY += val sumXSqr += per * per sumXY += val * per slope = (length * sumXY - sumX * sumY) / (length * sumXSqr - sumX * sumX) intercept = (sumY - slope * sumX) / length [slope, intercept] [slope, intercept] = f_log_regression(close, length) reg_start = math.exp(intercept + slope * length) reg_end = math.exp(intercept) deviation = ta.stdev(close, length) upper_start = reg_start + deviation * channel_width upper_end = reg_end + deviation * channel_width lower_start = reg_start - deviation * channel_width lower_end = reg_end - deviation * channel_width var line mid_line = na var line upper_line = na var line lower_line = na if na(mid_line) and mid_disp mid_line := line.new(bar_index[length], reg_start, bar_index, reg_end, color=col_mid, style=line.style_dashed) else line.set_xy1(mid_line, bar_index[length], reg_start) line.set_xy2(mid_line, bar_index, reg_end) if na(upper_line) upper_line := line.new(bar_index[length], upper_start, bar_index, upper_end, width=2, color=col_up) else line.set_xy1(upper_line, bar_index[length], upper_start) line.set_xy2(upper_line, bar_index, upper_end) if na(lower_line) lower_line := line.new(bar_index[length], lower_start, bar_index, lower_end, width=2, color=col_low) else line.set_xy1(lower_line, bar_index[length], lower_start) line.set_xy2(lower_line, bar_index, lower_end) // RSI 계산 lower_threshold = 100 - upper_threshold slope_ = (reg_start - reg_end) / length step = (upper_end - lower_end) / (upper_threshold - lower_threshold) rsi = ta.rsi(close, lengtht) sma_osc = ta.sma(rsi, length_sig) osc_col = color.new(osc_col_base, 100 - rsiOpacity) // 시각화 polyline_disp(float src, bool display, bool shadow = true, color_, width = 1) => if barstate.islast and display points = array.new<chart.point>() for i = 0 to length - 1 val = src[i] - lower_threshold lower = lower_end + slope_ * i cp = chart.point.from_index(bar_index[i], lower + step * val) array.push(points, cp) p1 = polyline.new(points, line_color=color_, closed=false, force_overlay=true, line_width=width) polyline.delete(p1[1]) if shadow label.delete(label.new(bar_index, lower_end + step * (src - lower_threshold), "&#2325;&#2352;&#2381;&#2350; RSI: " + str.tostring(src, "#.##"), style=label.style_label_left, color=color(na), textcolor=chart.fg_color)[1]) if show_threshold_labels label.delete(label.new(bar_index, lower_end, str.tostring(lower_threshold, " ##.#"), style=label.style_label_left, color=color(na), textcolor=chart.fg_color)[1]) label.delete(label.new(bar_index, upper_end, str.tostring(upper_threshold, " ##.#"), style=label.style_label_left, color=color(na), textcolor=chart.fg_color)[1]) // 배경 if fill_band linefill.new(upper_line, lower_line, color.new(osc_col, 95)) // Plot polyline_disp(rsi, true, true, osc_col, 4) polyline_disp(sma_osc, sig_disp, false, sig_line, 2)
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-06-09 14:17:59

안녕하세요 예스스탁입니다. polyline관련 내용은 구현이 되지 않습니다. input : length(150); input : channel_width(1.5); input : mid_disp(true); input : fill_band(true); input : col_up(Silver); input : col_mid(gray); input : col_low(Silver); input : lengtht(14); input : osc_col_base(Violet); input : rsiOpacity(70); input : upper_threshold(70); input : show_threshold_labels(true); input : sig_disp(true); input : length_sig(14); input : sig_line(Red); var : src(0),sumx(0),sumy(0),Sumxsqr(0),sumxy(0),i(0),val(0),per(0); var : slope(0),intercept(0); var : reg_start(0),reg_end(0),deviation(0); var : upper_start(0),upper_end(0); var : lower_start(0),lower_end(0); src = close; sumx = 0; sumy = 0; sumxsqr = 0; sumxy = 0; for i = 0 to length - 1 { val = log(src[i]); per = i + 1.0; sumX = sumX + per; sumY = sumY + val; sumXSqr = sumXSqr +(per * per); sumXY = sumXY + (val * per); } slope = (length * sumXY - sumX * sumY) / (length * sumXSqr - sumX * sumX); intercept = (sumY - slope * sumX) / length; reg_start = exp(intercept + slope * length); reg_end = exp(intercept); deviation = std(close, length); upper_start = reg_start + deviation * channel_width; upper_end = reg_end + deviation * channel_width; lower_start = reg_start - deviation * channel_width; lower_end = reg_end - deviation * channel_width; var : mid_line(Nan),upper_line(Nan),lower_line(Nan); if IsNan(mid_line) == true and mid_disp Then { mid_line = TL_New(sDate[length],sTime[length],reg_start,sDate,sTime,reg_start); TL_SetColor(upper_line,col_mid); TL_SetStyle(mid_line,3); } else { TL_SetBegin(mid_line, sDate[length],sTime[length], reg_start); TL_SetEnd(mid_line,sDate,sTime,reg_end); } if IsNan(upper_line) == true Then { upper_line = TL_New(sDate[length],sTime[length],upper_start,sDate,sTime,upper_end); TL_SetColor(upper_line,col_up); } else { TL_SetBegin(upper_line, sDate[length],sTime[length], upper_start); TL_SetEnd(upper_line,sDate,sTime,upper_end); } if IsNan(lower_line) == true Then { lower_line = TL_New(sDate[length],sTime[length],lower_start,sDate,sTime,lower_end); TL_SetColor(lower_line,col_low); } else { TL_SetBegin(lower_line, sDate[length],sTime[length], lower_start); TL_SetEnd(lower_line,sDate,sTime,lower_end); } var : lower_threshold(0),slope_(0),stp(0); var : r(0),sma_osc(0),osc_col(0); lower_threshold = 100 - upper_threshold; slope_ = (reg_start - reg_end) / length; stp = (upper_end - lower_end) / (upper_threshold - lower_threshold); r = rsi(lengtht); sma_osc = ma(r, length_sig); osc_col =osc_col_base; 즐거운 하루되세요 > 이글루 님이 쓴 글입니다. > 제목 : 수식변환 부탁드립니다. > 안녕하세요 수식변환 부탁드립니다. //@version=6 indicator("카르마RSI", overlay=true, max_bars_back = 500) // 채널 설정 int length = input.int(150, "채널 길이", group = "CHANNEL") float channel_width = input.float(1.5, "채널 폭", step = 0.1, group = "CHANNEL") bool mid_disp = input.bool(true, "50선", inline = "s", group = "CHANNEL") bool fill_band = input.bool(true, "백그라운드", inline = "s", group = "CHANNEL") color col_up = input.color(#a7abb9, "라인 색상:ㅤㅤ상단", group = "CHANNEL", inline = "Col") color col_mid = input.color(color.gray, "중앙", group = "CHANNEL", inline = "Col") color col_low = input.color(#a7abb9, "하단", group = "CHANNEL", inline = "Col") // RSI 설정 int lengtht = input.int(14, "길이", inline = "rsi", group = "RSI") color osc_col_base = input.color(color.rgb(161, 0, 182), "", inline = "rsi", group = "RSI") int rsiOpacity = input.int(70, "RSI 선 투명도 (0~100)", minval=0, maxval=100, group="RSI") int upper_threshold = input.int(70, "Scale", group = "RSI", inline = "rsi1") bool show_threshold_labels = input.bool(true, "기준선 라벨 표시", group = "RSI") bool sig_disp = input.bool(true, "Signal Line", inline = "sig") int length_sig = input.int(14, "", inline = "sig") color sig_line = input.color(color.rgb(255, 0, 0), "", inline = "sig") // 채널 구조 f_log_regression(src, length) => float sumX = 0.0, sumY = 0.0, sumXSqr = 0.0, sumXY = 0.0 for i = 0 to length - 1 val = math.log(src[i]) per = i + 1.0 sumX += per sumY += val sumXSqr += per * per sumXY += val * per slope = (length * sumXY - sumX * sumY) / (length * sumXSqr - sumX * sumX) intercept = (sumY - slope * sumX) / length [slope, intercept] [slope, intercept] = f_log_regression(close, length) reg_start = math.exp(intercept + slope * length) reg_end = math.exp(intercept) deviation = ta.stdev(close, length) upper_start = reg_start + deviation * channel_width upper_end = reg_end + deviation * channel_width lower_start = reg_start - deviation * channel_width lower_end = reg_end - deviation * channel_width var line mid_line = na var line upper_line = na var line lower_line = na if na(mid_line) and mid_disp mid_line := line.new(bar_index[length], reg_start, bar_index, reg_end, color=col_mid, style=line.style_dashed) else line.set_xy1(mid_line, bar_index[length], reg_start) line.set_xy2(mid_line, bar_index, reg_end) if na(upper_line) upper_line := line.new(bar_index[length], upper_start, bar_index, upper_end, width=2, color=col_up) else line.set_xy1(upper_line, bar_index[length], upper_start) line.set_xy2(upper_line, bar_index, upper_end) if na(lower_line) lower_line := line.new(bar_index[length], lower_start, bar_index, lower_end, width=2, color=col_low) else line.set_xy1(lower_line, bar_index[length], lower_start) line.set_xy2(lower_line, bar_index, lower_end) // RSI 계산 lower_threshold = 100 - upper_threshold slope_ = (reg_start - reg_end) / length step = (upper_end - lower_end) / (upper_threshold - lower_threshold) rsi = ta.rsi(close, lengtht) sma_osc = ta.sma(rsi, length_sig) osc_col = color.new(osc_col_base, 100 - rsiOpacity) // 시각화 polyline_disp(float src, bool display, bool shadow = true, color_, width = 1) => if barstate.islast and display points = array.new<chart.point>() for i = 0 to length - 1 val = src[i] - lower_threshold lower = lower_end + slope_ * i cp = chart.point.from_index(bar_index[i], lower + step * val) array.push(points, cp) p1 = polyline.new(points, line_color=color_, closed=false, force_overlay=true, line_width=width) polyline.delete(p1[1]) if shadow label.delete(label.new(bar_index, lower_end + step * (src - lower_threshold), "&#2325;&#2352;&#2381;&#2350; RSI: " + str.tostring(src, "#.##"), style=label.style_label_left, color=color(na), textcolor=chart.fg_color)[1]) if show_threshold_labels label.delete(label.new(bar_index, lower_end, str.tostring(lower_threshold, " ##.#"), style=label.style_label_left, color=color(na), textcolor=chart.fg_color)[1]) label.delete(label.new(bar_index, upper_end, str.tostring(upper_threshold, " ##.#"), style=label.style_label_left, color=color(na), textcolor=chart.fg_color)[1]) // 배경 if fill_band linefill.new(upper_line, lower_line, color.new(osc_col, 95)) // Plot polyline_disp(rsi, true, true, osc_col, 4) polyline_disp(sma_osc, sig_disp, false, sig_line, 2)