커뮤니티

지표 변환 부탁드립니다.

프로필 이미지
플로스트
2025-05-09 10:47:34
330
글번호 190676
답변완료
항상 감사합니다. 아래는 트레이딩뷰 스크립트입니다. 시간이 오래 걸리면 이평선 만이라도 차트에 적용할 수 있게 변환 부탁드립니다. //@version=5 indicator("Market Structure Trend Targets [ChartPrime]", "Market Structure TT [ChartPrime]", overlay = true, max_lines_count = 500, max_labels_count = 500) // --------------------------------------------------------------------------------------------------------------------} // &#120400;&#120398;&#120384;&#120397; &#120388;&#120393;&#120395;&#120400;&#120399;&#120398; // --------------------------------------------------------------------------------------------------------------------{ int length = input.int(10, "Length", maxval = 30, minval = 2) bool display_per = input.bool(false, "Display %") bool display_stop = input.bool(true, "Display Trailing Stop") color col_up = input.color(#54b6d4, "+", inline = "col") color col_dn = input.color(#cf3737, "-", inline = "col") // --------------------------------------------------------------------------------------------------------------------} // &#120388;&#120393;&#120383;&#120388;&#120382;&#120380;&#120399;&#120394;&#120397; &#120382;&#120380;&#120391;&#120382;&#120400;&#120391;&#120380;&#120399;&#120388;&#120394;&#120393;&#120398; // --------------------------------------------------------------------------------------------------------------------{ series float ph = ta.pivothigh(length, length) series float pl = ta.pivotlow(length, length) market_structure()=> var upper = float(na) var lower = float(na) var upper_count = 0 var lower_count = 0 var upper_index = 0 var lower_index = 0 var trend = bool(na) float source = ta.sma(high - low, 50)*2 float source1 = ta.sma(ta.median(close, 40), 10) float volatility = math.avg(ta.highest(source, 200), ta.lowest(source, 200)) float trend_line = float(na) var line_h = line(na) var line_l = line(na) if not na(ph) upper_index := bar_index[length] upper := high[length] line_h := line.new(upper_index, upper, upper_index, upper, color = col_up) if not na(pl) lower_index := bar_index[length] lower := low[length] line_l := line.new(lower_index, lower, lower_index, lower, color = col_dn) if ta.crossover(high, upper) upper_count += 1 var price_enter = 0. int index = bar_index - (bar_index - upper_index)/2 if upper_count == 1 price_enter := line_h.get_y1() float percent = (line_h.get_y1() - price_enter) / price_enter * 100 string txt = upper_count == 1 ? str.tostring(price_enter, "#.# △") : (display_per ? str.tostring(percent, format.percent) : str.tostring(upper_count-1)) label.new(index, line_h.get_y1(), txt, textcolor = chart.fg_color, color = color(na)) line_h.set_x2(bar_index) line_h := na upper := na lower_count := 0 trend := true if ta.crossunder(low, lower) lower_count += 1 var price_enter = 0. int index = bar_index - (bar_index - lower_index)/2 if lower_count == 1 price_enter := line_l.get_y1() float percent = (line_l.get_y1() - price_enter) / price_enter * 100 string txt = lower_count == 1 ? str.tostring(price_enter, "#.# ▽") : (display_per ? str.tostring(percent, format.percent) : str.tostring(lower_count-1)) label.new(index, line_l.get_y1(), txt, textcolor = chart.fg_color, color = color(na), style = label.style_label_up) line_l.set_x2(bar_index) line_l := na lower := na upper_count := 0 trend := false if trend trend_line := source1 - volatility else trend_line := source1 + volatility color color = trend ? col_up : col_dn if trend and ta.crossover(low, trend_line) and display_stop and not (trend and not trend[1]) label.new(bar_index[1], low[1], text = "◈", style = label.style_label_up, textcolor = color, color = color(na)) if not trend and ta.crossunder(high, trend_line) and display_stop and not (trend[1] and not trend) label.new(bar_index[1], high[1], text = "◈", style = label.style_label_down, textcolor = color, color = color(na)) if trend and not trend[1] label.new(bar_index, trend_line, text = "△", textcolor = color, style = label.style_label_center, color = color(na), size = size.large) if not trend and trend[1] label.new(bar_index, trend_line, text = "▽", textcolor = color, style = label.style_label_center, color = color(na), size = size.large) [color, trend_line, trend] [color, trend_line, trend] = market_structure() float stop_loss = trend_line, stop_loss := ta.change(trend) ? na : high > stop_loss and not trend ? na : low < stop_loss and trend ? na : stop_loss // --------------------------------------------------------------------------------------------------------------------} // &#120401;&#120388;&#120398;&#120400;&#120380;&#120391;&#120388;&#120405;&#120380;&#120399;&#120388;&#120394;&#120393; // --------------------------------------------------------------------------------------------------------------------{ display = display_stop ? display.all : display.none color1 = display_stop ? 90 : 100 sl = plot(stop_loss, style = plot.style_linebr, color = color, display = display), plot(stop_loss, style = plot.style_linebr, color = color.new(color, 80), linewidth = 5, display = display) pp = plot(hl2, color = color(na)) fill(sl, pp, stop_loss, hl2, color.new(color, color1), na) candle_col = color.new(color, 50) plotcandle(open, high, low, close, title='Candles Trend', color = candle_col, wickcolor=candle_col, bordercolor = candle_col) // --------------------------------------------------------------------------------------------------------------------}
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-05-09 17:32:51

