커뮤니티

부틱드립니다

프로필 이미지
파생돌이
2025-06-20 10:40:52
274
글번호 191951
답변완료
수고하십니다 매번 부탁드려서 죄송합니다 예스로 변경드립니다 // This Pine S cript™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // &#169; ChartPrime //@version=5 indicator('Linear Regression Channel', overlay = true, max_lines_count = 3) // ---------------------------------------------------------------------------------------------------------------------} // &#120400;&#120398;&#120384;&#120397; &#120388;&#120393;&#120395;&#120400;&#120399;&#120398; // ---------------------------------------------------------------------------------------------------------------------{ bool bands = input.bool(true, "Plot Linear Regression Bands", group = "Settings Bands") int window = input.int(150, "Length", group = "Settings Bands") float devlen_b = input.float(3., "Deviation Linear Regression Bands",step=0.1, group = "Settings Bands") bool channel = input.bool(false, "Plot Linear Regression Channel", group = "Settings Channel") int window1 = input.int(150, "Channel Length", group = "Settings Channel") float devlen1 = input.float(1., "Deviation Linear Regression Channel",step=0.1, group = "Settings Channel") bool channel1 = input.bool(false, "Plot Future Projection of linear regression", group = "Future Projection Channel") bool arr_dirc = input.bool(false, "Plot Arrow Direction", group = "Future Projection Channel") int window2 = input.int(50, "Length", group = "Future Projection Channel") float devlen2 = input.float(1., "Deviation Future Projection Regression Channel",step=0.1, group = "Future Projection Channel") // Define colors for up, down, and mid lines color col_dn = #f01313 color col_up = color.aqua color col_mid = color.yellow color gray = color.gray color fg_col = chart.fg_color // Regression Channel Arrays Line var reglines = array.new_line(3) var reglines_ = array.new_line(3) // ---------------------------------------------------------------------------------------------------------------------} // &#120388;&#120393;&#120383;&#120388;&#120382;&#120380;&#120399;&#120394;&#120397; &#120382;&#120380;&#120391;&#120382;&#120400;&#120391;&#120380;&#120399;&#120388;&#120394;&#120393;&#120398; // ---------------------------------------------------------------------------------------------------------------------{ //@function linear_regression //@des cription Calculates linear regression coefficients for a given source and window. //@param src (series float) The data series on which linear regression is calculated. //@param window (int) The number of bars to use in the calculation. //@returns the intercept slope, Deviation, end of the channel. linear_regression(src, window) => sum_x = 0.0 sum_y = 0.0 sum_xy = 0.0 sum_x_sq = 0.0 // Calculate sums for i = 0 to window - 1 by 1 sum_x += i + 1 sum_y += src[i] sum_xy += (i + 1) * src[i] sum_x_sq += math.pow(i + 1, 2) // Calculate linear regression coefficients slope = (window * sum_xy - sum_x * sum_y) / (window * sum_x_sq - math.pow(sum_x, 2)) intercept = (sum_y - slope * sum_x) / window y1 = intercept + slope * (window - 1) dev = 0.0 for i = 0 to window - 1 dev := dev + math.pow(src[i] - (slope * (window - i) + intercept), 2) dev := math.sqrt(dev/window) [intercept, y1, dev, slope] [y2, y1, dev, slope] = linear_regression(close, window) [y2_, y1_, dev_, slope_] = linear_regression(close, window1) [y2__, y1__, dev__, slope__] = linear_regression(close, window2) // Linear Regression Channel Lines series float mid = y2 + slope series float upper = mid + ta.rma(high - low, window) * devlen_b series float lower = mid - ta.rma(high - low, window) * devlen_b // Returns True for window length period isAllowed = (last_bar_index - bar_index < window1) // ---------------------------------------------------------------------------------------------------------------------} // &#120401;&#120388;&#120398;&#120400;&#120380;&#120391;&#120388;&#120405;&#120380;&#120399;&#120388;&#120394;&#120393; // ---------------------------------------------------------------------------------------------------------------------{ // Plot upper, lower, and mid lines if channel is not enabled p_u = plot(upper, color = bands and channel ? na : bands ? gray : na, linewidth = 2) p_l = plot(lower, color = bands and channel ? na : bands ? gray : na, linewidth = 2) p_m = plot(mid, color = bands and channel ? na : bands ? gray : na) // Fill areas between upper/mid and lower/mid lines fill(p_u, p_m, mid, upper, na, bands and channel ? na : bands ? color.new(col_up, 80) : na) fill(p_m, p_l, lower, mid, bands and channel ? na : bands ? color.new(col_dn, 80) : na, na) if barstate.islast and channel for i = 0 to 2 array.set(reglines, i, line.new(x1 = bar_index - (window1 - 1), y1 = y1_ + dev_ * devlen1 * (i - 1), x2 = bar_index, y2 = y2_ + dev_ * devlen1 * (i - 1), color = color.gray, style = i % 2 == 1 ? line.style_dashed : line.style_solid, width = 2, extend = extend.none) ) linefill.new(array.get(reglines, 1), array.get(reglines, 2), color = color.new(col_up, 90)) linefill.new(array.get(reglines, 1), array.get(reglines, 0), color = color.new(col_dn, 90)) if barstate.islast and channel1 for i = 0 to 2 array.set(reglines_, i, line.new(x1 = bar_index - (window2 - 1), y1 = y1__ + dev__ * devlen2 * (i - 1), x2 = bar_index, y2 = y2__ + dev__ * devlen2 * (i - 1), color = color.gray, style = i % 2 == 1 ? line.style_dotted : line.style_dashed, width = 1, extend = extend.right) ) linefill.new(array.get(reglines_, 1), array.get(reglines_, 2), color = color.new(col_up, 95)) linefill.new(array.get(reglines_, 1), array.get(reglines_, 0), color = color.new(col_dn, 95)) if arr_dirc l1 = label.new(chart.point.from_index(bar_index, hl2 > y2__ ? high : low), text = hl2 > y2__ ? "&#8663;" : hl2 < y2__ ? "&#8664;" : "⇒", textcolor = hl2 > y2__ ? col_up : hl2 < y2__ ? col_dn : gray, color = color(na), size = size.huge, style = label.style_label_left ) label.delete(l1[1]) // Bar Heat Map b_c = (close - lower) / (upper - lower) b_c := b_c > 1 ? 1 : b_c < 0 ? 0 : b_c bar_color = channel ? (isAllowed ? (b_c <= 0.5 ? color.from_gradient(b_c, 0, 0.5, col_up, col_mid) : color.from_gradient(b_c, 0.5, 1, col_mid, col_dn)) : na) : (b_c >= 0.5 ? color.from_gradient(b_c, 0.5, 1, col_mid, col_up) : color.from_gradient(b_c, 0, 0.5, col_dn, col_mid)) plotcandle(open, high, low, close, title = "Bar HeatMap", color = bar_color, wickcolor = bar_color, bordercolor = bar_color ) barcolor(bar_color) // Conditions for crossovers condition1 = bands and channel ? na : bands ? ta.pivotlow(3, 3) and close < lower : na condition2 = bands and channel ? na : bands ? ta.pivothigh(3, 3) and close > upper: na // Plot markers for channel break outs plotchar(condition1, "", "◆", size=size.tiny, location=location.belowbar, color = col_up) plotchar(condition2, "", "◆", size=size.tiny, location=location.abovebar, color = col_dn) // ------------------------------------------------------------------------------------
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-06-20 14:40:13

