Tekrar geçmiş olsun. Allah acil şifalar versin size ve babanıza...
T671H cihazımdan Tapatalk kullanılarak gönderildi
Printable View
üçün ikili kombinasyonu ile hazırlanmış...
döngüsel kalıba....
https://i.hizliresim.com/rt0mk6n.png
https://i.hizliresim.com/7oj30u9.png
https://i.hizliresim.com/7lojjld.png
https://i.hizliresim.com/7dn98ko.png
https://i.hizliresim.com/tbn4gni.png
https://i.hizliresim.com/rcgcncq.png
permütasyon (tercihiniz) bakılıp...
https://i.hizliresim.com/grthdxv.png
https://i.hizliresim.com/rdaoqc3.png
https://i.hizliresim.com/hdt5csu.png
https://i.hizliresim.com/6wjuorb.png
https://i.hizliresim.com/k55tfwf.png
https://i.hizliresim.com/m50b269.png
kıyaslarsanız(tercihinizle).....
https://i.hizliresim.com/ac68vg3.png
https://i.hizliresim.com/omctefp.png
https://i.hizliresim.com/f8a3gg3.png
https://i.hizliresim.com/81x6l2i.png
https://i.hizliresim.com/8riss94.png
https://i.hizliresim.com/2ee8i66.png
böyle görüntüler ortaya çıkar....
hazır kalıp şeklinde döngüseller...
https://tr.tradingview.com/script/yJ...-By-Leviathan/
bu kodla...sadeleştirme şartıyla...90 adet veriyi...istediğiniz periyottta....kodun içindeki hesaplamar ile taratabilirsiniz....
x100 e uyarlandığında örnek...
https://www.tradingview.com/x/zXb7P0Sk/
yörük döngüsel analiz....
aynı kodun...üç farklı değerle döngülenmesine örnektir....
kod 1...
tema üstsel hareketli ortalama...
5-20-50 değerini kullanınca ortaya çıkan görüntü.....
https://www.tradingview.com/x/hizPLo9h/
buna mtf yapınca...yani saatlik çağırınca...görüntü bu....
https://www.tradingview.com/x/h2gNbIAS/
döngüsel analize ekleyince.....
https://www.tradingview.com/x/OXdrlCaP/
saatlik bakınca....https://www.tradingview.com/x/6LQGoKvA/
döngüsel analize kıyas yapınca....
https://www.tradingview.com/x/RC2MPnx3/ saatlik...
https://www.tradingview.com/x/jp3PbcCW/
https://www.tradingview.com/x/Pe4JmIAA/
https://www.tradingview.com/x/Ov2lDMLP/
görüntüler böyle oluyor...
yörük döngüsel analiz....
tek kodun farklı değerlerinin döngülenmesine örnektir....
kanal olarak bolinger seçildi....
kod 2
bolinger normal görünüm....https://www.tradingview.com/x/VxjCaUoK/
günlükten saate mtf olursa....https://www.tradingview.com/x/GNLpwXef/
saatlik günlüğe mtf olursa...https://www.tradingview.com/x/D2GZB1Rv/
döngüsel analize eklenseydi....
https://www.tradingview.com/x/3QU50dAw/ günlüğü
saatliği.... https://www.tradingview.com/x/VIT7UAui/
kıyası yapılsaydı...
https://www.tradingview.com/x/hTy7DTsa/
https://www.tradingview.com/x/0Aei4jhX/
https://www.tradingview.com/x/M3v1VyP6/
https://www.tradingview.com/x/KsciyXCj/
görüntüler böyle oluyor...
x100 döngüsellik...
https://www.tradingview.com/x/5PHpwdzT/
https://www.tradingview.com/x/Ui645spa/
https://www.tradingview.com/x/U8j2yf3F/
https://www.tradingview.com/x/ZYLZj9dL/
saatlik uv...kırmamalı...
kırarsa seanslık kv kırılır...
Sayın Yörük merhaba, tradingview platformuna bir indikator yüklemek istiyorum, yardımcı olabilir misiniz uygun bir vaktinizde?
Sayın yörük özel mesaj gönderemiyorum..
Aşağıda.
Matriks'ten Tradingview'e Çeviren = @Hassonya - Hayrını görün*
//@version=5
indicator("Komut dosyam", overlay = true)
src = input(hlc3, title="Source")
highlight = input(true, title="Highlighting?")
showSignals = input(true, title="Show Signals?")
Q1 = input.int(3, title="Q1")
Q2 = input.float(0.8, title="Q2")
Q3 = Q2/100
Q4 = ta.ema(src, Q1)
Q5 = 0.0
Q5 := (Q4*(1-Q3))>nz(Q5[1],0) ? Q4*(1-Q3) : (Q4*(1+Q3))<nz(Q5[1],0) ? Q4*(1+Q3) : nz(Q5[1],0)
Z1 = input.int(3, title="Z1")
Z2 = input.float(1.23, title="Z2")
Z3 = Z2/100
Z4 = ta.ema(src, Z1)
Z5 = 0.0
Z5 := (Z4*(1-Z3))>nz(Z5[1],0) ? Z4*(1-Z3) : (Z4*(1+Z3))<nz(Z5[1],0) ? Z4*(1+Z3) : nz(Z5[1],0)
BuySignal = ta.crossover(Q5,Z5)
SellSignal = ta.crossunder(Q5,Z5)
Q5pl=plot(int(Q5/0.025+0.50)*0.025, color=color.green, linewidth=2)
Z5pl=plot(int(Z5/0.025+0.50)*0.025, color=color.red, linewidth=2)
fill(Q5pl,Z5pl, color= highlight ? Q5>Z5 ? color.new(color.green,50) : color.new(color.red,50) : na)
plotshape(showSignals and BuySignal, title="Buy Signal", style=shape.labelup, text="Buy", textcolor=color.white, color=color.green, location=location.belowbar)
plotshape(showSignals and SellSignal, title="Sell Signal", style=shape.labeldown, text="Sell", textcolor=color.white, color=color.red, location=location.abovebar)
özel mesajım kapalı....
gönderdiğin kod.... görüntüleri...
https://www.tradingview.com/x/5P5x6RY6/
https://www.tradingview.com/x/ealtsbFX/
Evet aldığım yerdeki görüntülerle tutarlı.
Ben ne yapacağım ? Pine editor üzerinden birşeyler yapmak lazım sanırım.
https://www.tradingview.com/x/VWsZ1sB7/ örneğin bu teyit olarak kullanılabilir....
sarı trend üstü al...altı sat....
aynı zamanda...kırılımlar ve dirençler gözükür ...
Ben bu göstergeyi tradingview'da kullanmak istiyorum. Yani ekranda sizinki gibi görmek istiyorum. Tanımlı değil bende. Kodu bir forumdan aldım.
Ne yapmam gerekiyor acaba?
eğer döngüleme yapalım dersek...
ne istediğimizi tam tanımlamamız gerekir...
örneğin bu kodu....1-5-15-60 için döngüleyip...
3 dakikalık periyodunu esas alıp...
1 dakkalık periyoda uygulama gibi....
kodu kopyala...pine editorde aç....kaydet....scriptlerimde...PHP Code:
//yörükten...başkaraya selamlarla......
//@version=5
indicator("Başkara", overlay = true)
src = input(hlc3, title="Source")
highlight = input(true, title="Highlighting?")
showSignals = input(true, title="Show Signals?")
Q1 = input.int(3, title="Q1")
Q2 = input.float(0.8, title="Q2")
Q3 = Q2/100
Q4 = ta.ema(src, Q1)
Q5 = 0.0
Q5 := (Q4*(1-Q3))>nz(Q5[1],0) ? Q4*(1-Q3) : (Q4*(1+Q3))<nz(Q5[1],0) ? Q4*(1+Q3) : nz(Q5[1],0)
Z1 = input.int(3, title="Z1")
Z2 = input.float(1.23, title="Z2")
Z3 = Z2/100
Z4 = ta.ema(src, Z1)
Z5 = 0.0
Z5 := (Z4*(1-Z3))>nz(Z5[1],0) ? Z4*(1-Z3) : (Z4*(1+Z3))<nz(Z5[1],0) ? Z4*(1+Z3) : nz(Z5[1],0)
BuySignal = ta.crossover(Q5,Z5)
SellSignal = ta.crossunder(Q5,Z5)
Q5pl=plot(int(Q5/0.025+0.50)*0.025, color=color.green, linewidth=1)
Z5pl=plot(int(Z5/0.025+0.50)*0.025, color=color.red, linewidth=1)
fill(Q5pl,Z5pl, color= highlight ? Q5>Z5 ? color.new(color.green,50) : color.new(color.red,50) : na)
plotshape(showSignals and BuySignal, title="Buy Signal", style=shape.labelup, text="Al", textcolor=color.white, color=color.green, location=location.belowbar)
plotshape(showSignals and SellSignal, title="Sell Signal", style=shape.labeldown, text="SAT", textcolor=color.white, color=color.red, location=location.abovebar)
başkara ismiyle gözükecek...
bu arada koda şöyle bakınca...düşük periyotlarda kullanmak mantıklı...
eğer viopta...h- h4 veya gün periyotlarında kullanılacak olursa...
kodun içindeki hesaplmalarda...
0.025 ile 0.50 kısmında kullanacağınız periyoda göre....
bir dip ayarlaması yapmanızı tavsiye ederim...
ya da ayarlardan kullanırken....
kırmızı çizgi için x100de değer 1.23 değil....3.23 yapılırsa...dip olasılığı yakalıyor gibi...
https://www.tradingview.com/x/qbE2V6AS/ örnek bu...
tabiki bu durumda küçük periyoda indirgerseniz....
https://www.tradingview.com/x/0HKPb9yM/ görüntü böyle olur...
kullanacağınız periyot önemli....
o periyoda göre gereksiz sinyaller azaltılmış olur ki.....
en güzeli 1 dakkalık periyotta kullanmak olur...
Çok teşekkür ederim. Casaubon hocanın yıllardır kullandğı indikatör aslında.. İsmini öyle değiştridim:)
teknikle ilgilenen arkadaşlar.....
teknik tasarım...sistem ya da vb.....
ilk olarak....yatırım yapacağınız süreyi belirleyin.... diyelim ki...3 aylık periyotlar olsun...
ikinci olarak.....kullanacağınız grafiğin periyodunu belirleyin.... diyelim ki saatlik olsun...
üçüncü olarak....döngü tasarlayın.... yazdığım gibi hareket edecek kişi....
döngüsüne h-h4 ve gün hesaplatıp.... döngü kullanmalı....
son olarak ise...
en iyi kullandığınız...indikatör v.b neyse...
onun verisini alarak....döngüyü başlatın ve strateji...sinyali ona göre ayarlayın....
örneğin bu görüntü....
başkara hocam ile benim döngünün beraber hali....
https://www.tradingview.com/x/Yn7Xo3Un/
eğer ben başkaranın kodunu döngüye alsaydım....
görüntü.....https://www.tradingview.com/x/rNzSZkrR/
https://www.tradingview.com/x/IdmqF49E/
https://www.tradingview.com/x/VOsZemA9/
https://www.tradingview.com/x/wajUAKim/
başkara hocanın kod değerlerinde oynanması ve volalite trend ile ilişkilendirilmesi sonucu ortaya çıkan görüntü....
kombine edilmiş kod...denemek isteyenlere...
değerler oynandığı için....PHP Code:
//yörükten...başkaraya selamlarla......
//@version=5
indicator("Başkara", overlay = true)
src = input(hlc3, title="Source")
highlight = input(true, title="Highlighting?")
showSignals = input(true, title="Show Signals?")
Q1 = input.int(1, title="Q1")
Q2 = input.float(1, title="Q2")
Q3 = Q2/100
Q4 = ta.ema(src, Q1)
Q5 = 0.0
Q5 := (Q4*(1-Q3))>nz(Q5[1],0) ? Q4*(1-Q3) : (Q4*(1+Q3))<nz(Q5[1],0) ? Q4*(1+Q3) : nz(Q5[1],0)
Z1 = input.int(5, title="Z1")
Z2 = input.float(5, title="Z2")
Z3 = Z2/100
Z4 = ta.ema(src, Z1)
Z5 = 0.0
Z5 := (Z4*(1-Z3))>nz(Z5[1],0) ? Z4*(1-Z3) : (Z4*(1+Z3))<nz(Z5[1],0) ? Z4*(1+Z3) : nz(Z5[1],0)
BuySignal = ta.crossover(Q5,Z5)
SellSignal = ta.crossunder(Q5,Z5)
Q5pl=plot(int(Q5/1.025+1.50)*1.025, color=color.green, linewidth=1,title="Direnç")
Z5pl=plot(int(Z5/1.025+1.50)*1.025, color=color.red, linewidth=1,title="Destek")
//fill(Q5pl,Z5pl, color= highlight ? Q5>Z5 ? color.new(color.green,50) : color.new(color.red,50) : na)
plotshape(showSignals and BuySignal, title="Buy Signal", style=shape.labelup, text="AL", textcolor=color.white, color=color.green, location=location.belowbar)
plotshape(showSignals and SellSignal, title="Sell Signal", style=shape.labeldown, text="SAT", textcolor=color.white, color=color.red, location=location.abovebar)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ ToolTips {
t1 = "Volatility Period defines the length of the look-back period for calculating volatility. Higher values make the bands adapt more slowly to volatility changes. Lower values make them adapt more quickly."
t2 = "Trend Factor adjusts the sensitivity of the trend line to price movements. A higher value makes the trend line less sensitive and smoother. Lower values make it more sensitive and reactive to price changes."
t3 = "Trend Step controls how quickly the trend line adjusts to sudden price changes. Higher values cause slower adjustments, leading to smoother trend lines. Lower values result in quicker adjustments to sudden changes."
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Inputs {
volatilityPeriod = input.int(20, title="Period", step=10, minval=2, maxval=1000, inline="vol", group="Volatility Settings", tooltip=t1)
trendFactor = input.float(9, step=0.1, title='Factor', minval = 0.1, inline="", group="Trend Settings", tooltip=t2)
trendStep = input.float(1, "Step", step=0.1,minval = 0.5, maxval = 5.0, inline="", group="Trend Settings", tooltip=t3)
color_trend = input.color(color.rgb(209, 245, 3), title="Trend Line  ", inline="trend", group="Style")
colorForUpperBand = input.color(color.new(#862458, 10), title="Upper Band", inline="band", group="Style")
colorForLowerBand = input.color(color.new(#493893, 10), title="Lower Band", inline="band", group="Style")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Initialize Variables
var float currentTrend = 0.0
var int trendDirection = 0
averageTrueRange = ta.atr(200)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Function to determine the trend direction
determineTrendDirection(direction) => direction - direction[1] > 0 ? 1 : (direction - direction[1] < 0 ? -1 : 0)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate Trend Direction
closingPrice = close
scaledStandardDev = (nz(averageTrueRange) * trendFactor)
trendDirection := determineTrendDirection(currentTrend) * int(scaledStandardDev)
priceTrendDiff = closingPrice - currentTrend > 0 ? closingPrice - currentTrend : currentTrend - closingPrice
reciprocalFactor = (scaledStandardDev * (1 / trendFactor)) * 1 / math.pow(2, 100)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate the Current Trend
trendAdjustment = priceTrendDiff > scaledStandardDev * trendStep ? math.avg(closingPrice, currentTrend) : trendDirection * reciprocalFactor + currentTrend
currentTrend := trendAdjustment
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate Upper and Lower Bands
upperBand = currentTrend + scaledStandardDev - averageTrueRange - ta.ema(ta.stdev(closingPrice, volatilityPeriod), 200)
lowerBand = currentTrend - scaledStandardDev + averageTrueRange + ta.ema(ta.stdev(closingPrice, volatilityPeriod), 200)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Plot
isTrendConsistent = trendDirection == trendDirection[1]
colorForPlot = trendDirection == 1 ? color_trend : color_trend
plotTrend = plot(isTrendConsistent ? currentTrend : na, title="Trend ", color=colorForPlot)
plotUpper = plot(isTrendConsistent ? upperBand : na, title="Trend+", color = color.new(color.black, 100))
plotLower = plot(isTrendConsistent ? lowerBand : na, title="Trend-", color = color.new(color.black, 100))
fill(plotUpper, plotTrend, top_color = colorForLowerBand, bottom_color =color.new(na,100), top_value = upperBand, bottom_value = currentTrend, title="Background Upper")
fill(plotTrend, plotLower, top_color = color.new(na,100), bottom_color = colorForUpperBand, top_value = currentTrend, bottom_value = lowerBand, title="Background Lower")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
kısa periyotlar tercihi...1-5-15 dakkalık daha stabilite sonuçlar veriri....
sar trend hesaplaması ve 15 dakkalık periyoda göre bar renklendirme örneği....
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
//@version=5
indicator(".", overlay = true)
//Trend Sar
psar(start1, inc1, maximum1) =>
out1 = float(na)
isUpTrend1 = bool(na)
maxMin1 = float(na)
acc1 = float(na)
prev1 = float(na)
if bar_index >= 1
prev1 := out1[1]
if bar_index == 1
if close > close[1]
isUpTrend1 := true
maxMin1 := math.max(high, high[1])
prev1 := math.min(low, low[1])
prev1
else
isUpTrend1 := false
maxMin1 := math.min(low, low[1])
prev1 := math.max(high, high[1])
prev1
acc1 := start1
acc1
else
isUpTrend1 := isUpTrend1[1]
acc1 := acc1[1]
maxMin1 := maxMin1[1]
maxMin1
if isUpTrend1
if high > maxMin1
maxMin1 := high
acc1 := math.min(acc1 + inc1, maximum1)
acc1
else
if low < maxMin1
maxMin1 := low
acc1 := math.min(acc1 + inc1, maximum1)
acc1
if na(out1)
out1 := prev1 + acc1 * (maxMin1 - prev1)
out1
if isUpTrend1
if low <= out1
isUpTrend1 := false
out1 := maxMin1
maxMin1 := low
acc1 := start1
acc1
else
if high >= out1
isUpTrend1 := true
out1 := maxMin1
maxMin1 := high
acc1 := start1
acc1
if na(out1)
if isUpTrend1
out1 := math.min(out1, bar_index == 1 ? low[1] : math.min(low[1], low[2]))
out1
else
out1 := math.max(out1, bar_index == 1 ? high[1] : math.max(high[1], high[2]))
out1
[out1, acc1, maxMin1, isUpTrend1]
start1 = input(0)
increment1 = input(0.01)
maximum1 = input(0.02)
[p1, AF1, EP1, isUpTrend1] = psar(start1, increment1, maximum1)
newEP1 = EP1 != EP1[1]
epNew1 = newEP1 ? EP1 : na
plot(p1, 'STrend', style=plot.style_stepline, color=isUpTrend1 ? color.rgb(25, 248, 5, 100) : color.rgb(243, 5, 5, 100), linewidth=1)
plot(EP1, 'STrend Devam', style=plot.style_circles, color=isUpTrend1 ? color.rgb(25, 248, 5, 100) : color.rgb(243, 5, 5, 100), linewidth=2)
x1 = input.timeframe('15', title='Resolution')
z = ta.sar(0, 0.01, 0.02)
// Security
y1 = request.security(syminfo.tickerid, x1, z)
//Plots
xz = input(true, title='Adaptive Coloring')
//Functions Sar for support and resistance
q3 = ta.sar(0.001, 0.01, 0.1)
q2 = ta.sar(0.001, 0.03, 0.3)
q1 = ta.sar(0.001, 0.05, 0.5)
plot(q3, title='UV-Sar', style=plot.style_circles, color=xz ? y1 > close ? color.rgb(2, 250, 238) : color.rgb(250, 225, 3) : color.silver, linewidth=1)
plot(q2, title='OV-Sar', style=plot.style_circles, color=xz ? y1 > close ? color.rgb(2, 250, 238) : color.rgb(250, 225, 3) : color.silver, linewidth=1)
plot(q1, title='KV-Sar', style=plot.style_circles, color=xz ? y1 > close ? color.rgb(2, 250, 238) : color.rgb(250, 225, 3) : color.silver, linewidth=1)
//END
bcolor = ta.crossunder(close,q3) ? color.red : ta.crossover(close,q3) ? color.green: close>q2 ? color.green : close<q2 ? color.red: color.rgb(216, 4, 253) // : color.black
barcolor(bcolor)
belirleyeceğiniz üç adet sar değerini.....
dilediğiniz periyot için... hesaplar...
örnek...1dakkalık için.... 15 dakkalıkta görüntü... https://www.tradingview.com/x/HWs1Pr0O/
bu da kodu denemek isteyenlere....
PHP Code:
//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
indicator('*', overlay=true)
//resolution
x1 = input.timeframe('1', title='Resolution')
//output functions
z = ta.sar(0, 0.02, 0.02)
// Security
y1 = request.security(syminfo.tickerid, x1, z)
//Plots
xz = input(true, title='Adaptive Coloring')
//Functions Sar for support and resistance
q3 = ta.sar(0.01, 0.02, 0.2)
q2 = ta.sar(0.01, 0.04, 0.4)
q1 = ta.sar(0.01, 0.06, 0.6)
plot(q3, title='SlowSar', style=plot.style_circles, color=xz ? y1 > close ? color.red : color.lime : color.silver, linewidth=1)
plot(q2, title='AvgSar', style=plot.style_circles, color=xz ? y1 > close ? color.red : color.lime : color.silver, linewidth=1)
plot(q1, title='FastSar', style=plot.style_circles, color=xz ? y1 > close ? color.red : color.lime : color.silver, linewidth=1)
//Signal
xyzq = (y1)
plot(xyzq, title='Yörük', style=plot.style_linebr, color=xz ? y1 > close ? color.rgb(255, 82, 82, 00) : color.rgb(0, 230, 119, 00) : color.silver, linewidth=1)
yukardaki örnek...volalite tren ile ilşkilendiğinde.....
denemek isteyene örnek....
https://www.tradingview.com/x/Uu09kCfD/PHP Code:
//yörükten...başkaraya selamlarla......
//@version=5
indicator(".", overlay = true)
src = input(close, title="Source")
highlight = input(true, title="Highlighting?")
showSignals = input(true, title="Show Signals?")
Q1 = input.int(1, title="Q1")
Q2 = input.float(1, title="Q2")
Q3 = Q2/100
Q4 = ta.ema(src, Q1)
Q5 = 0.0
Q5 := (Q4*(1-Q3))>nz(Q5[1],0) ? Q4*(1-Q3) : (Q4*(1+Q3))<nz(Q5[1],0) ? Q4*(1+Q3) : nz(Q5[1],0)
Z1 = input.int(5, title="Z1")
Z2 = input.float(5, title="Z2")
Z3 = Z2/100
Z4 = ta.ema(src, Z1)
Z5 = 0.0
Z5 := (Z4*(1-Z3))>nz(Z5[1],0) ? Z4*(1-Z3) : (Z4*(1+Z3))<nz(Z5[1],0) ? Z4*(1+Z3) : nz(Z5[1],0)
BuySignal = ta.crossover(Q5,Z5)
SellSignal = ta.crossunder(Q5,Z5)
Q5pl=plot(int(Q5/1.025+1.50)*1.025, color=color.green, linewidth=1,title="Direnç")
Z5pl=plot(int(Z5/1.025+1.50)*1.025, color=color.red, linewidth=1,title="Destek")
//fill(Q5pl,Z5pl, color= highlight ? Q5>Z5 ? color.new(color.green,50) : color.new(color.red,50) : na)
plotshape(showSignals and BuySignal, title="Buy Signal", style=shape.labelup, text="AL", textcolor=color.white, color=color.green, location=location.belowbar)
plotshape(showSignals and SellSignal, title="Sell Signal", style=shape.labeldown, text="SAT", textcolor=color.white, color=color.red, location=location.abovebar)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ ToolTips {
t1 = "Volatility Period defines the length of the look-back period for calculating volatility. Higher values make the bands adapt more slowly to volatility changes. Lower values make them adapt more quickly."
t2 = "Trend Factor adjusts the sensitivity of the trend line to price movements. A higher value makes the trend line less sensitive and smoother. Lower values make it more sensitive and reactive to price changes."
t3 = "Trend Step controls how quickly the trend line adjusts to sudden price changes. Higher values cause slower adjustments, leading to smoother trend lines. Lower values result in quicker adjustments to sudden changes."
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Inputs {
volatilityPeriod = input.int(20, title="Period", step=10, minval=2, maxval=1000, inline="vol", group="Volatility Settings", tooltip=t1)
trendFactor = input.float(9, step=0.1, title='Factor', minval = 0.1, inline="", group="Trend Settings", tooltip=t2)
trendStep = input.float(1, "Step", step=0.1,minval = 0.5, maxval = 5.0, inline="", group="Trend Settings", tooltip=t3)
color_trend = input.color(color.rgb(209, 245, 3), title="Trend Line ", inline="trend", group="Style")
colorForUpperBand = input.color(color.new(#862458, 10), title="Upper Band", inline="band", group="Style")
colorForLowerBand = input.color(color.new(#493893, 10), title="Lower Band", inline="band", group="Style")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Initialize Variables
var float currentTrend = 0.0
var int trendDirection = 0
averageTrueRange = ta.atr(200)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Function to determine the trend direction
determineTrendDirection(direction) => direction - direction[1] > 0 ? 1 : (direction - direction[1] < 0 ? -1 : 0)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate Trend Direction
closingPrice = close
scaledStandardDev = (nz(averageTrueRange) * trendFactor)
trendDirection := determineTrendDirection(currentTrend) * int(scaledStandardDev)
priceTrendDiff = closingPrice - currentTrend > 0 ? closingPrice - currentTrend : currentTrend - closingPrice
reciprocalFactor = (scaledStandardDev * (1 / trendFactor)) * 1 / math.pow(2, 100)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate the Current Trend
trendAdjustment = priceTrendDiff > scaledStandardDev * trendStep ? math.avg(closingPrice, currentTrend) : trendDirection * reciprocalFactor + currentTrend
currentTrend := trendAdjustment
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate Upper and Lower Bands
upperBand = currentTrend + scaledStandardDev - averageTrueRange - ta.ema(ta.stdev(closingPrice, volatilityPeriod), 200)
lowerBand = currentTrend - scaledStandardDev + averageTrueRange + ta.ema(ta.stdev(closingPrice, volatilityPeriod), 200)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Plot
isTrendConsistent = trendDirection == trendDirection[1]
colorForPlot = trendDirection == 1 ? color_trend : color_trend
plotTrend = plot(isTrendConsistent ? currentTrend : na, title="VTrend ", color=colorForPlot)
plotUpper = plot(isTrendConsistent ? upperBand : na, title="VDirenç", color = color.new(color.black, 100))
plotLower = plot(isTrendConsistent ? lowerBand : na, title="VDestek", color = color.new(color.black, 100))
//fill(plotUpper, plotTrend, top_color = colorForLowerBand, bottom_color =color.new(na,100), top_value = upperBand, bottom_value = currentTrend, title="Background Upper")
//fill(plotTrend, plotLower, top_color = color.new(na,100), bottom_color = colorForUpperBand, top_value = currentTrend, bottom_value = lowerBand, title="Background Lower")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//Trend Sar
psar(start1, inc1, maximum1) =>
out1 = float(na)
isUpTrend1 = bool(na)
maxMin1 = float(na)
acc1 = float(na)
prev1 = float(na)
if bar_index >= 1
prev1 := out1[1]
if bar_index == 1
if close > close[1]
isUpTrend1 := true
maxMin1 := math.max(high, high[1])
prev1 := math.min(low, low[1])
prev1
else
isUpTrend1 := false
maxMin1 := math.min(low, low[1])
prev1 := math.max(high, high[1])
prev1
acc1 := start1
acc1
else
isUpTrend1 := isUpTrend1[1]
acc1 := acc1[1]
maxMin1 := maxMin1[1]
maxMin1
if isUpTrend1
if high > maxMin1
maxMin1 := high
acc1 := math.min(acc1 + inc1, maximum1)
acc1
else
if low < maxMin1
maxMin1 := low
acc1 := math.min(acc1 + inc1, maximum1)
acc1
if na(out1)
out1 := prev1 + acc1 * (maxMin1 - prev1)
out1
if isUpTrend1
if low <= out1
isUpTrend1 := false
out1 := maxMin1
maxMin1 := low
acc1 := start1
acc1
else
if high >= out1
isUpTrend1 := true
out1 := maxMin1
maxMin1 := high
acc1 := start1
acc1
if na(out1)
if isUpTrend1
out1 := math.min(out1, bar_index == 1 ? low[1] : math.min(low[1], low[2]))
out1
else
out1 := math.max(out1, bar_index == 1 ? high[1] : math.max(high[1], high[2]))
out1
[out1, acc1, maxMin1, isUpTrend1]
start1 = input(0)
increment1 = input(0.01)
maximum1 = input(0.02)
[p1, AF1, EP1, isUpTrend1] = psar(start1, increment1, maximum1)
newEP1 = EP1 != EP1[1]
epNew1 = newEP1 ? EP1 : na
plot(p1, 'STrend', style=plot.style_stepline, color=isUpTrend1 ? color.rgb(25, 248, 5, 100) : color.rgb(243, 5, 5, 100), linewidth=1)
plot(EP1, 'STrend Devam', style=plot.style_circles, color=isUpTrend1 ? color.rgb(25, 248, 5, 100) : color.rgb(243, 5, 5, 100), linewidth=2)
/// sar hesaplamasını 1 dakika üzerinden bar renlendirmesi....
x1 = input.timeframe('1', title='Periyot')
z = ta.sar(0, 0.02, 0.02)
y1 = request.security(syminfo.tickerid, x1, z)
xz = input(true, title='Renk')
//Functions Sar for support and resistance
q3 = ta.sar(0.01, 0.02, 0.2)
q2 = ta.sar(0.01, 0.04, 0.4)
q1 = ta.sar(0.01, 0.06, 0.6)
plot(q3, title='UVSar', style=plot.style_circles, color=xz ? y1 > close ? color.red : color.lime : color.silver, linewidth=1)
plot(q2, title='OVSar', style=plot.style_circles, color=xz ? y1 > close ? color.red : color.lime : color.silver, linewidth=1)
plot(q1, title='KVSar', style=plot.style_circles, color=xz ? y1 > close ? color.red : color.lime : color.silver, linewidth=1)
//Signal
xyzq = (y1)
plot(xyzq, title='Yörük', style=plot.style_linebr, color=xz ? y1 > close ? color.rgb(255, 82, 82, 00) : color.rgb(0, 230, 119, 00) : color.silver, linewidth=1)
bcolor = ta.crossunder(close,q3) ? color.red : ta.crossover(close,q3) ? color.green: close>q2 ? color.green : close<q2 ? color.red: color.rgb(216, 4, 253) // : color.black
barcolor(bcolor)
macd indikatörünü bir dakikalık fiyat olarak okutmaya örnek....
https://www.tradingview.com/x/RuLFSxpm/
denemek isteyene kodu....
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
//@version=5
indicator(".", overlay = true)
//Trend Sar
//END
//Function
inp = input(title='Source', defval=close)
res = input.timeframe(title='Resolution', defval='1')
rep = input(title='Allow Repainting?', defval=true)
//////////////////////////////////////////////////////
src1 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLength1 = input.int(title='FastLength', defval=12, minval=1)
slowLength1 = input.int(title='SlowLength', defval=26, minval=1)
signalLength1 = input.int(title='SignalLength', defval=9, minval=1)
macdLevel1 = input.float(title='MacdLevel', defval=0, minval=0)
fastAlpha1 = 2.0 / (1 + fastLength1)
slowAlpha1 = 2.0 / (1 + slowLength1)
fastEma1 = ta.ema(src1, fastLength1)
slowEma1 = ta.ema(src1, slowLength1)
pMacdEq1 = fastAlpha1 - slowAlpha1 != 0 ? ((nz(fastEma1[1]) * fastAlpha1) - (nz(slowEma1[1]) * slowAlpha1)) / (fastAlpha1 - slowAlpha1) : 0
pMacdEqSig1 = ta.ema(pMacdEq1, signalLength1)
pMacdLevel1 = fastAlpha1 - slowAlpha1 != 0 ? (macdLevel1 - (nz(fastEma1[1]) * (1 - fastAlpha1)) + (nz(slowEma1[1]) * (1 - slowAlpha1))) / (fastAlpha1 - slowAlpha1) : 0
slo1 = src1 - pMacdEq1
sig1 = slo1 > 0 ? slo1 > nz(slo1[1]) ? 2 : 1 : slo1 < 0 ? slo1 < nz(slo1[1]) ? -2 : -1 : 0
rmacdColor = sig1 > 1 ? color.lime : sig1 > 0 ? color.lime : sig1 < -1 ? color.red : sig1 < 0 ? color.red : color.white
plot(pMacdEq1, title='MacdTrend',style=plot.style_stepline, color=rmacdColor, linewidth=2)
plot(pMacdEqSig1, title='MacdStop', color=color.rgb(255, 255, 255, 00), linewidth=1)
///////////////////////////////////////////////////////////////////////////
üstte kalan volalite trend....sar trendin.... saatlik macd ile ilişkilendirilmesi örneği....
denemek isteyene kodu....https://www.tradingview.com/x/rahMPWrF/
PHP Code:
//yörükten...başkaraya selamlarla......
//@version=5
indicator(".", overlay = true)
src = input(close, title="Source")
highlight = input(true, title="Highlighting?")
showSignals = input(true, title="Show Signals?")
Q1 = input.int(1, title="Q1")
Q2 = input.float(1, title="Q2")
Q3 = Q2/100
Q4 = ta.ema(src, Q1)
Q5 = 0.0
Q5 := (Q4*(1-Q3))>nz(Q5[1],0) ? Q4*(1-Q3) : (Q4*(1+Q3))<nz(Q5[1],0) ? Q4*(1+Q3) : nz(Q5[1],0)
Z1 = input.int(5, title="Z1")
Z2 = input.float(5, title="Z2")
Z3 = Z2/100
Z4 = ta.ema(src, Z1)
Z5 = 0.0
Z5 := (Z4*(1-Z3))>nz(Z5[1],0) ? Z4*(1-Z3) : (Z4*(1+Z3))<nz(Z5[1],0) ? Z4*(1+Z3) : nz(Z5[1],0)
BuySignal = ta.crossover(Q5,Z5)
SellSignal = ta.crossunder(Q5,Z5)
Q5pl=plot(int(Q5/1.025+1.50)*1.025, color=color.green, linewidth=1,title="Direnç")
Z5pl=plot(int(Z5/1.025+1.50)*1.025, color=color.red, linewidth=1,title="Destek")
//fill(Q5pl,Z5pl, color= highlight ? Q5>Z5 ? color.new(color.green,50) : color.new(color.red,50) : na)
//plotshape(showSignals and BuySignal, title="Buy Signal", style=shape.labelup, text="AL", textcolor=color.white, color=color.green, location=location.belowbar)
//plotshape(showSignals and SellSignal, title="Sell Signal", style=shape.labeldown, text="SAT", textcolor=color.white, color=color.red, location=location.abovebar)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ ToolTips {
t1 = "Volatility Period defines the length of the look-back period for calculating volatility. Higher values make the bands adapt more slowly to volatility changes. Lower values make them adapt more quickly."
t2 = "Trend Factor adjusts the sensitivity of the trend line to price movements. A higher value makes the trend line less sensitive and smoother. Lower values make it more sensitive and reactive to price changes."
t3 = "Trend Step controls how quickly the trend line adjusts to sudden price changes. Higher values cause slower adjustments, leading to smoother trend lines. Lower values result in quicker adjustments to sudden changes."
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Inputs {
volatilityPeriod = input.int(20, title="Period", step=10, minval=2, maxval=1000, inline="vol", group="Volatility Settings", tooltip=t1)
trendFactor = input.float(9, step=0.1, title='Factor', minval = 0.1, inline="", group="Trend Settings", tooltip=t2)
trendStep = input.float(1, "Step", step=0.1,minval = 0.5, maxval = 5.0, inline="", group="Trend Settings", tooltip=t3)
color_trend = input.color(color.rgb(209, 245, 3), title="Trend Line  ", inline="trend", group="Style")
colorForUpperBand = input.color(color.new(#862458, 10), title="Upper Band", inline="band", group="Style")
colorForLowerBand = input.color(color.new(#493893, 10), title="Lower Band", inline="band", group="Style")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Initialize Variables
var float currentTrend = 0.0
var int trendDirection = 0
averageTrueRange = ta.atr(200)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Function to determine the trend direction
determineTrendDirection(direction) => direction - direction[1] > 0 ? 1 : (direction - direction[1] < 0 ? -1 : 0)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate Trend Direction
closingPrice = close
scaledStandardDev = (nz(averageTrueRange) * trendFactor)
trendDirection := determineTrendDirection(currentTrend) * int(scaledStandardDev)
priceTrendDiff = closingPrice - currentTrend > 0 ? closingPrice - currentTrend : currentTrend - closingPrice
reciprocalFactor = (scaledStandardDev * (1 / trendFactor)) * 1 / math.pow(2, 100)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate the Current Trend
trendAdjustment = priceTrendDiff > scaledStandardDev * trendStep ? math.avg(closingPrice, currentTrend) : trendDirection * reciprocalFactor + currentTrend
currentTrend := trendAdjustment
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate Upper and Lower Bands
upperBand = currentTrend + scaledStandardDev - averageTrueRange - ta.ema(ta.stdev(closingPrice, volatilityPeriod), 200)
lowerBand = currentTrend - scaledStandardDev + averageTrueRange + ta.ema(ta.stdev(closingPrice, volatilityPeriod), 200)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Plot
isTrendConsistent = trendDirection == trendDirection[1]
colorForPlot = trendDirection == 1 ? color_trend : color_trend
plotTrend = plot(isTrendConsistent ? currentTrend : na, title="VTrend ", color=colorForPlot)
plotUpper = plot(isTrendConsistent ? upperBand : na, title="VDirenç", color = color.new(color.black, 100))
plotLower = plot(isTrendConsistent ? lowerBand : na, title="VDestek", color = color.new(color.black, 100))
//fill(plotUpper, plotTrend, top_color = colorForLowerBand, bottom_color =color.new(na,100), top_value = upperBand, bottom_value = currentTrend, title="Background Upper")
//fill(plotTrend, plotLower, top_color = color.new(na,100), bottom_color = colorForUpperBand, top_value = currentTrend, bottom_value = lowerBand, title="Background Lower")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//Trend Sar
psar(start1, inc1, maximum1) =>
out1 = float(na)
isUpTrend1 = bool(na)
maxMin1 = float(na)
acc1 = float(na)
prev1 = float(na)
if bar_index >= 1
prev1 := out1[1]
if bar_index == 1
if close > close[1]
isUpTrend1 := true
maxMin1 := math.max(high, high[1])
prev1 := math.min(low, low[1])
prev1
else
isUpTrend1 := false
maxMin1 := math.min(low, low[1])
prev1 := math.max(high, high[1])
prev1
acc1 := start1
acc1
else
isUpTrend1 := isUpTrend1[1]
acc1 := acc1[1]
maxMin1 := maxMin1[1]
maxMin1
if isUpTrend1
if high > maxMin1
maxMin1 := high
acc1 := math.min(acc1 + inc1, maximum1)
acc1
else
if low < maxMin1
maxMin1 := low
acc1 := math.min(acc1 + inc1, maximum1)
acc1
if na(out1)
out1 := prev1 + acc1 * (maxMin1 - prev1)
out1
if isUpTrend1
if low <= out1
isUpTrend1 := false
out1 := maxMin1
maxMin1 := low
acc1 := start1
acc1
else
if high >= out1
isUpTrend1 := true
out1 := maxMin1
maxMin1 := high
acc1 := start1
acc1
if na(out1)
if isUpTrend1
out1 := math.min(out1, bar_index == 1 ? low[1] : math.min(low[1], low[2]))
out1
else
out1 := math.max(out1, bar_index == 1 ? high[1] : math.max(high[1], high[2]))
out1
[out1, acc1, maxMin1, isUpTrend1]
start1 = input(0)
increment1 = input(0.01)
maximum1 = input(0.02)
[p1, AF1, EP1, isUpTrend1] = psar(start1, increment1, maximum1)
newEP1 = EP1 != EP1[1]
epNew1 = newEP1 ? EP1 : na
plot(p1, 'STrend', style=plot.style_stepline, color=isUpTrend1 ? color.rgb(25, 248, 5, 100) : color.rgb(243, 5, 5, 100), linewidth=1)
plot(EP1, 'STrend Devam', style=plot.style_circles, color=isUpTrend1 ? color.rgb(25, 248, 5, 100) : color.rgb(243, 5, 5, 100), linewidth=2)
/// sar hesaplamasını 1 dakika üzerinden bar renlendirmesi....
x1 = input.timeframe('1', title='Periyot')
z = ta.sar(0, 0.02, 0.02)
y1 = request.security(syminfo.tickerid, x1, z)
xz = input(true, title='Renk')
//Functions Sar for support and resistance
q3 = ta.sar(0.01, 0.02, 0.2)
q2 = ta.sar(0.01, 0.04, 0.4)
q1 = ta.sar(0.01, 0.06, 0.6)
plot(q3, title='UVSar', style=plot.style_circles, color=xz ? y1 > close ? color.red : color.lime : color.silver, linewidth=1)
plot(q2, title='OVSar', style=plot.style_circles, color=xz ? y1 > close ? color.red : color.lime : color.silver, linewidth=1)
plot(q1, title='KVSar', style=plot.style_circles, color=xz ? y1 > close ? color.red : color.lime : color.silver, linewidth=1)
//Signal
xyzq = (y1)
plot(xyzq, title='Yörük', style=plot.style_linebr, color=xz ? y1 > close ? color.rgb(255, 82, 82, 00) : color.rgb(0, 230, 119, 00) : color.silver, linewidth=1)
bcolor = ta.crossunder(close,q3) ? color.red : ta.crossover(close,q3) ? color.green: close>q2 ? color.green : close<q2 ? color.red: color.rgb(216, 4, 253) // : color.black
barcolor(bcolor)
////
//Function
inp = input(title='Source', defval=close)
res = input.timeframe(title='Resolution', defval='60')
rep = input(title='Allow Repainting?', defval=true)
//////////////////////////////////////////////////////
src1 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLength1 = input.int(title='FastLength', defval=12, minval=1)
slowLength1 = input.int(title='SlowLength', defval=26, minval=1)
signalLength1 = input.int(title='SignalLength', defval=9, minval=1)
macdLevel1 = input.float(title='MacdLevel', defval=0, minval=0)
fastAlpha1 = 2.0 / (1 + fastLength1)
slowAlpha1 = 2.0 / (1 + slowLength1)
fastEma1 = ta.ema(src1, fastLength1)
slowEma1 = ta.ema(src1, slowLength1)
pMacdEq1 = fastAlpha1 - slowAlpha1 != 0 ? ((nz(fastEma1[1]) * fastAlpha1) - (nz(slowEma1[1]) * slowAlpha1)) / (fastAlpha1 - slowAlpha1) : 0
pMacdEqSig1 = ta.ema(pMacdEq1, signalLength1)
pMacdLevel1 = fastAlpha1 - slowAlpha1 != 0 ? (macdLevel1 - (nz(fastEma1[1]) * (1 - fastAlpha1)) + (nz(slowEma1[1]) * (1 - slowAlpha1))) / (fastAlpha1 - slowAlpha1) : 0
slo1 = src1 - pMacdEq1
sig1 = slo1 > 0 ? slo1 > nz(slo1[1]) ? 2 : 1 : slo1 < 0 ? slo1 < nz(slo1[1]) ? -2 : -1 : 0
rmacdColor = sig1 > 1 ? color.rgb(0, 230, 119, 100) : sig1 > 0 ? color.rgb(0, 230, 119, 100) : sig1 < -1 ? color.rgb(255, 82, 82, 100) : sig1 < 0 ? color.rgb(255, 82, 82, 100) : color.white
plot(pMacdEq1, title='MacdTrend',style=plot.style_stepline, color=rmacdColor, linewidth=2)
plot(pMacdEqSig1, title='MacdStop', color=color.rgb(255, 255, 255, 100), linewidth=1)
///////////////////////////////////////////////////////////////////////////
aynı periyotlu....farklı değerli....2 psarı....döngüleme örneği....
denemek isteyene kod....
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
//@version=5
indicator("Sar döngü", overlay = true)
//END
//Function Sar; slow-avarage-fast
lenxc20 = input(1)
lenxc50 = input(1)
z20(close, lenxc20) =>
hcx20 = 0.0
dxc20 = 0.0
for i = 0 to lenxc20 - 1 by 1
kxc20 = (lenxc20 - i) * lenxc20
hcx20 += kxc20
dxc20 += close[i] * kxc20
dxc20
dxc20 / hcx20
cxc20 = z20(close, math.floor(math.sqrt(lenxc20)))
//
z50(close, lenxc50) =>
hxc50 = 0.0
dxc50 = 0.0
for i = 0 to lenxc50 - 1 by 1
kxc50 = (lenxc50 - i) * lenxc50
hxc50 += kxc50
dxc50 += close[i] * kxc50
dxc50
dxc50 / hxc50
cxc50 = z50(close, math.floor(math.sqrt(lenxc50)))
//
//
startsx20 = 0.1
incrementsx20 = 0.1
maximumsx20 = 0.1
ssx20 = ta.sar(startsx20, incrementsx20, maximumsx20)
s1sx20 = z20(ssx20, lenxc20)
pcsx20 = close < s1sx20 ? color.rgb(255, 82, 82, 00) : color.rgb(76, 175, 79, 00)
plot(s1sx20, title="SAR Slow",style=plot.style_line, color=pcsx20, linewidth=1)
startsx50 = 0
incrementsx50 = 0.1
maximumsx50 = 1
ssx50 = ta.sar(startsx50, incrementsx50, maximumsx50)
s1sx50 = z50(ssx50, lenxc50)
pcsx50 = close < s1sx50 ? color.rgb(255, 82, 82, 00) : color.rgb(76, 175, 79, 00)
plot(s1sx50, title="SAR Fast",style=plot.style_line, color=pcsx50, linewidth=1)
kırılımları görmek isteyenler için örnek deneme kodu.... dilediğiniz değerleri değiştirirn...
https://www.tradingview.com/x/446MwYrJ/PHP Code:
//@version=5
indicator(".", overlay = true)
//Stop Function
mult156 = input.float(3, 'Multiplicative Factor', minval = 0)
slope156 = input.float(100, 'Slope', minval = 0)
width156 = input.float(100, 'Width %', minval = 0, maxval = 100) / 100
//Style
bullCss156 = input.color(color.lime, 'Average Color', inline = 'avg', group = 'Style')
bearCss156 = input.color(color.red, '' , inline = 'avg', group = 'Style')
//Calculation
//-----------------------------------------------------------------------------{
var float upper156 = na
var float lower156 = na
var float avg156 = close
var hold156 = 0.
var os156 = 1.
atr156 = nz(ta.atr(200)) * mult156
avg156 := math.abs(close - avg156) > atr156 ?
math.avg(close, avg156)
: avg156 + os156 * (hold156 / mult156 / slope156)
os156 := math.sign(avg156 - avg156[1])
hold156 := os156 != os156[1] ? atr156 : hold156
upper156 := avg156 + width156 * hold156
lower156 := avg156 - width156 * hold156
css156 = os156 == 1 ? bullCss156 : bearCss156
plot_avg156 = plot(avg156, 'Kırılım', os156 != os156[1] ? na : css156, style=plot.style_line,linewidth = 4)
//END
hoşuma giden kodları kombine edip....sinyal çizgilerini kapatıp...ortalamasını aldım...fuşya renginde....
sonra ema 1-10-20-50-100-200 alıp....ortalamasını hesapladım...sarı çizgi......
sinyalleme size kalmıştır.....denemek isteyene örnek kod.....
örnek görüntü...https://www.tradingview.com/x/5z6zMpEL/PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
//@version=5
indicator('SCA', max_bars_back=100, overlay=true)
//Time period
inp = input(title='Source', defval=close)
res = input.timeframe(title='Resolution', defval='')
rep = input(title='Allow Repainting?', defval=false)
//
src1 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLength1 = input.int(title='FastLength', defval=12, minval=1)
slowLength1 = input.int(title='SlowLength', defval=26, minval=1)
signalLength1 = input.int(title='SignalLength', defval=9, minval=1)
macdLevel1 = input.float(title='MacdLevel', defval=0, minval=0)
fastAlpha1 = 2.0 / (1 + fastLength1)
slowAlpha1 = 2.0 / (1 + slowLength1)
fastEma1 = ta.ema(src1, fastLength1)
slowEma1 = ta.ema(src1, slowLength1)
pMacdEq1 = fastAlpha1 - slowAlpha1 != 0 ? ((nz(fastEma1[1]) * fastAlpha1) - (nz(slowEma1[1]) * slowAlpha1)) / (fastAlpha1 - slowAlpha1) : 0
pMacdEqSig1 = ta.ema(pMacdEq1, signalLength1)
pMacdLevel1 = fastAlpha1 - slowAlpha1 != 0 ? (macdLevel1 - (nz(fastEma1[1]) * (1 - fastAlpha1)) + (nz(slowEma1[1]) * (1 - slowAlpha1))) / (fastAlpha1 - slowAlpha1) : 0
slo1 = src1 - pMacdEq1
sig1 = slo1 > 0 ? slo1 > nz(slo1[1]) ? 2 : 1 : slo1 < 0 ? slo1 < nz(slo1[1]) ? -2 : -1 : 0
rmacdColor = sig1 > 1 ? color.lime : sig1 > 0 ? color.lime : sig1 < -1 ? color.red : sig1 < 0 ? color.red : color.white
//plot(pMacdEq1, title='Trend Continue',style=plot.style_cross, color=rmacdColor, linewidth=2)
//plot(pMacdEqSig1, title='MacdEqSignal', color=color.rgb(255, 255, 255, 100), linewidth=1)
//plot(pMacdLevel1, title='MacdLevel', color=color.blue, linewidth=2)
xyz1=(pMacdEq1+pMacdEqSig1+pMacdLevel1)/3
//plot(xyz11, title='Avarage', color=color.rgb(241, 225, 8, 100), linewidth=2)
//
src25 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLimit25 = input.float(title='FastLimit', defval=0.2, minval=0.01, step=0.01)
slowLimit25 = input.float(title='SlowLimit', defval=0.02, minval=0.01, step=0.01)
pi25 = 2 * math.asin(1)
period25 = 0.0
smooth25 = (4 * src25 + 3 * nz(src25[1]) + 2 * nz(src25[2]) + nz(src25[3])) / 10
detrender25 = (0.0962 * smooth25 + 0.5769 * nz(smooth25[2]) - 0.5769 * nz(smooth25[4]) - 0.0962 * nz(smooth25[6])) * (0.075 * nz(period25[1]) + 0.54)
q125 = (0.0962 * detrender25 + 0.5769 * nz(detrender25[2]) - 0.5769 * nz(detrender25[4]) - 0.0962 * nz(detrender25[6])) * (0.075 * nz(period25[1]) + 0.54)
i125 = nz(detrender25[3])
jI25 = (0.0962 * i125 + 0.5769 * nz(i125[2]) - 0.5769 * nz(i125[4]) - 0.0962 * nz(i125[6])) * (0.075 * nz(period25[1]) + 0.54)
jQ25 = (0.0962 * q125 + 0.5769 * nz(q125[2]) - 0.5769 * nz(q125[4]) - 0.0962 * nz(q125[6])) * (0.075 * nz(period25[1]) + 0.54)
i225 = i125 - jQ25
i225 := 0.2 * i225 + 0.8 * nz(i225[1])
q225 = q125 + jI25
q225 := 0.2 * q225 + 0.8 * nz(q225[1])
re25 = i225 * nz(i225[1]) + q225 * nz(q225[1])
re25 := 0.2 * re25 + 0.8 * nz(re25[1])
im25 = i225 * nz(q225[1]) - q225 * nz(i225[1])
im25 := 0.2 * im25 + 0.8 * nz(im25[1])
period25 := im25 != 0 and re25 != 0 ? 2 * pi25 / math.atan(im25 / re25) : 0
period25 := math.min(math.max(period25, 0.67 * nz(period25[1])), 1.5 * nz(period25[1]))
period25 := math.min(math.max(period25, 6), 50)
period25 := 0.2 * period25 + 0.8 * nz(period25[1])
smoothPeriod25 = 0.0
smoothPeriod25 := 0.33 * period25 + 0.67 * nz(smoothPeriod25[1])
phase25 = i125 != 0 ? math.atan(q125 / i125) * 180 / pi25 : 0
deltaPhase25 = nz(phase25[1]) - phase25
deltaPhase25 := deltaPhase25 < 1 ? 1 : deltaPhase25
alpha25 = fastLimit25 / deltaPhase25
alpha25 := alpha25 < slowLimit25 ? slowLimit25 : alpha25
mama25 = 0.0
mama25 := alpha25 * src25 + (1 - alpha25) * nz(mama25[1])
fama25 = 0.0
fama25 := 0.5 * alpha25 * mama25 + (1 - 0.5 * alpha25) * nz(fama25[1])
sig25 = mama25 > fama25 ? 1 : mama25 < fama25 ? -1 : 0
mamaColor25 = sig25 > 0 ? color.green : sig25 < 0 ? color.red : color.black
//plot(mama25, title='MAMA', color=mamaColor25, linewidth=2)
//plot(fama25, title='FAMA', color=color.new(color.yellow, 0), linewidth=2)
xyz2=(mama25+fama25)/2
//
length26 = input.int(title='Length', defval=15, minval=1)
momLength26 = input.int(title='MomentumLength', defval=5, minval=1)
src26 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
num26 = 0.0
coefSum26 = 0.0
for i = 0 to length26 - 1 by 1
coef26 = math.abs(nz(src26[i]) - nz(src26[i + momLength26]))
num26 += coef26 * nz(src26[i])
coefSum26 += coef26
coefSum26
filt26 = coefSum26 != 0 ? num26 / coefSum26 : 0
sig26 = src26 > filt26 ? 1 : src26 < filt26 ? -1 : 0
filtColor26 = sig26 > 0 ? color.green : sig26 < 0 ? color.red : color.black
//plot(filt26, title='Filter', color=filtColor26, linewidth=2)
//
src27 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
wma127 = (7 * src27 + 6 * nz(src27[1]) + 5 * nz(src27[2]) + 4 * nz(src27[3]) + 3 * nz(src27[4]) + 2 * nz(src27[5]) + nz(src27[6])) / 28
wma227 = (7 * wma127 + 6 * nz(wma127[1]) + 5 * nz(wma127[2]) + 4 * nz(wma127[3]) + 3 * nz(wma127[4]) + 2 * nz(wma127[5]) + nz(wma127[6])) / 28
predict27 = 2 * wma127 - wma227
trigger27 = (4 * predict27 + 3 * nz(predict27[1]) + 2 * nz(predict27[2]) + nz(predict27[3])) / 10
sig27 = predict27 > trigger27 ? 1 : predict27 < trigger27 ? -1 : 0
pmaColor27 = sig27 > 0 ? color.green : sig27 < 0 ? color.red : color.black
//plot(predict27, title='Predict', color=pmaColor27, linewidth=2)
//plot(trigger27, title='Trigger', color=color.new(color.yellow, 0), linewidth=1)
xyz3=(filt26+predict27+trigger27)/3
//
src29 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
shortLength29 = input.int(title='ShortLength', defval=5, minval=1)
longLength29 = input.int(title='LongLength', defval=20, minval=1)
shortAvg29 = ta.wma(src29, shortLength29)
shortMa29 = math.sum(math.pow(src29 - shortAvg29, 2), shortLength29) / shortLength29
shortRms29 = shortMa29 > 0 ? math.sqrt(shortMa29) : 0
longAvg29 = ta.wma(src29, longLength29)
longMa29 = math.sum(math.pow(src29 - longAvg29, 2), longLength29) / longLength29
longRms29 = longMa29 > 0 ? math.sqrt(longMa29) : 0
kk29 = longRms29 != 0 ? 0.2 * shortRms29 / longRms29 : 0
vidya29 = 0.0
vidya29 := kk29 * src29 + (1 - kk29) * nz(vidya29[1])
slo29 = src29 - vidya29
sig29 = slo29 > 0 ? slo29 > nz(slo29[1]) ? 2 : 1 : slo29 < 0 ? slo29 < nz(slo29[1]) ? -2 : -1 : 0
vidyaColor29 = sig29 > 1 ? color.green : sig29 > 0 ? color.lime : sig29 < -1 ? color.maroon : sig29 < 0 ? color.red : color.black
//plot(vidya29, title='Vidya', color=vidyaColor29, linewidth=2)
//
src32 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length32 = input.int(title='Length', defval=3, minval=1)
jsa32 = (src32 + src32[length32]) / 2
sig32 = src32 > jsa32 ? 1 : src32 < jsa32 ? -1 : 0
jsaColor32 = sig32 > 0 ? color.green : sig32 < 0 ? color.red : color.black
//plot(jsa32, color=jsaColor32, linewidth=2)
//
src33 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLength33 = input.int(title = "FastLength", defval = 5, minval = 1)
slowLength33 = input.int(title = "SlowLength", defval = 50, minval = 1)
leavittProjection(src33, length33) =>
result33 = ta.linreg(src33, length33, -1)
fastLp33 = leavittProjection(src33, fastLength33)
slowLp33 = leavittProjection(src33, slowLength33)
slo33 = fastLp33 - slowLp33
sig33 = slo33 > 0 ? slo33 > nz(slo33[1]) ? 2 : 1 : slo33 < 0 ? slo33 < nz(slo33[1]) ? -2 : -1 : 0
lpColor33 = sig33 > 1 ? color.lime : sig33 > 0 ? color.lime : sig33 < -1 ? color.red : sig33 < 0 ? color.red : color.white
//plot(fastLp33, title = 'FastLp', color = lpColor33, linewidth = 2)
//plot(slowLp33, title = 'Stop', style=plot.style_cross, color = rmacdColor, linewidth = 2)
xyz4=(vidya29+jsa32+fastLp33+slowLp33)/4
//
src37 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLength37 = input.int(title='FastLength', defval=5, minval=1)
slowLength37 = input.int(title='SlowLength', defval=20, minval=1)
mult37 = input.int(title='Multiple', defval=1, minval=1)
fastEma37 = ta.ema(src37, fastLength37)
slowEma37 = ta.ema(src37, slowLength37)
sqAvg37 = math.sum(math.pow(slowEma37 - fastEma37, 2), fastLength37) / fastLength37
dev37 = math.sqrt(sqAvg37) * mult37
upperBand37 = slowEma37 + dev37
lowerBand37 = slowEma37 - dev37
middleBand37 = fastEma37
sig37 = src37 > upperBand37 and nz(src37[1]) <= nz(upperBand37[1]) or src37 > lowerBand37 and nz(src37[1]) <= nz(lowerBand37[1]) ? 1 : src37 < lowerBand37 and nz(src37[1]) >= nz(lowerBand37[1]) or src37 < upperBand37 and nz(src37[1]) >= nz(upperBand37[1]) ? -1 : src37 > middleBand37 ? 1 : src37 < middleBand37 ? -1 : 0
mabColor37 = sig37 > 0 ? color.green : sig37 < 0 ? color.red : color.black
//plot(upperBand37, title='MabUp', color=mabColor37, linewidth=2)
//plot(middleBand37, title='MabMid', color=color.new(color.yellow, 0), linewidth=1)
//plot(lowerBand37, title='MabLow', color=mabColor37, linewidth=2)
xyz5=(upperBand37+middleBand37+lowerBand37)/3
//
src44 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length44 = input.int(title='Length', defval=10, minval=1)
middleBandLength44 = input.int(title='MiddleBandLength', defval=21, minval=1)
bandsDeviation44 = input.float(title='BandsDeviation', defval=2.4, minval=0.1)
lowBandAdjust44 = input.float(title='LowBandAdjust', defval=0.9, minval=0.1)
atrPeriod44 = length44 * 2 - 1
atrBuf44 = ta.atr(atrPeriod44) * bandsDeviation44
ma44 = ta.ema(src44, length44)
upperBand44 = ma44 + ma44 * atrBuf44 / src44
middleBand44 = ta.ema(src44, middleBandLength44)
lowerBand44 = ma44- ma44 * atrBuf44 * lowBandAdjust44 / src44
sig44 = src44 > upperBand44 and nz(src44[1]) <= nz(upperBand44[1]) or src44 > lowerBand44 and nz(src44[1]) <= nz(lowerBand44[1]) or src44 > middleBand44 ? 1 : src44 < lowerBand44 and nz(src44[1]) >= nz(lowerBand44[1]) or src44 < upperBand44 and nz(src44[1]) >= nz(upperBand44[1]) or src44 < middleBand44 ? -1 : 0
svbColor44 = sig44 > 0 ? color.green : sig44 < 0 ? color.red : color.black
//plot(upperBand44, title='SVBUp', color=svbColor44, linewidth=2)
//plot(middleBand44, title='SVBMid', color=color.new(color.black, 0), linewidth=1)
//plot(lowerBand44, title='SVBLow', color=svbColor44, linewidth=2)
xyz6=(upperBand44+middleBand44+lowerBand44)/3
//
float inp55 = input(title = 'Source', defval = close)
string res55 = input.timeframe(title = 'Resolution', defval = '')
bool rep55 = input(title = 'Allow Repainting?', defval = false)
//
float src51 = request.security(syminfo.ticker, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
int fastLength51 = input.int(title = 'FastLength', defval = 5, minval = 1)
int slowLength51 = input.int(title = 'SlowLength', defval = 20, minval = 1)
int sampleLength51 = input.int(title = 'SampleLength', defval = 5, minval = 1)
hannFilter51(float sampleSrc51, int length51) =>
filt51 = 0.0, coef51 = 0.0
for i = 1 to length51
cosine51 = 1 - math.cos(2 * math.pi * i / (length51 + 1))
filt51 := filt51 + (cosine51 * nz(sampleSrc51[i - 1]))
coef51 := coef51 + cosine51
filt51 := coef51 != 0 ? filt51 / coef51 : 0
float sample51 = 0.0
sample51 := bar_index % sampleLength51 == 0 ? src51 : nz(sample51[1])
float fastAvg51 = hannFilter51(sample51, fastLength51)
float slowAvg51 = hannFilter51(sample51, slowLength51)
float slo51 = fastAvg51 - slowAvg51
int sig51 = slo51 > 0 ? slo51 > nz(slo51[1]) ? 2 : 1 : slo51 < 0 ? slo51 < nz(slo51[1]) ? -2 : -1 : 0
color udsmaColor51 = sig51 > 1 ? color.green : sig51 > 0 ? color.lime : sig51 < -1 ? color.maroon : sig51 < 0 ? color.red : color.black
//plot(fastAvg51, title = "FastAverage", color = udsmaColor51, linewidth = 2)
//plot(slowAvg51, title = "SlowAverage", color = chart.fg_color, linewidth = 1)
xyz7=(fastAvg51+slowAvg51)/2
//
float src52 = request.security(syminfo.tickerid, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
fastLength52 = input.int(title = "FastLength", defval = 14, minval = 1)
slowLength52 = input.int(title = "SlowLength", defval = 30, minval = 1)
leavittProjection52(float src52, int length52) =>
float result52 = ta.linreg(src52, length52, -1)
leavittConvolution52(float src52, int length52) =>
int sqrtLength52 = math.floor(nz(math.sqrt(length52)))
float result52 = ta.linreg(leavittProjection52(src52, length52), sqrtLength52, -1)
float fastConv52 = leavittConvolution52(src52, fastLength52)
float slowConv52 = leavittConvolution52(src52, slowLength52)
float slo52 = fastConv52 - slowConv52
int sig52 = slo52 > 0 ? slo52 > nz(slo52[1]) ? 2 : 1 : slo52 < 0 ? slo52 < nz(slo52[1]) ? -2 : -1 : 0
color lcColor52 = sig52 > 1 ? color.green : sig52 > 0 ? color.lime : sig52 < -1 ? color.maroon : sig52 < 0 ? color.red : color.white
//plot(fastConv52, title = 'FastConv', color = lcColor52, linewidth = 2)
//plot(slowConv52, title = 'SlowConv', color = chart.fg_color, linewidth = 1)
xyz8=(fastConv52+slowConv52)/2
//
f_security(_symbol66, _res66, _src66, _repaint66) =>
request.security(_symbol66, _res66, _src66[_repaint66 ? 0 : barstate.isrealtime ? 1 : 0])[_repaint66 ? 0 : barstate.isrealtime ? 0 : 1]
res66 = input.timeframe(title='Resolution', defval='')
rep66 = input(title='Allow Repainting?', defval=false)
//
length53 = input.int(title='Length', defval=20, minval=1)
factor53 = input.int(title='Factor', defval=2, minval=1)
p53 = f_security(syminfo.tickerid, res66, hl2, rep66)
h53 = f_security(syminfo.tickerid, res66, high, rep66)
l53 = f_security(syminfo.tickerid, res66, low, rep66)
t53 = f_security(syminfo.tickerid, res66, ta.tr, rep66)
mpEma53 = ta.ema(p53, length53)
trEma53 = ta.ema(t53, length53)
stdDev53 = ta.stdev(trEma53, length53)
ad53 = p53 > nz(p53[1]) ? mpEma53 + trEma53 / 2 : p53 < nz(p53[1]) ? mpEma53 - trEma53 / 2 : mpEma53
adm53 = ta.ema(ad53, length53)
trndDn53 = 0.0
trndDn53 := ta.crossunder(adm53, mpEma53) ? h53[2] : p53 < nz(p53[1]) ? p53 + stdDev53 * factor53 : nz(trndDn53[1], h53[2])
trndUp53 = 0.0
trndUp53 := ta.crossover(adm53, mpEma53) ? l53[2] : p53 > nz(p53[1]) ? p53 - stdDev53 * factor53 : nz(trndUp53[1], l53[2])
trndr53 = 0.0
trndr53 := adm53 < mpEma53 ? trndDn53 : adm53 > mpEma53 ? trndUp53 : nz(trndr53[1], 0)
sig53 = p53 > trndr53 ? 1 : p53 < trndr53 ? -1 : 0
trndrColor53 = sig53 > 0 ? color.green : sig53 < 0 ? color.red : color.black
//plot(trndr53, color=trndrColor53, linewidth=2)
//plot(mpEma53, color=color.new(color.blue, 0), linewidth=2)
//plot(adm53, color=color.new(color.black, 0), linewidth=1)
xyz9=(trndDn53+mpEma53+adm53)/3
//
c54 = f_security(syminfo.tickerid, res66, close, rep66)
v54 = f_security(syminfo.tickerid, res66, volume, rep66)
length54 = input.int(title='Length', defval=50, minval=2)
mult54 = input.float(title='Mult', defval=10.0, minval=0.01)
alpha54 = 2.0 / (length54 + 1)
mom54 = c54 - nz(c54[1])
pv54 = mom54 > 0 ? v54 : 0
nv54 = mom54 < 0 ? v54 : 0
pvMa54 = ta.ema(pv54, length54)
nvMa54 = ta.ema(nv54, length54)
vs54 = pvMa54 + nvMa54 != 0 ? math.abs(pvMa54 - nvMa54) / (pvMa54 + nvMa54) : 0
rsvaEma54 = 0.0
rsvaEma54 := nz(rsvaEma54[1]) + (alpha54 * (1 + (vs54 * mult54)) * (c54 - nz(rsvaEma54[1])))
slo54 = c54 - rsvaEma54
sig54 = slo54 > 0 ? slo54 > nz(slo54[1]) ? 2 : 1 : slo54 < 0 ? slo54 < nz(slo54[1]) ? -2 : -1 : 0
rsvaemaColor54 = sig54 > 1 ? color.green : sig54 > 0 ? color.lime : sig54 < -1 ? color.maroon : sig54 < 0 ? color.red : color.black
//plot(rsvaEma54, title='RSEma', color=rsvaemaColor54, linewidth=2)
//
length56 = input.int(title='Length', defval=20, minval=1)
h56 = f_security(syminfo.tickerid, res66, high, rep66)
l56 = f_security(syminfo.tickerid, res66, low, rep66)
c56 = f_security(syminfo.tickerid, res66, close, rep66)
hh56 = ta.highest(h56, length56)
ll56 = ta.lowest(l56, length56)
atr56 = ta.atr(length56)
mult56 = math.sqrt(length56)
dSup56 = hh56 - atr56 * mult56
dRes56 = ll56 + atr56 * mult56
dMid56 = (dSup56 + dRes56) / 2
sig56 = c56 > dMid56 ? 1 : c56 < dMid56 ? -1 : 0
dsrColor56 = sig56 > 0 ? color.green : sig56 < 0 ? color.red : color.black
//plot(dSup56, title='Support', color=color.new(color.red, 0), linewidth=2)
//plot(dMid56, title='Middle', color=dsrColor56, linewidth=1)
//plot(dRes56, title='Resistance', color=color.new(color.green, 0), linewidth=2)
xyz10=(rsvaEma54+dSup56+dMid56+dRes56)/4
//
length57 = input.int(title='Length', defval=10, minval=1)
h57 = f_security(syminfo.tickerid, res66, high, rep66)
l57 = f_security(syminfo.tickerid, res66, low, rep66)
c57 = f_security(syminfo.tickerid, res66, close, rep66)
highMa57 = ta.sma(h57, length57)
lowMa57 = ta.sma(l57, length57)
ghla57 = 0.0
ghla57 := c57 > nz(highMa57[1]) ? lowMa57 : c57 < nz(lowMa57[1]) ? highMa57 : nz(ghla57[1])
sig57 = c57 > ghla57 ? 1 : c57 < ghla57 ? -1 : 0
ghlaColor57 = sig57 > 0 ? color.green : sig57 < 0 ? color.red : color.black
//plot(ghla57, title='GHLA', color=ghlaColor57, linewidth=2)
//
inp59 = input(title='Source', defval=close)
h59 = f_security(syminfo.tickerid, res66, high, rep66)
l59 = f_security(syminfo.tickerid, res66, low, rep66)
c59 = f_security(syminfo.tickerid, res66, inp59, rep66)
length59 = input.int(title='Length', defval=14, minval=1)
mHigh59 = ta.linreg(h59, length59, 0) - ta.linreg(h59, length59, 1)
mLow59 = ta.linreg(l59, length59, 0) - ta.linreg(l59, length59, 1)
upperBand59 = h59, lowerBand59 = l59
for i = 0 to length59 - 1
currH59 = nz(h59[i])
prevH59 = nz(h59[i - 1])
currL59 = nz(l59[i])
prevL59 = nz(l59[i - 1])
vHigh59 = currH59 + (nz(mHigh59[i]) * i)
vLow59 = currL59 + (nz(mLow59[i]) * i)
upperBand59 := math.max(vHigh59, upperBand59)
lowerBand59 := math.min(vLow59, lowerBand59)
middleBand59 = (upperBand59 + 59) / 2
slo59 = c59 - middleBand59
sig59 = (c59 > upperBand59 and nz(c59[1]) <= nz(upperBand59[1])) or (c59 > lowerBand59 and nz(c59[1]) <= nz(lowerBand59[1]))
? 1 : (c59 < lowerBand59 and nz(c59[1]) >= nz(lowerBand59[1])) or (c59 < upperBand59 and nz(c59[1]) >= nz(upperBand59[1]))
? -1 : slo59 > 0 ? slo59 > nz(slo59[1]) ? 2 : 1 : slo59 < 0 ? slo59 < nz(slo59[1]) ? -2 : -1 : 0
pbColor59 = sig59 > 1 ? color.green : sig59 > 0 ? color.lime : sig59 < -1 ? color.maroon : sig59 < 0 ? color.red : color.black
//plot(upperBand59, title="UpperBand", linewidth=2, color=pbColor59)
//plot(lowerBand59, title="LowerBand", linewidth=2, color=pbColor59)
xyz11=(ghla57+upperBand59+lowerBand59)/3
//
length61 = input.int(title='Length', defval=25, minval=1)
h61 = f_security(syminfo.tickerid, res66, high, rep66)
l61 = f_security(syminfo.tickerid, res66, low, rep66)
c61 = f_security(syminfo.tickerid, res66, close, rep66)
hh61 = ta.highest(h61, length61)
ll61 = ta.lowest(l61, length61)
range_161 = hh61 - ll61
sup161 = ll61 - 0.25 * range_161
sup261 = ll61 - 0.5 * range_161
res161 = hh61 + 0.25 * range_161
res261 = hh61 + 0.5 * range_161
mid61 = (sup161 + sup261 + res161 + res261) / 4
sig61 = c61 > mid61 ? 1 : c61 < mid61 ? -1 : 0
psrColor61 = sig61 > 0 ? color.green : sig61 < 0 ? color.red : color.black
//plot(sup161, title='Support1', color=color.new(color.red, 0), linewidth=2)
//plot(sup261, title='Support2', color=color.new(color.red, 0), linewidth=2)
//plot(mid61, title='Middle', color=psrColor61, linewidth=1)
//plot(res161, title='Resistance1', color=color.new(color.green, 0), linewidth=2)
//plot(res261, title='Resistance2', color=color.new(color.green, 0), linewidth=2)
xyz12=(sup161+sup261+mid61+res161+res261)/5
//Emas
price = request.security(syminfo.tickerid, "", close)
EMA_5 = ta.ema(price, 1)
EMA_13 = ta.ema(price, 10)
EMA_26 = ta.ema(price, 20)
EMA_50 = ta.ema(price, 50)
EMA_100 = ta.ema(price, 100)
EMA_200 = ta.ema(price, 200)
sdf=(EMA_5+EMA_13+EMA_26+EMA_50+EMA_100+EMA_200)/6
plot(sdf,"Ortalama EMA",color.yellow, linewidth=1)
//Function Avarage
xyz13=(xyz1+xyz2+xyz3+xyz4+xyz5+xyz6+xyz7+xyz8+xyz9+xyz10+xyz11+xyz12)/12
plot(xyz13, title='Super Avarage',style=plot.style_line, color=color.fuchsia, linewidth=2)
//END
2034 nolu mesajdaki koda....parabol ve çift döngü sar eklenmiş hali...ortalamalar saatlik hesaplatılmıştır...
denemek isteyene örnek kod....
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
//@version=5
indicator('.', max_bars_back=100, overlay=true)
//Time period
inp = input(title='Source', defval=close)
res = input.timeframe(title='Resolution', defval='15')
rep = input(title='Allow Repainting?', defval=false)
//
src1 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLength1 = input.int(title='FastLength', defval=12, minval=1)
slowLength1 = input.int(title='SlowLength', defval=26, minval=1)
signalLength1 = input.int(title='SignalLength', defval=9, minval=1)
macdLevel1 = input.float(title='MacdLevel', defval=0, minval=0)
fastAlpha1 = 2.0 / (1 + fastLength1)
slowAlpha1 = 2.0 / (1 + slowLength1)
fastEma1 = ta.ema(src1, fastLength1)
slowEma1 = ta.ema(src1, slowLength1)
pMacdEq1 = fastAlpha1 - slowAlpha1 != 0 ? ((nz(fastEma1[1]) * fastAlpha1) - (nz(slowEma1[1]) * slowAlpha1)) / (fastAlpha1 - slowAlpha1) : 0
pMacdEqSig1 = ta.ema(pMacdEq1, signalLength1)
pMacdLevel1 = fastAlpha1 - slowAlpha1 != 0 ? (macdLevel1 - (nz(fastEma1[1]) * (1 - fastAlpha1)) + (nz(slowEma1[1]) * (1 - slowAlpha1))) / (fastAlpha1 - slowAlpha1) : 0
slo1 = src1 - pMacdEq1
sig1 = slo1 > 0 ? slo1 > nz(slo1[1]) ? 2 : 1 : slo1 < 0 ? slo1 < nz(slo1[1]) ? -2 : -1 : 0
rmacdColor = sig1 > 1 ? color.lime : sig1 > 0 ? color.lime : sig1 < -1 ? color.red : sig1 < 0 ? color.red : color.white
//plot(pMacdEq1, title='Trend Continue',style=plot.style_cross, color=rmacdColor, linewidth=2)
//plot(pMacdEqSig1, title='MacdEqSignal', color=color.rgb(255, 255, 255, 100), linewidth=1)
//plot(pMacdLevel1, title='MacdLevel', color=color.blue, linewidth=2)
xyz1=(pMacdEq1+pMacdEqSig1+pMacdLevel1)/3
//plot(xyz11, title='Avarage', color=color.rgb(241, 225, 8, 100), linewidth=2)
//
src25 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLimit25 = input.float(title='FastLimit', defval=0.2, minval=0.01, step=0.01)
slowLimit25 = input.float(title='SlowLimit', defval=0.02, minval=0.01, step=0.01)
pi25 = 2 * math.asin(1)
period25 = 0.0
smooth25 = (4 * src25 + 3 * nz(src25[1]) + 2 * nz(src25[2]) + nz(src25[3])) / 10
detrender25 = (0.0962 * smooth25 + 0.5769 * nz(smooth25[2]) - 0.5769 * nz(smooth25[4]) - 0.0962 * nz(smooth25[6])) * (0.075 * nz(period25[1]) + 0.54)
q125 = (0.0962 * detrender25 + 0.5769 * nz(detrender25[2]) - 0.5769 * nz(detrender25[4]) - 0.0962 * nz(detrender25[6])) * (0.075 * nz(period25[1]) + 0.54)
i125 = nz(detrender25[3])
jI25 = (0.0962 * i125 + 0.5769 * nz(i125[2]) - 0.5769 * nz(i125[4]) - 0.0962 * nz(i125[6])) * (0.075 * nz(period25[1]) + 0.54)
jQ25 = (0.0962 * q125 + 0.5769 * nz(q125[2]) - 0.5769 * nz(q125[4]) - 0.0962 * nz(q125[6])) * (0.075 * nz(period25[1]) + 0.54)
i225 = i125 - jQ25
i225 := 0.2 * i225 + 0.8 * nz(i225[1])
q225 = q125 + jI25
q225 := 0.2 * q225 + 0.8 * nz(q225[1])
re25 = i225 * nz(i225[1]) + q225 * nz(q225[1])
re25 := 0.2 * re25 + 0.8 * nz(re25[1])
im25 = i225 * nz(q225[1]) - q225 * nz(i225[1])
im25 := 0.2 * im25 + 0.8 * nz(im25[1])
period25 := im25 != 0 and re25 != 0 ? 2 * pi25 / math.atan(im25 / re25) : 0
period25 := math.min(math.max(period25, 0.67 * nz(period25[1])), 1.5 * nz(period25[1]))
period25 := math.min(math.max(period25, 6), 50)
period25 := 0.2 * period25 + 0.8 * nz(period25[1])
smoothPeriod25 = 0.0
smoothPeriod25 := 0.33 * period25 + 0.67 * nz(smoothPeriod25[1])
phase25 = i125 != 0 ? math.atan(q125 / i125) * 180 / pi25 : 0
deltaPhase25 = nz(phase25[1]) - phase25
deltaPhase25 := deltaPhase25 < 1 ? 1 : deltaPhase25
alpha25 = fastLimit25 / deltaPhase25
alpha25 := alpha25 < slowLimit25 ? slowLimit25 : alpha25
mama25 = 0.0
mama25 := alpha25 * src25 + (1 - alpha25) * nz(mama25[1])
fama25 = 0.0
fama25 := 0.5 * alpha25 * mama25 + (1 - 0.5 * alpha25) * nz(fama25[1])
sig25 = mama25 > fama25 ? 1 : mama25 < fama25 ? -1 : 0
mamaColor25 = sig25 > 0 ? color.green : sig25 < 0 ? color.red : color.black
//plot(mama25, title='MAMA', color=mamaColor25, linewidth=2)
//plot(fama25, title='FAMA', color=color.new(color.yellow, 0), linewidth=2)
xyz2=(mama25+fama25)/2
//
length26 = input.int(title='Length', defval=15, minval=1)
momLength26 = input.int(title='MomentumLength', defval=5, minval=1)
src26 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
num26 = 0.0
coefSum26 = 0.0
for i = 0 to length26 - 1 by 1
coef26 = math.abs(nz(src26[i]) - nz(src26[i + momLength26]))
num26 += coef26 * nz(src26[i])
coefSum26 += coef26
coefSum26
filt26 = coefSum26 != 0 ? num26 / coefSum26 : 0
sig26 = src26 > filt26 ? 1 : src26 < filt26 ? -1 : 0
filtColor26 = sig26 > 0 ? color.green : sig26 < 0 ? color.red : color.black
//plot(filt26, title='Filter', color=filtColor26, linewidth=2)
//
src27 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
wma127 = (7 * src27 + 6 * nz(src27[1]) + 5 * nz(src27[2]) + 4 * nz(src27[3]) + 3 * nz(src27[4]) + 2 * nz(src27[5]) + nz(src27[6])) / 28
wma227 = (7 * wma127 + 6 * nz(wma127[1]) + 5 * nz(wma127[2]) + 4 * nz(wma127[3]) + 3 * nz(wma127[4]) + 2 * nz(wma127[5]) + nz(wma127[6])) / 28
predict27 = 2 * wma127 - wma227
trigger27 = (4 * predict27 + 3 * nz(predict27[1]) + 2 * nz(predict27[2]) + nz(predict27[3])) / 10
sig27 = predict27 > trigger27 ? 1 : predict27 < trigger27 ? -1 : 0
pmaColor27 = sig27 > 0 ? color.green : sig27 < 0 ? color.red : color.black
//plot(predict27, title='Predict', color=pmaColor27, linewidth=2)
//plot(trigger27, title='Trigger', color=color.new(color.yellow, 0), linewidth=1)
xyz3=(filt26+predict27+trigger27)/3
//
src29 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
shortLength29 = input.int(title='ShortLength', defval=5, minval=1)
longLength29 = input.int(title='LongLength', defval=20, minval=1)
shortAvg29 = ta.wma(src29, shortLength29)
shortMa29 = math.sum(math.pow(src29 - shortAvg29, 2), shortLength29) / shortLength29
shortRms29 = shortMa29 > 0 ? math.sqrt(shortMa29) : 0
longAvg29 = ta.wma(src29, longLength29)
longMa29 = math.sum(math.pow(src29 - longAvg29, 2), longLength29) / longLength29
longRms29 = longMa29 > 0 ? math.sqrt(longMa29) : 0
kk29 = longRms29 != 0 ? 0.2 * shortRms29 / longRms29 : 0
vidya29 = 0.0
vidya29 := kk29 * src29 + (1 - kk29) * nz(vidya29[1])
slo29 = src29 - vidya29
sig29 = slo29 > 0 ? slo29 > nz(slo29[1]) ? 2 : 1 : slo29 < 0 ? slo29 < nz(slo29[1]) ? -2 : -1 : 0
vidyaColor29 = sig29 > 1 ? color.green : sig29 > 0 ? color.lime : sig29 < -1 ? color.maroon : sig29 < 0 ? color.red : color.black
//plot(vidya29, title='Vidya', color=vidyaColor29, linewidth=2)
//
src32 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length32 = input.int(title='Length', defval=3, minval=1)
jsa32 = (src32 + src32[length32]) / 2
sig32 = src32 > jsa32 ? 1 : src32 < jsa32 ? -1 : 0
jsaColor32 = sig32 > 0 ? color.green : sig32 < 0 ? color.red : color.black
//plot(jsa32, color=jsaColor32, linewidth=2)
//
src33 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLength33 = input.int(title = "FastLength", defval = 5, minval = 1)
slowLength33 = input.int(title = "SlowLength", defval = 50, minval = 1)
leavittProjection(src33, length33) =>
result33 = ta.linreg(src33, length33, -1)
fastLp33 = leavittProjection(src33, fastLength33)
slowLp33 = leavittProjection(src33, slowLength33)
slo33 = fastLp33 - slowLp33
sig33 = slo33 > 0 ? slo33 > nz(slo33[1]) ? 2 : 1 : slo33 < 0 ? slo33 < nz(slo33[1]) ? -2 : -1 : 0
lpColor33 = sig33 > 1 ? color.lime : sig33 > 0 ? color.lime : sig33 < -1 ? color.red : sig33 < 0 ? color.red : color.white
//plot(fastLp33, title = 'FastLp', color = lpColor33, linewidth = 2)
//plot(slowLp33, title = 'Stop', style=plot.style_cross, color = rmacdColor, linewidth = 2)
xyz4=(vidya29+jsa32+fastLp33+slowLp33)/4
//
src37 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLength37 = input.int(title='FastLength', defval=5, minval=1)
slowLength37 = input.int(title='SlowLength', defval=20, minval=1)
mult37 = input.int(title='Multiple', defval=1, minval=1)
fastEma37 = ta.ema(src37, fastLength37)
slowEma37 = ta.ema(src37, slowLength37)
sqAvg37 = math.sum(math.pow(slowEma37 - fastEma37, 2), fastLength37) / fastLength37
dev37 = math.sqrt(sqAvg37) * mult37
upperBand37 = slowEma37 + dev37
lowerBand37 = slowEma37 - dev37
middleBand37 = fastEma37
sig37 = src37 > upperBand37 and nz(src37[1]) <= nz(upperBand37[1]) or src37 > lowerBand37 and nz(src37[1]) <= nz(lowerBand37[1]) ? 1 : src37 < lowerBand37 and nz(src37[1]) >= nz(lowerBand37[1]) or src37 < upperBand37 and nz(src37[1]) >= nz(upperBand37[1]) ? -1 : src37 > middleBand37 ? 1 : src37 < middleBand37 ? -1 : 0
mabColor37 = sig37 > 0 ? color.green : sig37 < 0 ? color.red : color.black
//plot(upperBand37, title='MabUp', color=mabColor37, linewidth=2)
//plot(middleBand37, title='MabMid', color=color.new(color.yellow, 0), linewidth=1)
//plot(lowerBand37, title='MabLow', color=mabColor37, linewidth=2)
xyz5=(upperBand37+middleBand37+lowerBand37)/3
//
src44 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length44 = input.int(title='Length', defval=10, minval=1)
middleBandLength44 = input.int(title='MiddleBandLength', defval=21, minval=1)
bandsDeviation44 = input.float(title='BandsDeviation', defval=2.4, minval=0.1)
lowBandAdjust44 = input.float(title='LowBandAdjust', defval=0.9, minval=0.1)
atrPeriod44 = length44 * 2 - 1
atrBuf44 = ta.atr(atrPeriod44) * bandsDeviation44
ma44 = ta.ema(src44, length44)
upperBand44 = ma44 + ma44 * atrBuf44 / src44
middleBand44 = ta.ema(src44, middleBandLength44)
lowerBand44 = ma44- ma44 * atrBuf44 * lowBandAdjust44 / src44
sig44 = src44 > upperBand44 and nz(src44[1]) <= nz(upperBand44[1]) or src44 > lowerBand44 and nz(src44[1]) <= nz(lowerBand44[1]) or src44 > middleBand44 ? 1 : src44 < lowerBand44 and nz(src44[1]) >= nz(lowerBand44[1]) or src44 < upperBand44 and nz(src44[1]) >= nz(upperBand44[1]) or src44 < middleBand44 ? -1 : 0
svbColor44 = sig44 > 0 ? color.green : sig44 < 0 ? color.red : color.black
//plot(upperBand44, title='SVBUp', color=svbColor44, linewidth=2)
//plot(middleBand44, title='SVBMid', color=color.new(color.black, 0), linewidth=1)
//plot(lowerBand44, title='SVBLow', color=svbColor44, linewidth=2)
xyz6=(upperBand44+middleBand44+lowerBand44)/3
//
float inp55 = input(title = 'Source', defval = close)
string res55 = input.timeframe(title = 'Resolution', defval = '')
bool rep55 = input(title = 'Allow Repainting?', defval = false)
//
float src51 = request.security(syminfo.ticker, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
int fastLength51 = input.int(title = 'FastLength', defval = 5, minval = 1)
int slowLength51 = input.int(title = 'SlowLength', defval = 20, minval = 1)
int sampleLength51 = input.int(title = 'SampleLength', defval = 5, minval = 1)
hannFilter51(float sampleSrc51, int length51) =>
filt51 = 0.0, coef51 = 0.0
for i = 1 to length51
cosine51 = 1 - math.cos(2 * math.pi * i / (length51 + 1))
filt51 := filt51 + (cosine51 * nz(sampleSrc51[i - 1]))
coef51 := coef51 + cosine51
filt51 := coef51 != 0 ? filt51 / coef51 : 0
float sample51 = 0.0
sample51 := bar_index % sampleLength51 == 0 ? src51 : nz(sample51[1])
float fastAvg51 = hannFilter51(sample51, fastLength51)
float slowAvg51 = hannFilter51(sample51, slowLength51)
float slo51 = fastAvg51 - slowAvg51
int sig51 = slo51 > 0 ? slo51 > nz(slo51[1]) ? 2 : 1 : slo51 < 0 ? slo51 < nz(slo51[1]) ? -2 : -1 : 0
color udsmaColor51 = sig51 > 1 ? color.green : sig51 > 0 ? color.lime : sig51 < -1 ? color.maroon : sig51 < 0 ? color.red : color.black
//plot(fastAvg51, title = "FastAverage", color = udsmaColor51, linewidth = 2)
//plot(slowAvg51, title = "SlowAverage", color = chart.fg_color, linewidth = 1)
xyz7=(fastAvg51+slowAvg51)/2
//
float src52 = request.security(syminfo.tickerid, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
fastLength52 = input.int(title = "FastLength", defval = 14, minval = 1)
slowLength52 = input.int(title = "SlowLength", defval = 30, minval = 1)
leavittProjection52(float src52, int length52) =>
float result52 = ta.linreg(src52, length52, -1)
leavittConvolution52(float src52, int length52) =>
int sqrtLength52 = math.floor(nz(math.sqrt(length52)))
float result52 = ta.linreg(leavittProjection52(src52, length52), sqrtLength52, -1)
float fastConv52 = leavittConvolution52(src52, fastLength52)
float slowConv52 = leavittConvolution52(src52, slowLength52)
float slo52 = fastConv52 - slowConv52
int sig52 = slo52 > 0 ? slo52 > nz(slo52[1]) ? 2 : 1 : slo52 < 0 ? slo52 < nz(slo52[1]) ? -2 : -1 : 0
color lcColor52 = sig52 > 1 ? color.green : sig52 > 0 ? color.lime : sig52 < -1 ? color.maroon : sig52 < 0 ? color.red : color.white
//plot(fastConv52, title = 'FastConv', color = lcColor52, linewidth = 2)
//plot(slowConv52, title = 'SlowConv', color = chart.fg_color, linewidth = 1)
xyz8=(fastConv52+slowConv52)/2
//
f_security(_symbol66, _res66, _src66, _repaint66) =>
request.security(_symbol66, _res66, _src66[_repaint66 ? 0 : barstate.isrealtime ? 1 : 0])[_repaint66 ? 0 : barstate.isrealtime ? 0 : 1]
res66 = input.timeframe(title='Resolution', defval='')
rep66 = input(title='Allow Repainting?', defval=false)
//
length53 = input.int(title='Length', defval=20, minval=1)
factor53 = input.int(title='Factor', defval=2, minval=1)
p53 = f_security(syminfo.tickerid, res66, hl2, rep66)
h53 = f_security(syminfo.tickerid, res66, high, rep66)
l53 = f_security(syminfo.tickerid, res66, low, rep66)
t53 = f_security(syminfo.tickerid, res66, ta.tr, rep66)
mpEma53 = ta.ema(p53, length53)
trEma53 = ta.ema(t53, length53)
stdDev53 = ta.stdev(trEma53, length53)
ad53 = p53 > nz(p53[1]) ? mpEma53 + trEma53 / 2 : p53 < nz(p53[1]) ? mpEma53 - trEma53 / 2 : mpEma53
adm53 = ta.ema(ad53, length53)
trndDn53 = 0.0
trndDn53 := ta.crossunder(adm53, mpEma53) ? h53[2] : p53 < nz(p53[1]) ? p53 + stdDev53 * factor53 : nz(trndDn53[1], h53[2])
trndUp53 = 0.0
trndUp53 := ta.crossover(adm53, mpEma53) ? l53[2] : p53 > nz(p53[1]) ? p53 - stdDev53 * factor53 : nz(trndUp53[1], l53[2])
trndr53 = 0.0
trndr53 := adm53 < mpEma53 ? trndDn53 : adm53 > mpEma53 ? trndUp53 : nz(trndr53[1], 0)
sig53 = p53 > trndr53 ? 1 : p53 < trndr53 ? -1 : 0
trndrColor53 = sig53 > 0 ? color.green : sig53 < 0 ? color.red : color.black
//plot(trndr53, color=trndrColor53, linewidth=2)
//plot(mpEma53, color=color.new(color.blue, 0), linewidth=2)
//plot(adm53, color=color.new(color.black, 0), linewidth=1)
xyz9=(trndDn53+mpEma53+adm53)/3
//
c54 = f_security(syminfo.tickerid, res66, close, rep66)
v54 = f_security(syminfo.tickerid, res66, volume, rep66)
length54 = input.int(title='Length', defval=50, minval=2)
mult54 = input.float(title='Mult', defval=10.0, minval=0.01)
alpha54 = 2.0 / (length54 + 1)
mom54 = c54 - nz(c54[1])
pv54 = mom54 > 0 ? v54 : 0
nv54 = mom54 < 0 ? v54 : 0
pvMa54 = ta.ema(pv54, length54)
nvMa54 = ta.ema(nv54, length54)
vs54 = pvMa54 + nvMa54 != 0 ? math.abs(pvMa54 - nvMa54) / (pvMa54 + nvMa54) : 0
rsvaEma54 = 0.0
rsvaEma54 := nz(rsvaEma54[1]) + (alpha54 * (1 + (vs54 * mult54)) * (c54 - nz(rsvaEma54[1])))
slo54 = c54 - rsvaEma54
sig54 = slo54 > 0 ? slo54 > nz(slo54[1]) ? 2 : 1 : slo54 < 0 ? slo54 < nz(slo54[1]) ? -2 : -1 : 0
rsvaemaColor54 = sig54 > 1 ? color.green : sig54 > 0 ? color.lime : sig54 < -1 ? color.maroon : sig54 < 0 ? color.red : color.black
//plot(rsvaEma54, title='RSEma', color=rsvaemaColor54, linewidth=2)
//
length56 = input.int(title='Length', defval=20, minval=1)
h56 = f_security(syminfo.tickerid, res66, high, rep66)
l56 = f_security(syminfo.tickerid, res66, low, rep66)
c56 = f_security(syminfo.tickerid, res66, close, rep66)
hh56 = ta.highest(h56, length56)
ll56 = ta.lowest(l56, length56)
atr56 = ta.atr(length56)
mult56 = math.sqrt(length56)
dSup56 = hh56 - atr56 * mult56
dRes56 = ll56 + atr56 * mult56
dMid56 = (dSup56 + dRes56) / 2
sig56 = c56 > dMid56 ? 1 : c56 < dMid56 ? -1 : 0
dsrColor56 = sig56 > 0 ? color.green : sig56 < 0 ? color.red : color.black
//plot(dSup56, title='Support', color=color.new(color.red, 0), linewidth=2)
//plot(dMid56, title='Middle', color=dsrColor56, linewidth=1)
//plot(dRes56, title='Resistance', color=color.new(color.green, 0), linewidth=2)
xyz10=(rsvaEma54+dSup56+dMid56+dRes56)/4
//
length57 = input.int(title='Length', defval=10, minval=1)
h57 = f_security(syminfo.tickerid, res66, high, rep66)
l57 = f_security(syminfo.tickerid, res66, low, rep66)
c57 = f_security(syminfo.tickerid, res66, close, rep66)
highMa57 = ta.sma(h57, length57)
lowMa57 = ta.sma(l57, length57)
ghla57 = 0.0
ghla57 := c57 > nz(highMa57[1]) ? lowMa57 : c57 < nz(lowMa57[1]) ? highMa57 : nz(ghla57[1])
sig57 = c57 > ghla57 ? 1 : c57 < ghla57 ? -1 : 0
ghlaColor57 = sig57 > 0 ? color.green : sig57 < 0 ? color.red : color.black
//plot(ghla57, title='GHLA', color=ghlaColor57, linewidth=2)
//
inp59 = input(title='Source', defval=close)
h59 = f_security(syminfo.tickerid, res66, high, rep66)
l59 = f_security(syminfo.tickerid, res66, low, rep66)
c59 = f_security(syminfo.tickerid, res66, inp59, rep66)
length59 = input.int(title='Length', defval=14, minval=1)
mHigh59 = ta.linreg(h59, length59, 0) - ta.linreg(h59, length59, 1)
mLow59 = ta.linreg(l59, length59, 0) - ta.linreg(l59, length59, 1)
upperBand59 = h59, lowerBand59 = l59
for i = 0 to length59 - 1
currH59 = nz(h59[i])
prevH59 = nz(h59[i - 1])
currL59 = nz(l59[i])
prevL59 = nz(l59[i - 1])
vHigh59 = currH59 + (nz(mHigh59[i]) * i)
vLow59 = currL59 + (nz(mLow59[i]) * i)
upperBand59 := math.max(vHigh59, upperBand59)
lowerBand59 := math.min(vLow59, lowerBand59)
middleBand59 = (upperBand59 + 59) / 2
slo59 = c59 - middleBand59
sig59 = (c59 > upperBand59 and nz(c59[1]) <= nz(upperBand59[1])) or (c59 > lowerBand59 and nz(c59[1]) <= nz(lowerBand59[1]))
? 1 : (c59 < lowerBand59 and nz(c59[1]) >= nz(lowerBand59[1])) or (c59 < upperBand59 and nz(c59[1]) >= nz(upperBand59[1]))
? -1 : slo59 > 0 ? slo59 > nz(slo59[1]) ? 2 : 1 : slo59 < 0 ? slo59 < nz(slo59[1]) ? -2 : -1 : 0
pbColor59 = sig59 > 1 ? color.green : sig59 > 0 ? color.lime : sig59 < -1 ? color.maroon : sig59 < 0 ? color.red : color.black
//plot(upperBand59, title="UpperBand", linewidth=2, color=pbColor59)
//plot(lowerBand59, title="LowerBand", linewidth=2, color=pbColor59)
xyz11=(ghla57+upperBand59+lowerBand59)/3
//
length61 = input.int(title='Length', defval=25, minval=1)
h61 = f_security(syminfo.tickerid, res66, high, rep66)
l61 = f_security(syminfo.tickerid, res66, low, rep66)
c61 = f_security(syminfo.tickerid, res66, close, rep66)
hh61 = ta.highest(h61, length61)
ll61 = ta.lowest(l61, length61)
range_161 = hh61 - ll61
sup161 = ll61 - 0.25 * range_161
sup261 = ll61 - 0.5 * range_161
res161 = hh61 + 0.25 * range_161
res261 = hh61 + 0.5 * range_161
mid61 = (sup161 + sup261 + res161 + res261) / 4
sig61 = c61 > mid61 ? 1 : c61 < mid61 ? -1 : 0
psrColor61 = sig61 > 0 ? color.green : sig61 < 0 ? color.red : color.black
//plot(sup161, title='Support1', color=color.new(color.red, 0), linewidth=2)
//plot(sup261, title='Support2', color=color.new(color.red, 0), linewidth=2)
//plot(mid61, title='Middle', color=psrColor61, linewidth=1)
//plot(res161, title='Resistance1', color=color.new(color.green, 0), linewidth=2)
//plot(res261, title='Resistance2', color=color.new(color.green, 0), linewidth=2)
xyz12=(sup161+sup261+mid61+res161+res261)/5
//Function Avarage
xyz13=(xyz1+xyz2+xyz3+xyz4+xyz5+xyz6+xyz7+xyz8+xyz9+xyz10+xyz11+xyz12)/12
plot(xyz13, title='Super Avarage',style=plot.style_stepline, color=rmacdColor, linewidth=2)
//Emas
price = request.security(syminfo.tickerid, "60", close)
EMA_5 = ta.ema(price, 5)
EMA_13 = ta.ema(price, 13)
EMA_26 = ta.ema(price, 26)
EMA_50 = ta.ema(price, 50)
EMA_100 = ta.ema(price, 100)
EMA_200 = ta.ema(price, 200)
sdf=(EMA_5+EMA_13+EMA_26+EMA_50+EMA_100+EMA_200)/6
plot(sdf,"Avarage EMA",color.yellow, linewidth=1)
//END
//2 Pole Super Smoother Function
SSF(x, t) =>
omega = 2 * math.atan(1) * 4 / t
a = math.exp(-math.sqrt(2) * math.atan(1) * 4 / t)
b = 2 * a * math.cos(math.sqrt(2) / 2 * omega)
c2 = b
c3 = -math.pow(a, 2)
c1 = 1 - c2 - c3
SSF = 0.0
SSF := c1 * x + c2 * nz(SSF[1], x) + c3 * nz(SSF[2], nz(SSF[1], x))
SSF
//Getter Function For Pseudo 2D Matrix
get_val(mat, row, col, rowsize) =>
array.get(mat, int(rowsize * row + col))
//Setter Function For Pseudo 2D Matrix
set_val(mat, row, col, rowsize, val) =>
array.set(mat, int(rowsize * row + col), val)
//LU Decomposition Function
LU(A, B) =>
A_size = array.size(A)
B_size = array.size(B)
var L = array.new_float(A_size)
var U = array.new_float(A_size)
L_temp = 0.0
U_temp = 0.0
for c = 0 to B_size - 1 by 1
set_val(U, 0, c, B_size, get_val(A, 0, c, B_size))
for r = 1 to B_size - 1 by 1
set_val(L, r, 0, B_size, get_val(A, r, 0, B_size) / get_val(U, 0, 0, B_size))
for r = 0 to B_size - 1 by 1
for c = 0 to B_size - 1 by 1
if r == c
set_val(L, r, c, B_size, 1)
if r < c
set_val(L, r, c, B_size, 0)
if r > c
set_val(U, r, c, B_size, 0)
for r = 0 to B_size - 1 by 1
for c = 0 to B_size - 1 by 1
if na(get_val(L, r, c, B_size))
L_temp := get_val(A, r, c, B_size)
for k = 0 to math.max(c - 1, 0) by 1
L_temp -= get_val(U, k, c, B_size) * get_val(L, r, k, B_size)
L_temp
set_val(L, r, c, B_size, L_temp / get_val(U, c, c, B_size))
if na(get_val(U, r, c, B_size))
U_temp := get_val(A, r, c, B_size)
for k = 0 to math.max(r - 1, 0) by 1
U_temp -= get_val(U, k, c, B_size) * get_val(L, r, k, B_size)
U_temp
set_val(U, r, c, B_size, U_temp)
[L, U]
//Lower Triangular Solution Function (Forward Substitution)
LT_solve(L_, B) =>
B_size = array.size(B)
var Y = array.new_float(B_size)
Y_temp = 0.0
array.set(Y, 0, array.get(B, 0) / get_val(L_, 0, 0, B_size))
for r = 1 to B_size - 1 by 1
Y_temp := array.get(B, r)
for k = 0 to math.max(r - 1, 0) by 1
Y_temp -= get_val(L_, r, k, B_size) * array.get(Y, k)
Y_temp
array.set(Y, r, Y_temp / get_val(L_, r, r, B_size))
Y
//Upper Triangular Solution Function (Backward Substitution)
UT_solve(U_, Y_) =>
Y_size = array.size(Y_)
U_rev = array.copy(U_)
Y_rev = array.copy(Y_)
array.reverse(U_rev)
array.reverse(Y_rev)
X_rev = LT_solve(U_rev, Y_rev)
X = array.copy(X_rev)
array.reverse(X)
X
//Regression Function
regression_val(X_, index_, order_, offset_) =>
reg = 0.0
for i = 0 to order_ by 1
reg += array.get(X_, i) * math.pow(index_ - offset_, i)
reg
reg
//Curve Segment Drawing Function
draw_curve(Y, sdev, n, step_, col, ls, lw, draw, conf) =>
var line segment = line.new(x1=time[n * step_], y1=array.get(Y, n) + sdev, x2=time[(n - 1) * step_], y2=array.get(Y, n - 1) + sdev, xloc=xloc.bar_time)
if draw
if conf ? barstate.isconfirmed : 1
line.set_xy1(segment, time[n * step_], array.get(Y, n) + sdev)
line.set_xy2(segment, time[(n - 1) * step_], array.get(Y, n - 1) + sdev)
line.set_color(segment, col)
line.set_width(segment, lw)
line.set_style(segment, ls == 'Solid' ? line.style_solid : ls == 'Dotted' ? line.style_dotted : line.style_dashed)
else
line.delete(segment)
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Source Inputs
src = input(defval=close, title='Input Source Value')
use_filt = input(defval=true, title='Smooth Data Before Curve Fitting')
filt_per = input.int(defval=10, minval=2, title='Data Smoothing Period ═══════════════════')
//Calculation Inputs
per = input.int(defval=20, minval=2, title='Regression Sample Period')
order = input.int(defval=2, minval=1, title='Polynomial Order')
calc_offs = input(defval=0, title='Regression Offset')
ndev = input.float(defval=2.0, minval=0, title='Width Coefficient')
equ_from = input.int(defval=0, minval=0, title='Forecast From _ Bars Ago ═══════════════════')
//Channel Display Inputs
show_curve = input(defval=true, title='Show Fitted Curve')
show_high = input(defval=true, title='Show Fitted Channel High')
show_low = input(defval=true, title='Show Fitted Channel Low')
draw_step1 = input.int(defval=10, minval=1, title='Curve Drawing Step Size')
auto_step = input(defval=true, title='Auto Decide Step Size Instead')
draw_freq = input.string(defval='Close Only', options=['Continuous', 'Close Only'], title='Curve Update Frequency')
poly_col_h = input(defval=color.yellow, title='Channel High Line Color')
poly_lw_h = input.int(defval=1, minval=1, title='Channel High Line Width')
poly_ls_h = input.string(defval='Dashed', options=['Solid', 'Dotted', 'Dashed'], title='Channel High Line Style')
poly_col_m = input(defval=color.rgb(255, 235, 59, 100), title='Channel Middle Line Color')
poly_lw_m = input.int(defval=1, minval=1, title='Channel Middle Line Width')
poly_ls_m = input.string(defval='Dotted', options=['Solid', 'Dotted', 'Dashed'], title='Channel Middle Line Style')
poly_col_l = input(defval=color.yellow, title='Channel Low Line Color')
poly_lw_l = input.int(defval=1, minval=1, title='Channel Low Line Width')
poly_ls_l = input.string(defval='Dashed', options=['Solid', 'Dotted', 'Dashed'], title='Channel Low Line Style ═══════════════════')
//Smooth data and determine source type for calculation.
filt = SSF(src, filt_per)
srcxd = use_filt ? filt : src
//Populate a period sized array with bar values.
var x_vals = array.new_float(per)
for i = 0 to per - 1 by 1
array.set(x_vals, i, i + 1)
//Populate a period sized array with historical source values.
var src_vals = array.new_float(per)
for i = 0 to per - 1 by 1
array.set(src_vals, i, srcxd[per - 1 - i + equ_from])
//Populate an order*2 + 1 sized array with bar power sums.
var xp_sums = array.new_float(order * 2 + 1)
xp_sums_temp = 0.0
for i = 0 to order * 2 by 1
xp_sums_temp := 0
for j = 0 to per - 1 by 1
xp_sums_temp += math.pow(array.get(x_vals, j), i)
xp_sums_temp
array.set(xp_sums, i, xp_sums_temp)
//Populate an order + 1 sized array with (bar power)*(source value) sums.
var xpy_sums = array.new_float(order + 1)
xpy_sums_temp = 0.0
for i = 0 to order by 1
xpy_sums_temp := 0
for j = 0 to per - 1 by 1
xpy_sums_temp += math.pow(array.get(x_vals, j), i) * array.get(src_vals, j)
xpy_sums_temp
array.set(xpy_sums, i, xpy_sums_temp)
//Generate a pseudo square matrix with row and column sizes of order + 1 using bar power sums.
var xp_matrix = array.new_float(int(math.pow(order + 1, 2)))
for r = 0 to order by 1
for c = 0 to order by 1
set_val(xp_matrix, r, c, order + 1, array.get(xp_sums, r + c))
//Factor the power sum matrix into lower and upper triangular matrices with order + 1 rows and columns.
[lower, upper] = LU(xp_matrix, xpy_sums)
//Find lower triangular matrix solutions using (bar power)*(source value) sums.
l_solutions = LT_solve(lower, xpy_sums)
//Find upper triangular matrix solutions using lower matrix solutions. This gives us our regression coefficients.
reg_coefs = UT_solve(upper, l_solutions)
//Define curve drawing step size.
draw_step = auto_step ? math.ceil(per / 10) : draw_step1
//Calculate curve values.
var inter_vals = array.new_float(11)
for i = 0 to 10 by 1
array.set(inter_vals, i, regression_val(reg_coefs, per, order, calc_offs - equ_from + draw_step * i))
//Calculate standard deviation for channel.
Stdev = array.stdev(src_vals) * ndev
//Draw interpolated segments.
draw_curve(inter_vals, 0, 1, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 2, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 3, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 4, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 5, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 6, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 7, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 8, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 9, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 10, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
//Draw channel high segments.
draw_curve(inter_vals, Stdev, 1, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 2, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 3, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 4, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 5, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 6, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 7, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 8, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 9, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 10, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
//Draw channel low segments.
draw_curve(inter_vals, -Stdev, 1, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 2, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 3, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 4, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 5, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 6, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 7, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 8, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 9, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 10, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
//END
//Function Sar; slow-avarage-fast
lenxc = input(5)
lenxc20 = input(5)
lenxc50 = input(5)
z(close, lenxc) =>
hxc = 0.0
dxc = 0.0
for i = 0 to lenxc - 1 by 1
kxc = (lenxc - i) * lenxc
hxc += kxc
dxc += close[i] * kxc
dxc
dxc / hxc
cxc = z(close, math.floor(math.sqrt(lenxc)))
//
z20(close, lenxc20) =>
hcx20 = 0.0
dxc20 = 0.0
for i = 0 to lenxc20 - 1 by 1
kxc20 = (lenxc20 - i) * lenxc20
hcx20 += kxc20
dxc20 += close[i] * kxc20
dxc20
dxc20 / hcx20
cxc20 = z20(close, math.floor(math.sqrt(lenxc20)))
//
z50(close, lenxc50) =>
hxc50 = 0.0
dxc50 = 0.0
for i = 0 to lenxc50 - 1 by 1
kxc50 = (lenxc50 - i) * lenxc50
hxc50 += kxc50
dxc50 += close[i] * kxc50
dxc50
dxc50 / hxc50
cxc50 = z50(close, math.floor(math.sqrt(lenxc50)))
//
//
startsx = 0.05
incrementsx = 0.75
maximumsx = 0.35
ssx = ta.sar(startsx, incrementsx, maximumsx)
s1sx = z(ssx, lenxc)
pcsx = close < s1sx ? color.rgb(255, 82, 82, 100) : color.rgb(76, 175, 79, 100)
//plot(s1sx, title="SAR Avarage",style=plot.style_cross, color=pcsx, linewidth=1)
startsx20 = 0
incrementsx20 = 0.01
maximumsx20 = 1
ssx20 = ta.sar(startsx20, incrementsx20, maximumsx20)
s1sx20 = z20(ssx20, lenxc20)
pcsx20 = close < s1sx20 ? color.rgb(255, 82, 82, 00) : color.rgb(76, 175, 79, 00)
plot(s1sx20, title="Cyclical Slow",style=plot.style_line, color=pcsx20, linewidth=1)
startsx50 = 0
incrementsx50 = 0.1
maximumsx50 = 1
ssx50 = ta.sar(startsx50, incrementsx50, maximumsx50)
s1sx50 = z50(ssx50, lenxc50)
pcsx50 = close < s1sx50 ? color.rgb(255, 82, 82, 00) : color.rgb(76, 175, 79, 00)
plot(s1sx50, title="Cyclical Fast",style=plot.style_line, color=pcsx50, linewidth=1)
//END
aynı değerle hesaplanan....iki psarın....50 uzunluktaki parabol içinde....
trend görüntüsü örneği....https://www.tradingview.com/x/VxcfWL6c/
not....parabol işlem yapılan alan olarak düşünülmeli....
parabolün yönü trend yönü....çizgilerin ucu ise destek-direnç gibi düşünülmelidir...
periyodu ve sinyallemeyi dilediğiniz gibi yapın....
denemek isteyene kod....
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
//@version=5
indicator("Sar Reverse", overlay = true)
//Psar
psar(start1, inc1, maximum1) =>
out1 = float(na)
isUpTrend1 = bool(na)
maxMin1 = float(na)
acc1 = float(na)
prev1 = float(na)
if bar_index >= 1
prev1 := out1[1]
if bar_index == 1
if close > close[1]
isUpTrend1 := true
maxMin1 := math.max(high, high[1])
prev1 := math.min(low, low[1])
prev1
else
isUpTrend1 := false
maxMin1 := math.min(low, low[1])
prev1 := math.max(high, high[1])
prev1
acc1 := start1
acc1
else
isUpTrend1 := isUpTrend1[1]
acc1 := acc1[1]
maxMin1 := maxMin1[1]
maxMin1
if isUpTrend1
if high > maxMin1
maxMin1 := high
acc1 := math.min(acc1 + inc1, maximum1)
acc1
else
if low < maxMin1
maxMin1 := low
acc1 := math.min(acc1 + inc1, maximum1)
acc1
if na(out1)
out1 := prev1 + acc1 * (maxMin1 - prev1)
out1
if isUpTrend1
if low <= out1
isUpTrend1 := false
out1 := maxMin1
maxMin1 := low
acc1 := start1
acc1
else
if high >= out1
isUpTrend1 := true
out1 := maxMin1
maxMin1 := high
acc1 := start1
acc1
if na(out1)
if isUpTrend1
out1 := math.min(out1, bar_index == 1 ? low[1] : math.min(low[1], low[2]))
out1
else
out1 := math.max(out1, bar_index == 1 ? high[1] : math.max(high[1], high[2]))
out1
[out1, acc1, maxMin1, isUpTrend1]
start1 = input(0)
increment1 = input(0.1)
maximum1 = input(1)
[p1, AF1, EP1, isUpTrend1] = psar(start1, increment1, maximum1)
newEP1 = EP1 != EP1[1]
epNew1 = newEP1 ? EP1 : na
//plot(p1, 'TREND-Continue', style=plot.style_line, color=isUpTrend1 ? color.rgb(76, 175, 79, 00) : color.rgb(255, 82, 82, 00), linewidth=2)
plot(EP1, 'HızlıTREND', style=plot.style_line, color=isUpTrend1 ? color.rgb(76, 175, 79, 00) : color.rgb(255, 82, 82, 00), linewidth=2)
//Psar Reverse
x10= ta.sar(0, 0.1, 1)
plot(x10, title='YavaşTREND', style=plot.style_line, color=isUpTrend1 ? color.rgb(76, 175, 79, 00) : color.rgb(255, 82, 82, 00), linewidth=2)
//End
//2 Pole Super Smoother Function
SSF(x, t) =>
omega = 2 * math.atan(1) * 4 / t
a = math.exp(-math.sqrt(2) * math.atan(1) * 4 / t)
b = 2 * a * math.cos(math.sqrt(2) / 2 * omega)
c2 = b
c3 = -math.pow(a, 2)
c1 = 1 - c2 - c3
SSF = 0.0
SSF := c1 * x + c2 * nz(SSF[1], x) + c3 * nz(SSF[2], nz(SSF[1], x))
SSF
//Getter Function For Pseudo 2D Matrix
get_val(mat, row, col, rowsize) =>
array.get(mat, int(rowsize * row + col))
//Setter Function For Pseudo 2D Matrix
set_val(mat, row, col, rowsize, val) =>
array.set(mat, int(rowsize * row + col), val)
//LU Decomposition Function
LU(A, B) =>
A_size = array.size(A)
B_size = array.size(B)
var L = array.new_float(A_size)
var U = array.new_float(A_size)
L_temp = 0.0
U_temp = 0.0
for c = 0 to B_size - 1 by 1
set_val(U, 0, c, B_size, get_val(A, 0, c, B_size))
for r = 1 to B_size - 1 by 1
set_val(L, r, 0, B_size, get_val(A, r, 0, B_size) / get_val(U, 0, 0, B_size))
for r = 0 to B_size - 1 by 1
for c = 0 to B_size - 1 by 1
if r == c
set_val(L, r, c, B_size, 1)
if r < c
set_val(L, r, c, B_size, 0)
if r > c
set_val(U, r, c, B_size, 0)
for r = 0 to B_size - 1 by 1
for c = 0 to B_size - 1 by 1
if na(get_val(L, r, c, B_size))
L_temp := get_val(A, r, c, B_size)
for k = 0 to math.max(c - 1, 0) by 1
L_temp -= get_val(U, k, c, B_size) * get_val(L, r, k, B_size)
L_temp
set_val(L, r, c, B_size, L_temp / get_val(U, c, c, B_size))
if na(get_val(U, r, c, B_size))
U_temp := get_val(A, r, c, B_size)
for k = 0 to math.max(r - 1, 0) by 1
U_temp -= get_val(U, k, c, B_size) * get_val(L, r, k, B_size)
U_temp
set_val(U, r, c, B_size, U_temp)
[L, U]
//Lower Triangular Solution Function (Forward Substitution)
LT_solve(L_, B) =>
B_size = array.size(B)
var Y = array.new_float(B_size)
Y_temp = 0.0
array.set(Y, 0, array.get(B, 0) / get_val(L_, 0, 0, B_size))
for r = 1 to B_size - 1 by 1
Y_temp := array.get(B, r)
for k = 0 to math.max(r - 1, 0) by 1
Y_temp -= get_val(L_, r, k, B_size) * array.get(Y, k)
Y_temp
array.set(Y, r, Y_temp / get_val(L_, r, r, B_size))
Y
//Upper Triangular Solution Function (Backward Substitution)
UT_solve(U_, Y_) =>
Y_size = array.size(Y_)
U_rev = array.copy(U_)
Y_rev = array.copy(Y_)
array.reverse(U_rev)
array.reverse(Y_rev)
X_rev = LT_solve(U_rev, Y_rev)
X = array.copy(X_rev)
array.reverse(X)
X
//Regression Function
regression_val(X_, index_, order_, offset_) =>
reg = 0.0
for i = 0 to order_ by 1
reg += array.get(X_, i) * math.pow(index_ - offset_, i)
reg
reg
//Curve Segment Drawing Function
draw_curve(Y, sdev, n, step_, col, ls, lw, draw, conf) =>
var line segment = line.new(x1=time[n * step_], y1=array.get(Y, n) + sdev, x2=time[(n - 1) * step_], y2=array.get(Y, n - 1) + sdev, xloc=xloc.bar_time)
if draw
if conf ? barstate.isconfirmed : 1
line.set_xy1(segment, time[n * step_], array.get(Y, n) + sdev)
line.set_xy2(segment, time[(n - 1) * step_], array.get(Y, n - 1) + sdev)
line.set_color(segment, col)
line.set_width(segment, lw)
line.set_style(segment, ls == 'Solid' ? line.style_solid : ls == 'Dotted' ? line.style_dotted : line.style_dashed)
else
line.delete(segment)
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Source Inputs
src = input(defval=close, title='Input Source Value')
use_filt = input(defval=true, title='Smooth Data Before Curve Fitting')
filt_per = input.int(defval=10, minval=2, title='Data Smoothing Period ═══════════════════')
//Calculation Inputs
per = input.int(defval=50, minval=2, title='Regression Sample Period')
order = input.int(defval=2, minval=1, title='Polynomial Order')
calc_offs = input(defval=0, title='Regression Offset')
ndev = input.float(defval=2.0, minval=0, title='Width Coefficient')
equ_from = input.int(defval=0, minval=0, title='Forecast From _ Bars Ago ═══════════════════')
//Channel Display Inputs
show_curve = input(defval=true, title='Show Fitted Curve')
show_high = input(defval=true, title='Show Fitted Channel High')
show_low = input(defval=true, title='Show Fitted Channel Low')
draw_step1 = input.int(defval=10, minval=1, title='Curve Drawing Step Size')
auto_step = input(defval=true, title='Auto Decide Step Size Instead')
draw_freq = input.string(defval='Close Only', options=['Continuous', 'Close Only'], title='Curve Update Frequency')
poly_col_h = input(defval=color.yellow, title='Channel High Line Color')
poly_lw_h = input.int(defval=1, minval=1, title='Channel High Line Width')
poly_ls_h = input.string(defval='Dashed', options=['Solid', 'Dotted', 'Dashed'], title='Channel High Line Style')
poly_col_m = input(defval=color.rgb(255, 235, 59, 100), title='Channel Middle Line Color')
poly_lw_m = input.int(defval=1, minval=1, title='Channel Middle Line Width')
poly_ls_m = input.string(defval='Dotted', options=['Solid', 'Dotted', 'Dashed'], title='Channel Middle Line Style')
poly_col_l = input(defval=color.yellow, title='Channel Low Line Color')
poly_lw_l = input.int(defval=1, minval=1, title='Channel Low Line Width')
poly_ls_l = input.string(defval='Dashed', options=['Solid', 'Dotted', 'Dashed'], title='Channel Low Line Style ═══════════════════')
//Smooth data and determine source type for calculation.
filt = SSF(src, filt_per)
src1 = use_filt ? filt : src
//Populate a period sized array with bar values.
var x_vals = array.new_float(per)
for i = 0 to per - 1 by 1
array.set(x_vals, i, i + 1)
//Populate a period sized array with historical source values.
var src_vals = array.new_float(per)
for i = 0 to per - 1 by 1
array.set(src_vals, i, src1[per - 1 - i + equ_from])
//Populate an order*2 + 1 sized array with bar power sums.
var xp_sums = array.new_float(order * 2 + 1)
xp_sums_temp = 0.0
for i = 0 to order * 2 by 1
xp_sums_temp := 0
for j = 0 to per - 1 by 1
xp_sums_temp += math.pow(array.get(x_vals, j), i)
xp_sums_temp
array.set(xp_sums, i, xp_sums_temp)
//Populate an order + 1 sized array with (bar power)*(source value) sums.
var xpy_sums = array.new_float(order + 1)
xpy_sums_temp = 0.0
for i = 0 to order by 1
xpy_sums_temp := 0
for j = 0 to per - 1 by 1
xpy_sums_temp += math.pow(array.get(x_vals, j), i) * array.get(src_vals, j)
xpy_sums_temp
array.set(xpy_sums, i, xpy_sums_temp)
//Generate a pseudo square matrix with row and column sizes of order + 1 using bar power sums.
var xp_matrix = array.new_float(int(math.pow(order + 1, 2)))
for r = 0 to order by 1
for c = 0 to order by 1
set_val(xp_matrix, r, c, order + 1, array.get(xp_sums, r + c))
//Factor the power sum matrix into lower and upper triangular matrices with order + 1 rows and columns.
[lower, upper] = LU(xp_matrix, xpy_sums)
//Find lower triangular matrix solutions using (bar power)*(source value) sums.
l_solutions = LT_solve(lower, xpy_sums)
//Find upper triangular matrix solutions using lower matrix solutions. This gives us our regression coefficients.
reg_coefs = UT_solve(upper, l_solutions)
//Define curve drawing step size.
draw_step = auto_step ? math.ceil(per / 10) : draw_step1
//Calculate curve values.
var inter_vals = array.new_float(11)
for i = 0 to 10 by 1
array.set(inter_vals, i, regression_val(reg_coefs, per, order, calc_offs - equ_from + draw_step * i))
//Calculate standard deviation for channel.
Stdev = array.stdev(src_vals) * ndev
//Draw interpolated segments.
draw_curve(inter_vals, 0, 1, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 2, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 3, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 4, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 5, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 6, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 7, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 8, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 9, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 10, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
//Draw channel high segments.
draw_curve(inter_vals, Stdev, 1, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 2, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 3, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 4, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 5, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 6, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 7, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 8, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 9, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 10, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
//Draw channel low segments.
draw_curve(inter_vals, -Stdev, 1, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 2, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 3, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 4, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 5, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 6, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 7, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 8, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 9, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 10, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
//END
bu kodla...strateji testi yapıp...kendinize en uygun...psar değerini bulabilirsiniz....
ben içine bir değer yerleştirdim.....ortalama yüzde 27 ile sonuç verdi....
PHP Code:
//@version=5
strategy("*", overlay=true)
start = input(0.05)
increment = input(0.075)
maximum = input(0.35)
var bool uptrend = na
var float EP = na
var float SAR = na
var float AF = start
var float nextBarSAR = na
if bar_index > 0
firstTrendBar = false
SAR := nextBarSAR
if bar_index == 1
float prevSAR = na
float prevEP = na
lowPrev = low[1]
highPrev = high[1]
closeCur = close
closePrev = close[1]
if closeCur > closePrev
uptrend := true
EP := high
prevSAR := lowPrev
prevEP := high
else
uptrend := false
EP := low
prevSAR := highPrev
prevEP := low
firstTrendBar := true
SAR := prevSAR + start * (prevEP - prevSAR)
if uptrend
if SAR > low
firstTrendBar := true
uptrend := false
SAR := math.max(EP, high)
EP := low
AF := start
else
if SAR < high
firstTrendBar := true
uptrend := true
SAR := math.min(EP, low)
EP := high
AF := start
if not firstTrendBar
if uptrend
if high > EP
EP := high
AF := math.min(AF + increment, maximum)
else
if low < EP
EP := low
AF := math.min(AF + increment, maximum)
if uptrend
SAR := math.min(SAR, low[1])
if bar_index > 1
SAR := math.min(SAR, low[2])
else
SAR := math.max(SAR, high[1])
if bar_index > 1
SAR := math.max(SAR, high[2])
nextBarSAR := SAR + AF * (EP - SAR)
if barstate.isconfirmed
if uptrend
strategy.entry("ParSE", strategy.short, stop=nextBarSAR, comment="Sat")
strategy.cancel("ParLE")
else
strategy.entry("ParLE", strategy.long, stop=nextBarSAR, comment="Al")
strategy.cancel("ParSE")
plot(SAR, style=plot.style_line, linewidth=1, color=color.orange)
plot(nextBarSAR, style=plot.style_line, linewidth=1, color=color.aqua)
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
50lik parabol içine 50lik regrasyon birleştirerek....
bar renklendirme....mavi barlar...trend kararsızlığı....https://www.tradingview.com/x/dbWgpgbJ/
işlem alanı parabol içi....parabol kullanım aynı...yukarda anlattığım gibi düşünülür...
denemek isteyene kodu....
PHP Code:
// © OmegaTools
//@version=5
indicator("Linear Regression", overlay = true)
import TradingView/ta/5
lnt = input(50, "Lenght")
lnt2 = lnt * 2
off = input(1, "Offset")
reg = ta.linreg(close, lnt, 0)
reg2 = ta.linreg(close, lnt2, 0)
regavg = math.avg(reg, reg2)
barc = reg > reg[1] and reg2 > reg2[1] ? #79f504 : reg < reg[1] and reg2 < reg2[1] ? #e91e63 : color.rgb(11, 7, 236)
barcolor(barc, 0, true, title = "Bar Color")
plot(regavg, "Regression line", color.white, 1, plot.style_line, offset = off)
//End
//2 Pole Super Smoother Function
SSF(x, t) =>
omega = 2 * math.atan(1) * 4 / t
a = math.exp(-math.sqrt(2) * math.atan(1) * 4 / t)
b = 2 * a * math.cos(math.sqrt(2) / 2 * omega)
c2 = b
c3 = -math.pow(a, 2)
c1 = 1 - c2 - c3
SSF = 0.0
SSF := c1 * x + c2 * nz(SSF[1], x) + c3 * nz(SSF[2], nz(SSF[1], x))
SSF
//Getter Function For Pseudo 2D Matrix
get_val(mat, row, col, rowsize) =>
array.get(mat, int(rowsize * row + col))
//Setter Function For Pseudo 2D Matrix
set_val(mat, row, col, rowsize, val) =>
array.set(mat, int(rowsize * row + col), val)
//LU Decomposition Function
LU(A, B) =>
A_size = array.size(A)
B_size = array.size(B)
var L = array.new_float(A_size)
var U = array.new_float(A_size)
L_temp = 0.0
U_temp = 0.0
for c = 0 to B_size - 1 by 1
set_val(U, 0, c, B_size, get_val(A, 0, c, B_size))
for r = 1 to B_size - 1 by 1
set_val(L, r, 0, B_size, get_val(A, r, 0, B_size) / get_val(U, 0, 0, B_size))
for r = 0 to B_size - 1 by 1
for c = 0 to B_size - 1 by 1
if r == c
set_val(L, r, c, B_size, 1)
if r < c
set_val(L, r, c, B_size, 0)
if r > c
set_val(U, r, c, B_size, 0)
for r = 0 to B_size - 1 by 1
for c = 0 to B_size - 1 by 1
if na(get_val(L, r, c, B_size))
L_temp := get_val(A, r, c, B_size)
for k = 0 to math.max(c - 1, 0) by 1
L_temp -= get_val(U, k, c, B_size) * get_val(L, r, k, B_size)
L_temp
set_val(L, r, c, B_size, L_temp / get_val(U, c, c, B_size))
if na(get_val(U, r, c, B_size))
U_temp := get_val(A, r, c, B_size)
for k = 0 to math.max(r - 1, 0) by 1
U_temp -= get_val(U, k, c, B_size) * get_val(L, r, k, B_size)
U_temp
set_val(U, r, c, B_size, U_temp)
[L, U]
//Lower Triangular Solution Function (Forward Substitution)
LT_solve(L_, B) =>
B_size = array.size(B)
var Y = array.new_float(B_size)
Y_temp = 0.0
array.set(Y, 0, array.get(B, 0) / get_val(L_, 0, 0, B_size))
for r = 1 to B_size - 1 by 1
Y_temp := array.get(B, r)
for k = 0 to math.max(r - 1, 0) by 1
Y_temp -= get_val(L_, r, k, B_size) * array.get(Y, k)
Y_temp
array.set(Y, r, Y_temp / get_val(L_, r, r, B_size))
Y
//Upper Triangular Solution Function (Backward Substitution)
UT_solve(U_, Y_) =>
Y_size = array.size(Y_)
U_rev = array.copy(U_)
Y_rev = array.copy(Y_)
array.reverse(U_rev)
array.reverse(Y_rev)
X_rev = LT_solve(U_rev, Y_rev)
X = array.copy(X_rev)
array.reverse(X)
X
//Regression Function
regression_val(X_, index_, order_, offset_) =>
reg = 0.0
for i = 0 to order_ by 1
reg += array.get(X_, i) * math.pow(index_ - offset_, i)
reg
reg
//Curve Segment Drawing Function
draw_curve(Y, sdev, n, step_, col, ls, lw, draw, conf) =>
var line segment = line.new(x1=time[n * step_], y1=array.get(Y, n) + sdev, x2=time[(n - 1) * step_], y2=array.get(Y, n - 1) + sdev, xloc=xloc.bar_time)
if draw
if conf ? barstate.isconfirmed : 1
line.set_xy1(segment, time[n * step_], array.get(Y, n) + sdev)
line.set_xy2(segment, time[(n - 1) * step_], array.get(Y, n - 1) + sdev)
line.set_color(segment, col)
line.set_width(segment, lw)
line.set_style(segment, ls == 'Solid' ? line.style_solid : ls == 'Dotted' ? line.style_dotted : line.style_dashed)
else
line.delete(segment)
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Source Inputs
src = input(defval=close, title='Input Source Value')
use_filt = input(defval=true, title='Smooth Data Before Curve Fitting')
filt_per = input.int(defval=10, minval=2, title='Data Smoothing Period ═══════════════════')
//Calculation Inputs
per = input.int(defval=50, minval=2, title='Regression Sample Period')
order = input.int(defval=2, minval=1, title='Polynomial Order')
calc_offs = input(defval=0, title='Regression Offset')
ndev = input.float(defval=2.0, minval=0, title='Width Coefficient')
equ_from = input.int(defval=0, minval=0, title='Forecast From _ Bars Ago ═══════════════════')
//Channel Display Inputs
show_curve = input(defval=true, title='Show Fitted Curve')
show_high = input(defval=true, title='Show Fitted Channel High')
show_low = input(defval=true, title='Show Fitted Channel Low')
draw_step1 = input.int(defval=10, minval=1, title='Curve Drawing Step Size')
auto_step = input(defval=true, title='Auto Decide Step Size Instead')
draw_freq = input.string(defval='Close Only', options=['Continuous', 'Close Only'], title='Curve Update Frequency')
poly_col_h = input(defval=color.yellow, title='Channel High Line Color')
poly_lw_h = input.int(defval=1, minval=1, title='Channel High Line Width')
poly_ls_h = input.string(defval='Dashed', options=['Solid', 'Dotted', 'Dashed'], title='Channel High Line Style')
poly_col_m = input(defval=color.rgb(255, 235, 59, 100), title='Channel Middle Line Color')
poly_lw_m = input.int(defval=1, minval=1, title='Channel Middle Line Width')
poly_ls_m = input.string(defval='Dotted', options=['Solid', 'Dotted', 'Dashed'], title='Channel Middle Line Style')
poly_col_l = input(defval=color.yellow, title='Channel Low Line Color')
poly_lw_l = input.int(defval=1, minval=1, title='Channel Low Line Width')
poly_ls_l = input.string(defval='Dashed', options=['Solid', 'Dotted', 'Dashed'], title='Channel Low Line Style ═══════════════════')
//Smooth data and determine source type for calculation.
filt = SSF(src, filt_per)
src1 = use_filt ? filt : src
//Populate a period sized array with bar values.
var x_vals = array.new_float(per)
for i = 0 to per - 1 by 1
array.set(x_vals, i, i + 1)
//Populate a period sized array with historical source values.
var src_vals = array.new_float(per)
for i = 0 to per - 1 by 1
array.set(src_vals, i, src1[per - 1 - i + equ_from])
//Populate an order*2 + 1 sized array with bar power sums.
var xp_sums = array.new_float(order * 2 + 1)
xp_sums_temp = 0.0
for i = 0 to order * 2 by 1
xp_sums_temp := 0
for j = 0 to per - 1 by 1
xp_sums_temp += math.pow(array.get(x_vals, j), i)
xp_sums_temp
array.set(xp_sums, i, xp_sums_temp)
//Populate an order + 1 sized array with (bar power)*(source value) sums.
var xpy_sums = array.new_float(order + 1)
xpy_sums_temp = 0.0
for i = 0 to order by 1
xpy_sums_temp := 0
for j = 0 to per - 1 by 1
xpy_sums_temp += math.pow(array.get(x_vals, j), i) * array.get(src_vals, j)
xpy_sums_temp
array.set(xpy_sums, i, xpy_sums_temp)
//Generate a pseudo square matrix with row and column sizes of order + 1 using bar power sums.
var xp_matrix = array.new_float(int(math.pow(order + 1, 2)))
for r = 0 to order by 1
for c = 0 to order by 1
set_val(xp_matrix, r, c, order + 1, array.get(xp_sums, r + c))
//Factor the power sum matrix into lower and upper triangular matrices with order + 1 rows and columns.
[lower, upper] = LU(xp_matrix, xpy_sums)
//Find lower triangular matrix solutions using (bar power)*(source value) sums.
l_solutions = LT_solve(lower, xpy_sums)
//Find upper triangular matrix solutions using lower matrix solutions. This gives us our regression coefficients.
reg_coefs = UT_solve(upper, l_solutions)
//Define curve drawing step size.
draw_step = auto_step ? math.ceil(per / 10) : draw_step1
//Calculate curve values.
var inter_vals = array.new_float(11)
for i = 0 to 10 by 1
array.set(inter_vals, i, regression_val(reg_coefs, per, order, calc_offs - equ_from + draw_step * i))
//Calculate standard deviation for channel.
Stdev = array.stdev(src_vals) * ndev
//Draw interpolated segments.
draw_curve(inter_vals, 0, 1, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 2, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 3, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 4, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 5, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 6, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 7, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 8, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 9, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
draw_curve(inter_vals, 0, 10, draw_step, poly_col_m, poly_ls_m, poly_lw_m, show_curve, draw_freq == 'Close Only')
//Draw channel high segments.
draw_curve(inter_vals, Stdev, 1, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 2, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 3, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 4, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 5, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 6, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 7, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 8, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 9, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
draw_curve(inter_vals, Stdev, 10, draw_step, poly_col_h, poly_ls_h, poly_lw_h, show_high, draw_freq == 'Close Only')
//Draw channel low segments.
draw_curve(inter_vals, -Stdev, 1, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 2, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 3, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 4, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 5, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 6, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 7, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 8, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 9, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
draw_curve(inter_vals, -Stdev, 10, draw_step, poly_col_l, poly_ls_l, poly_lw_l, show_low, draw_freq == 'Close Only')
//END
bunu yaptığınızda...
farklı periyotlar için farklı değerlerin....
ve bunları birbiriyle ilişkilendirdiğinizde...
farklı döngüler elde edebilirsiniz.....
örnek...farklı 12 psar değerini hesaplatıp...ortalamasını çekerseniz.....
https://www.tradingview.com/x/7pcyt7yn/ görüntü bu...
denemek isteyene kodu...
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
//@version=5
indicator("*", overlay = true)
//Sar Functıons
x1= ta.sar(0.01, 0.01, 0.1)
x2 = ta.sar(0.01, 0.02, 0.1)
x3= ta.sar(0.01, 0.03, 0.1)
x4= ta.sar(0.01, 0.02, 0.2)
x5= ta.sar(0.01, 0.04, 0.2)
x6= ta.sar(0.02, 0.02, 0.2)
x7= ta.sar(0, 0.1, 1)
x8= ta.sar(0, 0.01, 1)
x9= ta.sar(0, 0.01, 0.2)
x10= ta.sar(0.1, 0, 0.2)
x11= ta.sar(0.1, 0.1, 0.1)
x12= ta.sar(0.05, 0.075, 0.35)
reverseavg=(x1+x2+x3+x4+x5+x6+x7+x8+x9+x10+x11+x12)/12
plot(reverseavg, title='Sar Ortalamaları', style=plot.style_stepline, linewidth=2)
bir noktadan sonsuz doğru geçirme...
ve ya
bir noktaya eşit uzaklıklar....
matematik sembolü daire....
daire....döngü denilirse....
döngülerin hakikatı...aslına rucudur....
şimdi...
herhangi bir değeri...tüm periyotlara ilişkilendirip....
ortalama alma örneği.....
örnekte psar kullanıldı.... renklendirme 15lik periyotla ilişkilendirirldi......
https://www.tradingview.com/x/dcaAeX5M/
denemek isteyene örnek kod.....
PHP Code:
//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
indicator('*', overlay=true)
//resolution
x1 = input.timeframe('1', title='Resolution')
x3 = input.timeframe('3', title='Resolution')
x5 = input.timeframe('5', title='Resolution')
x15 = input.timeframe('15', title='Resolution')
x30 = input.timeframe('30', title='Resolution')
x45 = input.timeframe('45', title='Resolution')
x60 = input.timeframe('60', title='Resolution')
x120 = input.timeframe('120', title='Resolution')
x180 = input.timeframe('180', title='Resolution')
x240 = input.timeframe('240', title='Resolution')
x720 = input.timeframe('D', title='Resolution')
//output functions
z = ta.sar(0.05, 0.075, 0.35)
// Security
y1 = request.security(syminfo.tickerid, x1, z)
y3 = request.security(syminfo.tickerid, x3, z)
y5 = request.security(syminfo.tickerid, x5, z)
y15 = request.security(syminfo.tickerid, x15, z)
y30 = request.security(syminfo.tickerid, x30, z)
y45 = request.security(syminfo.tickerid, x45, z)
y60 = request.security(syminfo.tickerid, x60, z)
y120 = request.security(syminfo.tickerid, x120, z)
y180 = request.security(syminfo.tickerid, x180, z)
y240 = request.security(syminfo.tickerid, x240, z)
y720 = request.security(syminfo.tickerid, x720, z)
//Plots
xz = input(true, title='Adaptive Coloring')
//plot(y1, title="1", style=circles, color=xz?(y1>close?red:lime) : silver, transp=100, linewidth=1)
//plot(y3, title="3", style=circles, color=xz?(y3>close?red:lime) : silver, transp=100, linewidth=1)
//plot(y5, title="5", style=circles, color=xz?(y5>close?red:lime) : silver, transp=100, linewidth=1)
//plot(y15, title="15", style=circles, color=xz?(y15>close?red:lime) : silver, transp=100, linewidth=1)
//plot(y30, title="30", style=circles, color=xz?(y30>close?red:lime) : silver, transp=100, linewidth=1)
//plot(y45, title="45", style=circles, color=xz?(y45>close?red:lime) : silver, transp=100, linewidth=1)
//plot(y60, title="60", style=circles, color=xz?(y60>close?red:lime) : silver, transp=100, linewidth=1)
//plot(y120, title="120", style=circles, color=xz?(y120>close?red:lime) : silver, transp=100, linewidth=1)
//plot(y180, title="180", style=circles, color=xz?(y180>close?red:lime) : silver, transp=100, linewidth=1)
//plot(y240, title="240", style=circles, color=xz?(y240>close?red:lime) : silver, transp=100, linewidth=1)
//plot(y720, title="720", style=circles, color=xz?(y720>close?red:lime) : silver, transp=100, linewidth=1)
xyzq = (y1 + y3 + y5 + y15 + y30 + y45 + y60 + y120 + y180 + y240 + y720 ) / 11
plot(xyzq, title='tüm periyotlar ortalaması', style=plot.style_linebr, color=xz ? y15 > close ? color.red : color.lime : color.silver, linewidth=2)