커뮤니티

수식 문의드립니다.

프로필 이미지
cooparoo
2024-04-21 06:50:19
612
글번호 178766
답변완료
안녕하세요. 아래는 트레이딩뷰 소스코드입니다. 예스로 변환 부탁드립니다. 감사합니다. //@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) 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 endpoint of the estimator') //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 //-----------------------------------------------------------------------------} //Compute and display NWE //-----------------------------------------------------------------------------{ float y2 = na float y1 = na float y1_d = na line l = na label lb = na if barstate.islast and repaint //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 d = y2 - y1 //Set coordinate line l := array.get(ln,i) line.set_xy1(l,n-i+1,y1) line.set_xy2(l,n-i,y2) line.set_color(l,y2 > y1 ? dnCss : upCss) line.set_width(l,2) if d * y1_d < 0 label.new(n-i+1, src[i], y1_d < 0 ? '▲' : '▼' , color = color(na) , style = y1_d < 0 ? label.style_label_up : label.style_label_down , textcolor = y1_d < 0 ? upCss : dnCss , textalign = text.align_center) y1 := y2 y1_d := d //-----------------------------------------------------------------------------} //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, 'NWE Endpoint Estimator', out > out[1] ? upCss : dnCss) //-----------------------------------------------------------------------------}
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2024-04-22 14:51:14

안녕하세요 예스스탁입니다. 올려주신 수식은 repaint이 true이면 차트상 마지막봉의 값을 기준으로 과거봉에 다시 그리는 내용입니다. 예스랭귀지의 plot은 현재시점에서 과거봉에 그릴수가 없어서 텍스트 함수로 과거봉에 -표시로 출력하게 작성해 드립니다. 예스랭귀지의 구조가 차트 과거봉부터 현재봉으로 오면서 그리게 되어 매봉 과거 500봉에 대해 그리고 지우기를 반복하게 되므로 차트에 조회된 봉이 많으면 적용 후 로드가 심해 프로그램이 다운될수도 있습니다. 차트의 조회봉수를 가급적 500봉 이상 1000봉 이하 정도로 조회해서 적용하시기 바랍니다. input : hh(8),repaint(true),upCss(Teal),dnCss(Red); var : src(0),n(0),i(0),w(0),den(0),out(0); Array : ln[500](0),coefs[500](0); Array : tx[500](0),tx1[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; var : y2(0),y1(0),d(0),y1_d(0),ll(0); var : j(0),sum(0),sumw(0); if Index >= 500 and repaint == true Then { for i = 0 to min(499,n - 1) { Text_Delete(tx[i]); Text_Delete(tx1[i]); } 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; d = y1-y2; ll = ln[i]; tx[i] = text_new(sDate[i],sTime[i],y2,"-"); Text_SetColor(tx[i],IFF(y2 > y1,dnCss,upCss)); Text_SetStyle(tx[i],2,2); if d*y1_d < 0 Then { if y1_d < 0 Then { tx1[i] = text_new(sDate[i-1],sTime[i-1],H[i-1],"▼"); Text_SetColor(tx1[i],dncss); Text_SetStyle(tx1[i],2,1); } Else { tx1[i] = text_new(sDate[i-1],sTime[i-1],L[i-1],"▲"); Text_SetColor(tx1[i],upcss); Text_SetStyle(tx1[i],2,0); } } y1 = y2; y1_d = d; } } if repaint == False Then Plot1(out,"NWE Endpoint Estimator"); Else NoPlot(1); 즐거운 하루되세요 > 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) 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 endpoint of the estimator') //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 //-----------------------------------------------------------------------------} //Compute and display NWE //-----------------------------------------------------------------------------{ float y2 = na float y1 = na float y1_d = na line l = na label lb = na if barstate.islast and repaint //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 d = y2 - y1 //Set coordinate line l := array.get(ln,i) line.set_xy1(l,n-i+1,y1) line.set_xy2(l,n-i,y2) line.set_color(l,y2 > y1 ? dnCss : upCss) line.set_width(l,2) if d * y1_d < 0 label.new(n-i+1, src[i], y1_d < 0 ? '▲' : '▼' , color = color(na) , style = y1_d < 0 ? label.style_label_up : label.style_label_down , textcolor = y1_d < 0 ? upCss : dnCss , textalign = text.align_center) y1 := y2 y1_d := d //-----------------------------------------------------------------------------} //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, 'NWE Endpoint Estimator', out > out[1] ? upCss : dnCss) //-----------------------------------------------------------------------------}