안녕하세요 예스스탁입니다. 선그래프만 작성해 드립니다. input : window(100),devlen_b(2.0); var : sum_x(0),sum_y(0),sum_xy(0),sum_x_sq(0),i(0); var : slope(0),y2(0),y1(0),dev(0); var : mid(0),upper(0),lower(0),alpha(0),rmav(0); sum_x = 0.0; sum_y = 0.0; sum_xy = 0.0; sum_x_sq = 0.0; for i = 0 to window - 1 { sum_x = sum_x + i + 1; sum_y = sum_y + close[i]; sum_xy = sum_xy + (i + 1) * close[i]; sum_x_sq = sum_x_sq + pow(i + 1, 2); } slope = (window * sum_xy - sum_x * sum_y) / (window * sum_x_sq - pow(sum_x, 2)); y2 = (sum_y - slope * sum_x) / window; y1 = y2 + slope * (window - 1); dev = 0.0; for i = 0 to window - 1 { dev = dev + pow(close[i] - (slope * (window - i) + y2), 2); } dev = sqrt(dev / window); mid = y2 + slope; alpha = 1 / window ; rmav = IFf(IsNan(rmav[1]) == true, ma(H-L,window) , alpha * (H-L) + (1 - alpha) * IFf(isnan(rmav[1])==true,0,rmav[1])); upper = mid + rmav * devlen_b; lower = mid - rmav * devlen_b; Plot1(upper,"upper",Gray); Plot2(mid,"mid",Gray); Plot3(lower,"lower",Gray); 즐거운 하루되세요 > 파생돌이 님이 쓴 글입니다. > 제목 : 부틱드립니다 > 수고하십니다 매번 부탁드려서 죄송합니다 예스로 변경드립니다 // This Pine S cript™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // &#169; ChartPrime //@version=5 indicator('Linear Regression Channel', overlay = true, max_lines_count = 3) // ---------------------------------------------------------------------------------------------------------------------} // &#120400;&#120398;&#120384;&#120397; &#120388;&#120393;&#120395;&#120400;&#120399;&#120398; // ---------------------------------------------------------------------------------------------------------------------{ bool bands = input.bool(true, "Plot Linear Regression Bands", group = "Settings Bands") int window = input.int(150, "Length", group = "Settings Bands") float devlen_b = input.float(3., "Deviation Linear Regression Bands",step=0.1, group = "Settings Bands") bool channel = input.bool(false, "Plot Linear Regression Channel", group = "Settings Channel") int window1 = input.int(150, "Channel Length", group = "Settings Channel") float devlen1 = input.float(1., "Deviation Linear Regression Channel",step=0.1, group = "Settings Channel") bool channel1 = input.bool(false, "Plot Future Projection of linear regression", group = "Future Projection Channel") bool arr_dirc = input.bool(false, "Plot Arrow Direction", group = "Future Projection Channel") int window2 = input.int(50, "Length", group = "Future Projection Channel") float devlen2 = input.float(1., "Deviation Future Projection Regression Channel",step=0.1, group = "Future Projection Channel") // Define colors for up, down, and mid lines color col_dn = #f01313 color col_up = color.aqua color col_mid = color.yellow color gray = color.gray color fg_col = chart.fg_color // Regression Channel Arrays Line var reglines = array.new_line(3) var reglines_ = array.new_line(3) // ---------------------------------------------------------------------------------------------------------------------} // &#120388;&#120393;&#120383;&#120388;&#120382;&#120380;&#120399;&#120394;&#120397; &#120382;&#120380;&#120391;&#120382;&#120400;&#120391;&#120380;&#120399;&#120388;&#120394;&#120393;&#120398; // ---------------------------------------------------------------------------------------------------------------------{ //@function linear_regression //@des cription Calculates linear regression coefficients for a given source and window. //@param src (series float) The data series on which linear regression is calculated. //@param window (int) The number of bars to use in the calculation. //@returns the intercept slope, Deviation, end of the channel. linear_regression(src, window) => sum_x = 0.0 sum_y = 0.0 sum_xy = 0.0 sum_x_sq = 0.0 // Calculate sums for i = 0 to window - 1 by 1 sum_x += i + 1 sum_y += src[i] sum_xy += (i + 1) * src[i] sum_x_sq += math.pow(i + 1, 2) // Calculate linear regression coefficients slope = (window * sum_xy - sum_x * sum_y) / (window * sum_x_sq - math.pow(sum_x, 2)) intercept = (sum_y - slope * sum_x) / window y1 = intercept + slope * (window - 1) dev = 0.0 for i = 0 to window - 1 dev := dev + math.pow(src[i] - (slope * (window - i) + intercept), 2) dev := math.sqrt(dev/window) [intercept, y1, dev, slope] [y2, y1, dev, slope] = linear_regression(close, window) [y2_, y1_, dev_, slope_] = linear_regression(close, window1) [y2__, y1__, dev__, slope__] = linear_regression(close, window2) // Linear Regression Channel Lines series float mid = y2 + slope series float upper = mid + ta.rma(high - low, window) * devlen_b series float lower = mid - ta.rma(high - low, window) * devlen_b // Returns True for window length period isAllowed = (last_bar_index - bar_index < window1) // ---------------------------------------------------------------------------------------------------------------------} // &#120401;&#120388;&#120398;&#120400;&#120380;&#120391;&#120388;&#120405;&#120380;&#120399;&#120388;&#120394;&#120393; // ---------------------------------------------------------------------------------------------------------------------{ // Plot upper, lower, and mid lines if channel is not enabled p_u = plot(upper, color = bands and channel ? na : bands ? gray : na, linewidth = 2) p_l = plot(lower, color = bands and channel ? na : bands ? gray : na, linewidth = 2) p_m = plot(mid, color = bands and channel ? na : bands ? gray : na) // Fill areas between upper/mid and lower/mid lines fill(p_u, p_m, mid, upper, na, bands and channel ? na : bands ? color.new(col_up, 80) : na) fill(p_m, p_l, lower, mid, bands and channel ? na : bands ? color.new(col_dn, 80) : na, na) if barstate.islast and channel for i = 0 to 2 array.set(reglines, i, line.new(x1 = bar_index - (window1 - 1), y1 = y1_ + dev_ * devlen1 * (i - 1), x2 = bar_index, y2 = y2_ + dev_ * devlen1 * (i - 1), color = color.gray, style = i % 2 == 1 ? line.style_dashed : line.style_solid, width = 2, extend = extend.none) ) linefill.new(array.get(reglines, 1), array.get(reglines, 2), color = color.new(col_up, 90)) linefill.new(array.get(reglines, 1), array.get(reglines, 0), color = color.new(col_dn, 90)) if barstate.islast and channel1 for i = 0 to 2 array.set(reglines_, i, line.new(x1 = bar_index - (window2 - 1), y1 = y1__ + dev__ * devlen2 * (i - 1), x2 = bar_index, y2 = y2__ + dev__ * devlen2 * (i - 1), color = color.gray, style = i % 2 == 1 ? line.style_dotted : line.style_dashed, width = 1, extend = extend.right) ) linefill.new(array.get(reglines_, 1), array.get(reglines_, 2), color = color.new(col_up, 95)) linefill.new(array.get(reglines_, 1), array.get(reglines_, 0), color = color.new(col_dn, 95)) if arr_dirc l1 = label.new(chart.point.from_index(bar_index, hl2 > y2__ ? high : low), text = hl2 > y2__ ? "&#8663;" : hl2 < y2__ ? "&#8664;" : "⇒", textcolor = hl2 > y2__ ? col_up : hl2 < y2__ ? col_dn : gray, color = color(na), size = size.huge, style = label.style_label_left ) label.delete(l1[1]) // Bar Heat Map b_c = (close - lower) / (upper - lower) b_c := b_c > 1 ? 1 : b_c < 0 ? 0 : b_c bar_color = channel ? (isAllowed ? (b_c <= 0.5 ? color.from_gradient(b_c, 0, 0.5, col_up, col_mid) : color.from_gradient(b_c, 0.5, 1, col_mid, col_dn)) : na) : (b_c >= 0.5 ? color.from_gradient(b_c, 0.5, 1, col_mid, col_up) : color.from_gradient(b_c, 0, 0.5, col_dn, col_mid)) plotcandle(open, high, low, close, title = "Bar HeatMap", color = bar_color, wickcolor = bar_color, bordercolor = bar_color ) barcolor(bar_color) // Conditions for crossovers condition1 = bands and channel ? na : bands ? ta.pivotlow(3, 3) and close < lower : na condition2 = bands and channel ? na : bands ? ta.pivothigh(3, 3) and close > upper: na // Plot markers for channel break outs plotchar(condition1, "", "◆", size=size.tiny, location=location.belowbar, color = col_up) plotchar(condition2, "", "◆", size=size.tiny, location=location.abovebar, color = col_dn) // ------------------------------------------------------------------------------------