안녕하세요 예스스탁입니다. input : length(10); input : display_per(false); input : display_stop(true); input : col_up(Blue); input : col_dn(Red); var : upper(nan),upperD(nan),upperT(nan); var : lower(nan),lowerD(nan),lowerT(nan); var : upper_count(0); var : lower_count(0); var : upper_index(0); var : lower_index(0); var : trend(False); var : source(0),source1(0),volatility(0),trend_line(Nan); var : line_h(0),line_l(0),color(0),cnt(0); Array : CC[100](0); For cnt = 39 DownTo 1 { CC[cnt] = CC[cnt-1]; } CC[0] = C; source = ma(high - low, 50)*2; source1 = ma(MedianArray(CC, 40), 10); volatility = (highest(source, 200)+lowest(source, 200))/2; if SwingHigh(1,h,length,length,length*2+1) != -1 Then { upperD = sDate[length]; upperT = sTime[length]; upper = high[length]; } if SwingLow(1,L,length,length,length*2+1) != -1 Then { lowerD = sDate[length]; lowerT = sTime[length]; lower = low[length]; } var : price_enter(0),idx(0); if CrossUp(high, upper) Then { upper_count = upper_count + 1; line_h = TL_new(upperD,upperT,upper, sDate,sTime,upper); TL_SetColor(line_h,col_up); upper = Nan; lower_count = 0; trend = true; } if CrossDown(low, lower) then { lower_count = lower_count + 1; line_l = TL_new(lowerD,lowerT,lower, sDate,sTime,lower); TL_SetColor(line_l,col_dn); lower = nan; upper_count = 0; trend = false; } if trend Then trend_line = source1 - volatility; else trend_line = source1 + volatility; color = iff(trend , col_up , col_dn); var : stop_loss(0); stop_loss = trend_line; stop_loss = iff(trend != Trend[1] , Nan , iff(high > stop_loss and trend == False , Nan , iff(low < stop_loss and trend == true , Nan , stop_loss))); if stop_loss > 0 Then { plot1(stop_loss,"stop_loss", color); } Else { NoPlot(1); } 즐거운 하루되세요 > 플로스트 님이 쓴 글입니다. > 제목 : 지표 변환 부탁드립니다. > 항상 감사합니다. 아래는 트레이딩뷰 스크립트입니다. 시간이 오래 걸리면 이평선 만이라도 차트에 적용할 수 있게 변환 부탁드립니다. //@version=5 indicator("Market Structure Trend Targets [ChartPrime]", "Market Structure TT [ChartPrime]", overlay = true, max_lines_count = 500, max_labels_count = 500) // --------------------------------------------------------------------------------------------------------------------} // &#120400;&#120398;&#120384;&#120397; &#120388;&#120393;&#120395;&#120400;&#120399;&#120398; // --------------------------------------------------------------------------------------------------------------------{ int length = input.int(10, "Length", maxval = 30, minval = 2) bool display_per = input.bool(false, "Display %") bool display_stop = input.bool(true, "Display Trailing Stop") color col_up = input.color(#54b6d4, "+", inline = "col") color col_dn = input.color(#cf3737, "-", inline = "col") // --------------------------------------------------------------------------------------------------------------------} // &#120388;&#120393;&#120383;&#120388;&#120382;&#120380;&#120399;&#120394;&#120397; &#120382;&#120380;&#120391;&#120382;&#120400;&#120391;&#120380;&#120399;&#120388;&#120394;&#120393;&#120398; // --------------------------------------------------------------------------------------------------------------------{ series float ph = ta.pivothigh(length, length) series float pl = ta.pivotlow(length, length) market_structure()=> var upper = float(na) var lower = float(na) var upper_count = 0 var lower_count = 0 var upper_index = 0 var lower_index = 0 var trend = bool(na) float source = ta.sma(high - low, 50)*2 float source1 = ta.sma(ta.median(close, 40), 10) float volatility = math.avg(ta.highest(source, 200), ta.lowest(source, 200)) float trend_line = float(na) var line_h = line(na) var line_l = line(na) if not na(ph) upper_index := bar_index[length] upper := high[length] line_h := line.new(upper_index, upper, upper_index, upper, color = col_up) if not na(pl) lower_index := bar_index[length] lower := low[length] line_l := line.new(lower_index, lower, lower_index, lower, color = col_dn) if ta.crossover(high, upper) upper_count += 1 var price_enter = 0. int index = bar_index - (bar_index - upper_index)/2 if upper_count == 1 price_enter := line_h.get_y1() float percent = (line_h.get_y1() - price_enter) / price_enter * 100 string txt = upper_count == 1 ? str.tostring(price_enter, "#.# △") : (display_per ? str.tostring(percent, format.percent) : str.tostring(upper_count-1)) label.new(index, line_h.get_y1(), txt, textcolor = chart.fg_color, color = color(na)) line_h.set_x2(bar_index) line_h := na upper := na lower_count := 0 trend := true if ta.crossunder(low, lower) lower_count += 1 var price_enter = 0. int index = bar_index - (bar_index - lower_index)/2 if lower_count == 1 price_enter := line_l.get_y1() float percent = (line_l.get_y1() - price_enter) / price_enter * 100 string txt = lower_count == 1 ? str.tostring(price_enter, "#.# ▽") : (display_per ? str.tostring(percent, format.percent) : str.tostring(lower_count-1)) label.new(index, line_l.get_y1(), txt, textcolor = chart.fg_color, color = color(na), style = label.style_label_up) line_l.set_x2(bar_index) line_l := na lower := na upper_count := 0 trend := false if trend trend_line := source1 - volatility else trend_line := source1 + volatility color color = trend ? col_up : col_dn if trend and ta.crossover(low, trend_line) and display_stop and not (trend and not trend[1]) label.new(bar_index[1], low[1], text = "◈", style = label.style_label_up, textcolor = color, color = color(na)) if not trend and ta.crossunder(high, trend_line) and display_stop and not (trend[1] and not trend) label.new(bar_index[1], high[1], text = "◈", style = label.style_label_down, textcolor = color, color = color(na)) if trend and not trend[1] label.new(bar_index, trend_line, text = "△", textcolor = color, style = label.style_label_center, color = color(na), size = size.large) if not trend and trend[1] label.new(bar_index, trend_line, text = "▽", textcolor = color, style = label.style_label_center, color = color(na), size = size.large) [color, trend_line, trend] [color, trend_line, trend] = market_structure() float stop_loss = trend_line, stop_loss := ta.change(trend) ? na : high > stop_loss and not trend ? na : low < stop_loss and trend ? na : stop_loss // --------------------------------------------------------------------------------------------------------------------} // &#120401;&#120388;&#120398;&#120400;&#120380;&#120391;&#120388;&#120405;&#120380;&#120399;&#120388;&#120394;&#120393; // --------------------------------------------------------------------------------------------------------------------{ display = display_stop ? display.all : display.none color1 = display_stop ? 90 : 100 sl = plot(stop_loss, style = plot.style_linebr, color = color, display = display), plot(stop_loss, style = plot.style_linebr, color = color.new(color, 80), linewidth = 5, display = display) pp = plot(hl2, color = color(na)) fill(sl, pp, stop_loss, hl2, color.new(color, color1), na) candle_col = color.new(color, 50) plotcandle(open, high, low, close, title='Candles Trend', color = candle_col, wickcolor=candle_col, bordercolor = candle_col) // --------------------------------------------------------------------------------------------------------------------}