커뮤니티

변환 부탁 드립니다.

프로필 이미지
cooparoo
2024-04-21 07:00:12
702
글번호 178767
답변완료
한 개 더 변환 부탁 드립니다. 바쁘실 텐데 정말 죄송합니다. 다음은 트레이딩뷰 소스코드입니다. //@version=5 indicator(overlay = true, max_lines_count = 500, max_labels_count = 500, max_bars_back=500) //------------------------------------------------------------------------------ //Settings //-----------------------------------------------------------------------------{ h = input.float(8.,'Bandwidth', minval = 0) mult = input.float(3., minval = 0) src = input(close, 'Source') repaint = input(true, 'Repainting Smoothing', tooltip = 'Repainting is an effect where the indicators historical output is subject to change over time. Disabling repainting will cause the indicator to output the endpoints of the calculations') //Style upCss = input.color(color.teal, 'Colors', inline = 'inline1', group = 'Style') dnCss = input.color(color.red, '', inline = 'inline1', group = 'Style') //-----------------------------------------------------------------------------} //Functions //-----------------------------------------------------------------------------{ //Gaussian window gauss(x, h) => math.exp(-(math.pow(x, 2)/(h * h * 2))) //-----------------------------------------------------------------------------} //Append lines //-----------------------------------------------------------------------------{ n = bar_index var ln = array.new_line(0) if barstate.isfirst and repaint for i = 0 to 499 array.push(ln,line.new(na,na,na,na)) //-----------------------------------------------------------------------------} //End point method //-----------------------------------------------------------------------------{ var coefs = array.new_float(0) var den = 0. if barstate.isfirst and not repaint for i = 0 to 499 w = gauss(i, h) coefs.push(w) den := coefs.sum() out = 0. if not repaint for i = 0 to 499 out += src[i] * coefs.get(i) out /= den mae = ta.sma(math.abs(src - out), 499) * mult upper = out + mae lower = out - mae //-----------------------------------------------------------------------------} //Compute and display NWE //-----------------------------------------------------------------------------{ float y2 = na float y1 = na nwe = array.new<float>(0) if barstate.islast and repaint sae = 0. //Compute and set NWE point for i = 0 to math.min(499,n - 1) sum = 0. sumw = 0. //Compute weighted mean for j = 0 to math.min(499,n - 1) w = gauss(i - j, h) sum += src[j] * w sumw += w y2 := sum / sumw sae += math.abs(src[i] - y2) nwe.push(y2) sae := sae / math.min(499,n - 1) * mult for i = 0 to math.min(499,n - 1) if i%2 line.new(n-i+1, y1 + sae, n-i, nwe.get(i) + sae, color = upCss) line.new(n-i+1, y1 - sae, n-i, nwe.get(i) - sae, color = dnCss) if src[i] > nwe.get(i) + sae and src[i+1] < nwe.get(i) + sae label.new(n-i, src[i], '▼', color = color(na), style = label.style_label_down, textcolor = dnCss, textalign = text.align_center) if src[i] < nwe.get(i) - sae and src[i+1] > nwe.get(i) - sae label.new(n-i, src[i], '▲', color = color(na), style = label.style_label_up, textcolor = upCss, textalign = text.align_center) y1 := nwe.get(i) //-----------------------------------------------------------------------------} //Dashboard //-----------------------------------------------------------------------------{ var tb = table.new(position.top_right, 1, 1 , bgcolor = #1e222d , border_color = #373a46 , border_width = 1 , frame_color = #373a46 , frame_width = 1) if repaint tb.cell(0, 0, 'Repainting Mode Enabled', text_color = color.white, text_size = size.small) //-----------------------------------------------------------------------------} //Plot //-----------------------------------------------------------------------------} plot(repaint ? na : out + mae, 'Upper', upCss) plot(repaint ? na : out - mae, 'Lower', dnCss) //Crossing Arrows plotshape(ta.crossunder(close, out - mae) ? low : na, "Crossunder", shape.labelup, location.absolute, color(na), 0 , text = '▲', textcolor = upCss, size = size.tiny) plotshape(ta.crossover(close, out + mae) ? high : na, "Crossover", shape.labeldown, location.absolute, color(na), 0 , text = '▼', textcolor = dnCss, size = size.tiny) //-----------------------------------------------------------------------------}
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2024-04-22 15:00:31

