커뮤니티

부탁드립니다

프로필 이미지
파생돌이
2025-06-19 15:29:19
232
글번호 191934
답변완료
수고하십니다 예스로 부탁드립니다 // INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{ int length = input.int(100, "Lookback Period") float channel_width = input.float(1.5, "Channel Width", step = 0.1) int channel_len = input(100, "Channel Length") bool mid_disp = input.bool(true, "Mid Line", inline = "s") bool fill_band = input.bool(true, "Fill Band", inline = "s") color col1 = input.color(#21dfac, "", inline = "s1") color col2 = input.color(#df216d, "", inline = "s1") // } // CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{ // Function to compute logarithmic regression f_log_regression(src, length) => float sumX = 0.0 float sumY = 0.0 float sumXSqr = 0.0 float 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) average = sumY / length intercept = average - slope * sumX / length + slope [slope, intercept] // Calculate slope and intercept [slope, intercept] = f_log_regression(close, length) float start = math.exp(intercept + slope * length) float end = math.exp(intercept) float diff = end - end[3] float deviation = ta.stdev(close, length) bool up_sig = ta.crossover(diff, 0) and barstate.isconfirmed bool dn_sig = ta.crossunder(diff, 0) and barstate.isconfirmed // } // PLOT ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{ // Define Colors color color_up = color.from_gradient(diff, ta.lowest(diff,200), ta.highest(diff,200), na, col1) color color_dn = color.from_gradient(diff, ta.lowest(diff,200), ta.highest(diff,200), col2, na) color channel_col = end > start ? col1 : col2 color trend_col = end > end[3] ? color_up : color_dn color trend_col1 = end > end[3] ? col1 : col2 p1 = plot(end, "Log Regression", color = trend_col1, linewidth = 2) p2 = plot(end[3], color = trend_col, display = display.none, editable = false) plotshape(up_sig ? end : na, "Up", shape.xcross, location.absolute, chart.fg_color, size = size.tiny) plotshape(dn_sig ? end : na, "Dn", shape.xcross, location.absolute, chart.fg_color, size = size.tiny) fill(p1, p2, fill_band ? trend_col : na) // Define upper and lower channel based on standard deviation var line up1 = na var line up = na var line base = na var line lw = na var line lw1 = na var label lbl_t = na if na(base) and mid_disp base := line.new(bar_index[channel_len], start, bar_index, end, style = line.style_dashed) else base.set_xy1(bar_index[channel_len], start) base.set_xy2(bar_index, end) base.set_color(chart.fg_color) if na(up1) up1 := line.new(bar_index[channel_len], start+deviation*(channel_width+0.3), bar_index, end + deviation*(channel_width+0.3), width = 3) else up1.set_xy1(bar_index[channel_len], start+deviation*(channel_width+0.3)) up1.set_xy2(bar_index, end + deviation*(channel_width+0.3)) up1.set_color(channel_col) if na(up) up := line.new(bar_index[channel_len], start+deviation*channel_width, bar_index, end + deviation*channel_width, width = 1) else up.set_xy1(bar_index[channel_len], start+deviation*channel_width) up.set_xy2(bar_index, end + deviation*channel_width) up.set_color(na) if na(lw) lw := line.new(bar_index[channel_len], start-deviation*channel_width, bar_index, end - deviation*channel_width, width = 1) else lw.set_xy1(bar_index[channel_len], start-deviation*channel_width) lw.set_xy2(bar_index, end - deviation*channel_width) lw.set_color(na) if na(lw1) lw1 := line.new(bar_index[channel_len], start-deviation*(channel_width+0.3), bar_index, end - deviation*(channel_width+0.3), width = 3) lbl_t := label.new(bar_index[channel_len], start-deviation*(channel_width+0.3)) else lw1.set_xy1(bar_index[channel_len], start-deviation*(channel_width+0.3)) lw1.set_xy2(bar_index, end - deviation*(channel_width+0.3)) lw1.set_color(channel_col) lbl_t.set_xy(bar_index[channel_len], start-deviation*(channel_width+0.3)) lbl_t.set_text(end > start ? "UP" : "DN") lbl_t.set_style((end < start ? label.style_label_lower_right : label.style_label_upper_right)) lbl_t.set_color(channel_col) lbl_t.set_textcolor(#070f23) // Fill Channel Upper and Lower Zones with color linefill.new(lw, lw1, color.new(channel_col, 70)) linefill.new(up, up1, color.new(channel_col, 70)) // Info Dash if barstate.islast dash = table.new(position.top_right, 10, 10, bgcolor = color.new(chart.fg_color, 90), border_color = chart.bg_color, border_width = 5) dash.cell(0, 0, "Slope: " + str.tostring(slope*100, "#,###.###"), text_color = chart.fg_color) dash.cell(0, 1, "Log Regression Channel: " + (end > start ? "UP" : "DN"), text_color = channel_col) dash.cell(0, 2, "Logarithmic Regression: " + (end > end[3] ? "UP" : "DN"), text_color = color.new(trend_col, 0)) // }
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-06-20 11:03:18

