예스스탁
예스스탁 답변
2025-08-06 15:01:38
안녕하세요
예스스탁입니다.
해당식 현재시점에서 과거로 500봉을 텍스트함수로 선을 그리게 됩니다.
봉수가 많으면 로드가 많이 걸리는 내용입니다.
차트에 1000봉 이하 조회하고 적용하시기 바랍니다.
5000봉에 그리시기 위해서는 수식내 499와 500으로 지정된 값을 4
999,5000으로 변경하시고 5000봉 이상 로드한 차트에 적용하시면 되지만
로드가 너무 많이 걸려 프로그램이 다운될수도 있습니다.
권장하지 않습니다.
input : hh(8),mult(3),src(close),upCss(Teal),dnCss(Red);
var : n(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);
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 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)
{
if (i%2 == 0) Then
{
uptx[i] = text_new(sDate[i],sTime[i],nwe[i]+sae,"-");
Text_SetColor(uptx[i],upcss);
dntx[i] = text_new(sDate[i],sTime[i],nwe[i]-sae,"-");
Text_SetColor(dntx[i],dncss);
if src[i] > nwe[i] + sae and src[i+1] < nwe[i] + sae Then
{
dntx1[i] = text_new(sDate[i],sTime[i],nwe[i]+sae,"▼");
Text_SetColor(dntx1[i],dncss);
}
if src[i] < nwe[i] - sae and src[i+1] > nwe[i] - sae Then
{
uptx1[i] = text_new(sDate[i],sTime[i],nwe[i]+sae,"▲");
Text_SetColor(uptx1[i],upcss);
}
}
y1 = nwe[i];
}
}
즐거운 하루되세요
> 해암 님이 쓴 글입니다.
> 제목 : 문의드립니다.
> 1.아래의 트레이딩뷰수식을 변환부탁드립니다.
2 위1번에서 차트는 과거봉 500개까지 밴드가 그려지는 것으로 보이는데, 과거봉 5000개까지 확장적용하려면 어떻게 해야 하는지요?
=====================
indicator("Nadaraya-Watson Envelope [LuxAlgo]", "LuxAlgo - Nadaraya-Watson Envelope", 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(1.6., 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(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)
//-----------------------------------------------------------------------------}
==================
매번 감사드립니다. 수고하세요!!!