안녕하세요 예스스탁입니다. 이전문의와 같이 올려주신 수식이 repaint이 true이면 차트상 마지막봉의 값을 기준으로 과거봉에 다시 그리는 내용입니다. repaint거 true일때 차트에 봉이 많으면 부하가 많이 걸릴수 있으므로 차트의 조회봉수를 가급적 500봉 이상 1000봉 이하 정도로 조회해서 적용하시기 바랍니다. input : hh(8),mult(3),repaint(true),upCss(Teal),dnCss(Red); var : n(0),src(0),i(0),w(0),den(0),out(0),mae(0),upper(0),lower(0); Array : ln[500](0),coefs[500](0); Array : nwe[500](0),uptx[500](0),dntx[500](0),uptx1[500](0),dntx1[500](0); src = close; n = index; den = 0; for i = 0 to 499 { ln[i] = 0; w = exp(-(pow(i, 2)/(hh *hh * 2))); coefs[i] = w; den = den + coefs[i]; } out = 0; for i = 0 to 499 { out = out +(src[i] * coefs[i]); } out = out/den; mae = ma(abs(src - out), 499) * mult; upper = out + mae; lower = out - mae; var : sae(0),y2(0),y1(0),j(0); var : sum(0),sumw(0); if Index >= 500 and repaint == true Then { for i = 0 to min(499,n - 1) { nwe[i] = 0; Text_Delete(uptx[i]); Text_Delete(dntx[i]); Text_Delete(uptx1[i]); Text_Delete(dntx1[i]); } sae = 0; for i = 0 to min(499,n - 1) { sum = 0; sumw = 0; for j = 0 to min(499,n - 1) { w = exp(-(pow(i-j, 2)/(hh *hh * 2))); sum = sum + src[j] * w; sumw = sumw + w; } y2 = sum / sumw; sae = sae + abs(src[i] - y2); nwe[i] = y2; } sae = sae / min(499,n - 1) * mult; for i = 0 to min(499,n - 1) { uptx[i] = text_new(sDate[i],sTime[i],nwe[i]+sae,"-"); Text_SetColor(uptx[i],upcss); Text_SetStyle(uptx[i],2,2); dntx[i] = text_new(sDate[i],sTime[i],nwe[i]-sae,"-"); Text_SetColor(dntx[i],dncss); Text_SetStyle(dntx[i],2,2); if src[i] > nwe[i] + sae and src[i+1] < nwe[i] + sae Then { dntx1[i] = text_new(sDate[i],sTime[i],h[i],"▼"); Text_SetColor(dntx1[i],dncss); Text_SetStyle(dntx1[i],2,1); } if src[i] < nwe[i] - sae and src[i+1] > nwe[i] - sae Then { uptx1[i] = text_new(sDate[i],sTime[i],L[i],"▲"); Text_SetColor(uptx1[i],upcss); Text_SetStyle(uptx1[i],2,0); } y1 = nwe[i]; } } if repaint == False Then { plot1(out + mae, "Upper", upCss); plot2(out - mae, "Lower", dnCss); } 즐거운 하루되세요 > cooparoo 님이 쓴 글입니다. > 제목 : 변환 부탁 드립니다. > 한 개 더 변환 부탁 드립니다. 바쁘실 텐데 정말 죄송합니다. 다음은 트레이딩뷰 소스코드입니다. //@version=5 indicator(overlay = true, max_lines_count = 500, max_labels_count = 500, max_bars_back=500) //------------------------------------------------------------------------------ //Settings //-----------------------------------------------------------------------------{ h = input.float(8.,'Bandwidth', minval = 0) mult = input.float(3., minval = 0) src = input(close, 'Source') repaint = input(true, 'Repainting Smoothing', tooltip = 'Repainting is an effect where the indicators historical output is subject to change over time. Disabling repainting will cause the indicator to output the endpoints of the calculations') //Style upCss = input.color(color.teal, 'Colors', inline = 'inline1', group = 'Style') dnCss = input.color(color.red, '', inline = 'inline1', group = 'Style') //-----------------------------------------------------------------------------} //Functions //-----------------------------------------------------------------------------{ //Gaussian window gauss(x, h) => math.exp(-(math.pow(x, 2)/(h * h * 2))) //-----------------------------------------------------------------------------} //Append lines //-----------------------------------------------------------------------------{ n = bar_index var ln = array.new_line(0) if barstate.isfirst and repaint for i = 0 to 499 array.push(ln,line.new(na,na,na,na)) //-----------------------------------------------------------------------------} //End point method //-----------------------------------------------------------------------------{ var coefs = array.new_float(0) var den = 0. if barstate.isfirst and not repaint for i = 0 to 499 w = gauss(i, h) coefs.push(w) den := coefs.sum() out = 0. if not repaint for i = 0 to 499 out += src[i] * coefs.get(i) out /= den mae = ta.sma(math.abs(src - out), 499) * mult upper = out + mae lower = out - mae //-----------------------------------------------------------------------------} //Compute and display NWE //-----------------------------------------------------------------------------{ float y2 = na float y1 = na nwe = array.new<float>(0) if barstate.islast and repaint sae = 0. //Compute and set NWE point for i = 0 to math.min(499,n - 1) sum = 0. sumw = 0. //Compute weighted mean for j = 0 to math.min(499,n - 1) w = gauss(i - j, h) sum += src[j] * w sumw += w y2 := sum / sumw sae += math.abs(src[i] - y2) nwe.push(y2) sae := sae / math.min(499,n - 1) * mult for i = 0 to math.min(499,n - 1) if i%2 line.new(n-i+1, y1 + sae, n-i, nwe.get(i) + sae, color = upCss) line.new(n-i+1, y1 - sae, n-i, nwe.get(i) - sae, color = dnCss) if src[i] > nwe.get(i) + sae and src[i+1] < nwe.get(i) + sae label.new(n-i, src[i], '▼', color = color(na), style = label.style_label_down, textcolor = dnCss, textalign = text.align_center) if src[i] < nwe.get(i) - sae and src[i+1] > nwe.get(i) - sae label.new(n-i, src[i], '▲', color = color(na), style = label.style_label_up, textcolor = upCss, textalign = text.align_center) y1 := nwe.get(i) //-----------------------------------------------------------------------------} //Dashboard //-----------------------------------------------------------------------------{ var tb = table.new(position.top_right, 1, 1 , bgcolor = #1e222d , border_color = #373a46 , border_width = 1 , frame_color = #373a46 , frame_width = 1) if repaint tb.cell(0, 0, 'Repainting Mode Enabled', text_color = color.white, text_size = size.small) //-----------------------------------------------------------------------------} //Plot //-----------------------------------------------------------------------------} plot(repaint ? na : out + mae, 'Upper', upCss) plot(repaint ? na : out - mae, 'Lower', dnCss) //Crossing Arrows plotshape(ta.crossunder(close, out - mae) ? low : na, "Crossunder", shape.labelup, location.absolute, color(na), 0 , text = '▲', textcolor = upCss, size = size.tiny) plotshape(ta.crossover(close, out + mae) ? high : na, "Crossover", shape.labeldown, location.absolute, color(na), 0 , text = '▼', textcolor = dnCss, size = size.tiny) //-----------------------------------------------------------------------------}