안녕하세요 예스스탁입니다. input : length(100); input : channel_width(1.5); input : channel_len(100); input : mid_disp(true); input : fill_band(true); input : col1(Cyan); input : col2(Red); var : sumX(0); var : sumY(0); var : sumXSqr(0); var : sumXY(0); var : i(0),val(0),per(0); var : slope(0),average(0),intercept(0); sumX = 0; sumY = 0; sumXSqr = 0; sumXY = 0; for i = 0 to length - 1 { val = Log(close[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); average = sumY / length; intercept = average - slope * sumX / length + slope; var : start(0),Ed(0),diff(0),deviation(0),up_sig(False),dn_sig(False); start = exp(intercept + slope * length); ed = exp(intercept); diff = ed - ed[3]; deviation = std(close, length); up_sig = CrossUp(diff, 0); dn_sig = CrossDown(diff, 0); var : color_up(0),color_dn(0),channel_col(0),trend_col(0),trend_col1(0); color_up = col1; color_dn = col2; channel_col = iff(ed > start , col1 , col2); trend_col = iff(ed > ed[3] , color_up , color_dn); trend_col1 = iff(ed > ed[3] , col1 , col2); plot1(ed, "Log Regression", trend_col1); plot2(ed[3],"Log Regression[3]",trend_col); var :tx1(0),tx2(0); if up_sig == true Then { tx1 = Text_New(sDate,sTime,ed,"X"); Text_SetStyle(tx1,2,2); Text_SetColor(tx1,Black); } if dn_sig == true Then { tx2 = Text_New(sDate,sTime,ed,"X"); Text_SetStyle(tx2,2,2); Text_SetColor(tx2,Black); } var : base(nan),up1(Nan),up(Nan),lw(Nan),lw1(NaN),lbl_t(Nan); if IsNaN(base) == true and mid_disp == true Then { base = TL_New(sDate[channel_len],sTime[channel_len],start,sDate,sTime,ed); TL_SetStyle(base,3); } Else { TL_SetBegin(base,sDate[channel_len],sTime[channel_len],start); TL_SetEnd(base,sDate,sTime,ed); } if IsNan(up1) == true Then { up1 = TL_New(sDate[channel_len],sTime[channel_len],start+deviation*(channel_width+0.3),sDate,sTime,ed + deviation*(channel_width+0.3)); TL_SetSize(up1,3); TL_SetColor(up1,channel_col); } else { TL_SetBegin(up1,sDate[channel_len],sTime[channel_len],start+deviation*(channel_width+0.3)); TL_SetEnd(up1,sDate,sTime,ed + deviation*(channel_width+0.3)); } if IsNan(up) == true Then { up = TL_New(sDate[channel_len],sTime[channel_len],start+deviation*channel_width,sDate,sTime,ed + deviation*channel_width); TL_SetSize(up,1); TL_SetColor(up,channel_col); } else { TL_SetBegin(up,sDate[channel_len],sTime[channel_len],start+deviation*channel_width); TL_SetEnd(up,sDate,sTime,ed + deviation*channel_width); } if IsNan(lw) == true Then { lw = TL_New(sDate[channel_len],sTime[channel_len],start-deviation*channel_width,sDate,sTime,ed - deviation*channel_width); TL_SetSize(lw,1); TL_SetColor(lw,channel_col); } else { TL_SetBegin(lw,sDate[channel_len],sTime[channel_len],start-deviation*channel_width); TL_SetEnd(lw,sDate,sTime,ed - deviation*channel_width); } if IsNan(lw1) == true Then { lw1 = TL_New(sDate[channel_len],sTime[channel_len],start-deviation*(channel_width+0.3),sDate,sTime,ed - deviation*(channel_width+0.3)); TL_SetSize(lw1,3); TL_SetColor(lw1,channel_col); lbl_t = Text_New(sDate[channel_len],sTime[channel_len],start-deviation*(channel_width+0.3),"a"); } else { TL_SetBegin(lw1,sDate[channel_len],sTime[channel_len],start-deviation*(channel_width+0.3)); TL_SetEnd(lw1,sDate,sTime,ed - deviation*(channel_width+0.3)); Text_SetLocation(lbl_t,sDate[channel_len],sTime[channel_len],start-deviation*(channel_width+0.3)); if ed > start Then Text_SetString(lbl_t,"UP"); Else Text_SetString(lbl_t,"DN"); Text_SetColor(lbl_t,Black); } var : GridID(0), str1(""),str2(""),str3(""); GridID = Grid_New(1, 1, 3, White, White, 1, White, 1); # 그리드 셀 값 입력 if( LastBarOnChart() == 1 ) Then { str1 = "Slope : "+NumToStr(slope,3); if ed > start Then str2 = "Log Regression Channel : UP"; Else str2 = "Log Regression Channel : DN"; if ed > ed[3] Then str3 = "Logarithmic Regression : UP"; Else str3 = "Logarithmic Regression : DN"; Grid_Cell(GridID,0,0,str1,0,0,Black,Black); Grid_Cell(GridID,0,1,str2,0,0,Black,Black); Grid_Cell(GridID,0,2,str3,0,0,Black,Black); Grid_CellSetTextHAlign(GridID,0,0, 2); Grid_CellSetTextVAlign(GridID,0,0, 2); } 즐거운 하루되세요 > 파생돌이 님이 쓴 글입니다. > 제목 : 부탁드립니다 > 수고하십니다 예스로 부탁드립니다 // INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{ int length = input.int(100, "Lookback Period") float channel_width = input.float(1.5, "Channel Width", step = 0.1) int channel_len = input(100, "Channel Length") bool mid_disp = input.bool(true, "Mid Line", inline = "s") bool fill_band = input.bool(true, "Fill Band", inline = "s") color col1 = input.color(#21dfac, "", inline = "s1") color col2 = input.color(#df216d, "", inline = "s1") // } // CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{ // Function to compute logarithmic regression f_log_regression(src, length) => float sumX = 0.0 float sumY = 0.0 float sumXSqr = 0.0 float 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) average = sumY / length intercept = average - slope * sumX / length + slope [slope, intercept] // Calculate slope and intercept [slope, intercept] = f_log_regression(close, length) float start = math.exp(intercept + slope * length) float end = math.exp(intercept) float diff = end - end[3] float deviation = ta.stdev(close, length) bool up_sig = ta.crossover(diff, 0) and barstate.isconfirmed bool dn_sig = ta.crossunder(diff, 0) and barstate.isconfirmed // } // PLOT ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{ // Define Colors color color_up = color.from_gradient(diff, ta.lowest(diff,200), ta.highest(diff,200), na, col1) color color_dn = color.from_gradient(diff, ta.lowest(diff,200), ta.highest(diff,200), col2, na) color channel_col = end > start ? col1 : col2 color trend_col = end > end[3] ? color_up : color_dn color trend_col1 = end > end[3] ? col1 : col2 p1 = plot(end, "Log Regression", color = trend_col1, linewidth = 2) p2 = plot(end[3], color = trend_col, display = display.none, editable = false) plotshape(up_sig ? end : na, "Up", shape.xcross, location.absolute, chart.fg_color, size = size.tiny) plotshape(dn_sig ? end : na, "Dn", shape.xcross, location.absolute, chart.fg_color, size = size.tiny) fill(p1, p2, fill_band ? trend_col : na) // Define upper and lower channel based on standard deviation var line up1 = na var line up = na var line base = na var line lw = na var line lw1 = na var label lbl_t = na if na(base) and mid_disp base := line.new(bar_index[channel_len], start, bar_index, end, style = line.style_dashed) else base.set_xy1(bar_index[channel_len], start) base.set_xy2(bar_index, end) base.set_color(chart.fg_color) if na(up1) up1 := line.new(bar_index[channel_len], start+deviation*(channel_width+0.3), bar_index, end + deviation*(channel_width+0.3), width = 3) else up1.set_xy1(bar_index[channel_len], start+deviation*(channel_width+0.3)) up1.set_xy2(bar_index, end + deviation*(channel_width+0.3)) up1.set_color(channel_col) if na(up) up := line.new(bar_index[channel_len], start+deviation*channel_width, bar_index, end + deviation*channel_width, width = 1) else up.set_xy1(bar_index[channel_len], start+deviation*channel_width) up.set_xy2(bar_index, end + deviation*channel_width) up.set_color(na) if na(lw) lw := line.new(bar_index[channel_len], start-deviation*channel_width, bar_index, end - deviation*channel_width, width = 1) else lw.set_xy1(bar_index[channel_len], start-deviation*channel_width) lw.set_xy2(bar_index, end - deviation*channel_width) lw.set_color(na) if na(lw1) lw1 := line.new(bar_index[channel_len], start-deviation*(channel_width+0.3), bar_index, end - deviation*(channel_width+0.3), width = 3) lbl_t := label.new(bar_index[channel_len], start-deviation*(channel_width+0.3)) else lw1.set_xy1(bar_index[channel_len], start-deviation*(channel_width+0.3)) lw1.set_xy2(bar_index, end - deviation*(channel_width+0.3)) lw1.set_color(channel_col) lbl_t.set_xy(bar_index[channel_len], start-deviation*(channel_width+0.3)) lbl_t.set_text(end > start ? "UP" : "DN") lbl_t.set_style((end < start ? label.style_label_lower_right : label.style_label_upper_right)) lbl_t.set_color(channel_col) lbl_t.set_textcolor(#070f23) // Fill Channel Upper and Lower Zones with color linefill.new(lw, lw1, color.new(channel_col, 70)) linefill.new(up, up1, color.new(channel_col, 70)) // Info Dash if barstate.islast dash = table.new(position.top_right, 10, 10, bgcolor = color.new(chart.fg_color, 90), border_color = chart.bg_color, border_width = 5) dash.cell(0, 0, "Slope: " + str.tostring(slope*100, "#,###.###"), text_color = chart.fg_color) dash.cell(0, 1, "Log Regression Channel: " + (end > start ? "UP" : "DN"), text_color = channel_col) dash.cell(0, 2, "Logarithmic Regression: " + (end > end[3] ? "UP" : "DN"), text_color = color.new(trend_col, 0)) // }