OPEN-SOURCE SCRIPT

Nadaraya-supertrend [MehmetaliAkdag]

By MehmetaliAkdag
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org/MPL/2.0/
// © MehmetaliAkdag



//version=5
indicator("Nadaraya-supertrend [MehmetaliAkdag]", "MehmetaliAkdag - Nadaraya-super trend ", 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 * 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 - 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 > nwe.get(i) + sae and src[i+1] < nwe.get(i) + sae
label.new(n-i, src, '▼', color = color(na), style = label.style_label_down, textcolor = dnCss, textalign = text.align_center)
if src < nwe.get(i) - sae and src[i+1] > nwe.get(i) - sae
label.new(n-i, src, '▲', 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)

//-----------------------------------------------------------------------------}


// SuperTrend
factor = input.float(3, "Atr Çarpanı", group = "SuperTrend")
AtrPeriod = input.int(10, "ATR Period", group = "SuperTrend")

// Periyotlar
P1 = input.timeframe("1", "1. Periyot", group = "Periyotlar")
P2 = input.timeframe("3", "2. Periyot", group = "Periyotlar")
P3 = input.timeframe("5", "3. Periyot", group = "Periyotlar")
P4 = input.timeframe("15", "4. Periyot", group = "Periyotlar")
P5 = input.timeframe("30", "5. Periyot", group = "Periyotlar")
P6 = input.timeframe("60", "6. Periyot", group = "Periyotlar")
P7 = input.timeframe("120", "7. Periyot", group = "Periyotlar")
P8 = input.timeframe("240", "8. Periyot", group = "Periyotlar")
P9 = input.timeframe("D", "9. Periyot", group = "Periyotlar")
P10 = input.timeframe("W", "10. Periyot", group = "Periyotlar")

// MTF Fonksiyonu (Multi Time Frame)
SuperTrendMTF(periyot)=>

// Trend değişkeni boş olarak ekle
int trend = na

// Periyotlardan SuperTrend değerlerini iste
[supertrend, direction] = request.security(syminfo.tickerid, periyot, ta.supertrend(factor, AtrPeriod))

// Gelen değerlere göre trendi belirle.
if direction < 0
trend := 1 // Yükselen Trend
if direction > 0
trend := 0 // Düşen Trend

// Hesaplanama sonucu trend değerini fonksiyonun sonucu olarak ver
trend

// Periyotlardan verileri iste
periyot1 = SuperTrendMTF(P1)
periyot2 = SuperTrendMTF(P2)
periyot3 = SuperTrendMTF(P3)
periyot4 = SuperTrendMTF(P4)
periyot5 = SuperTrendMTF(P5)
periyot6 = SuperTrendMTF(P6)
periyot7 = SuperTrendMTF(P7)
periyot8 = SuperTrendMTF(P8)
periyot9 = SuperTrendMTF(P9)
periyot10 = SuperTrendMTF(P10)

// Tabloyu oluştur ve verileri grafikte göster
var table stTablo = table.new(position.top_right, 1, 11, bgcolor = color.blue)

if barstate.islast
table.cell(stTablo, 0, 0, "SuperTrend MTF", text_color = color.white)

table.cell(stTablo, 0, 1, str.tostring(P1), text_color = color.white, bgcolor = periyot1 == 1 ? color.green : color.red)
table.cell(stTablo, 0, 2, str.tostring(P2), text_color = color.white, bgcolor = periyot2 == 1 ? color.green : color.red)
table.cell(stTablo, 0, 3, str.tostring(P3), text_color = color.white, bgcolor = periyot3 == 1 ? color.green : color.red)
table.cell(stTablo, 0, 4, str.tostring(P4), text_color = color.white, bgcolor = periyot4 == 1 ? color.green : color.red)
table.cell(stTablo, 0, 5, str.tostring(P5), text_color = color.white, bgcolor = periyot5 == 1 ? color.green : color.red)
table.cell(stTablo, 0, 6, str.tostring(P6), text_color = color.white, bgcolor = periyot6 == 1 ? color.green : color.red)
table.cell(stTablo, 0, 7, str.tostring(P7), text_color = color.white, bgcolor = periyot7 == 1 ? color.green : color.red)
table.cell(stTablo, 0, 8, str.tostring(P8), text_color = color.white, bgcolor = periyot8 == 1 ? color.green : color.red)
table.cell(stTablo, 0, 9, str.tostring(P9), text_color = color.white, bgcolor = periyot9 == 1 ? color.green : color.red)
table.cell(stTablo, 0, 10, str.tostring(P10), text_color = color.white, bgcolor = periyot10 == 1 ? color.green : color.red)


// SuperTrend'i mevcut periyot için grafikte göster
[supertrend, direction] = ta.supertrend(factor, AtrPeriod)
plot(direction < 0 ? supertrend : na, "Yükselen Trend", color = color.green, style=plot.style_linebr)
plot(direction > 0 ? supertrend : na, "Düşen Trend", color = color.red, style=plot.style_linebr)








multitimeframePine utilitiesTrend Analysis
MehmetaliAkdag

نص برمجي مفتوح المصدر

قام مؤلف هذا النص البرمجي بنشره وجعله مفتوح المصدر، بحيث يمكن للمتداولين فهمه والتحقق منه، وهو الأمر الذي يدخل ضمن قيم TradingView. تحياتنا للمؤلف! يمكنك استخدامه مجانًا، ولكن إعادة استخدام هذا الرمز في المنشور يخضع لقواعد‎‎قوانين الموقع. يمكنك جعله مفضلاً لاستخدامه على الرسم البياني.

هل تريد استخدام هذا النص البرمجي على الرسم البياني؟

إخلاء المسؤولية