-
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...
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")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
değerler oynandığı için....
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....
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)
https://www.tradingview.com/x/Uu09kCfD/
-
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)