derlemede stratejiye bağlı örnek sistem derlemeleri
örnek görüntü https://www.tradingview.com/x/LHIlBVqs/
kod örneği
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Vallahualem
//@version=4
study("Sequentially Filter","*",true)
length = input(14),src = input(close)
//----
sum = 0.
filt = 0.
//----
ma = sma(src,length)
a = sign(change(ma))
for i = 0 to length-1
sum := sum + a[i]
alpha = abs(sum) == length ? 1 : 0
filt := alpha*ma+(1-alpha)*nz(filt[1],ma)
//----
css = filt > filt[1] ? #2157f3 : filt < filt[1] ? #2157f3 : na
plot(filt,"SayımStop9",fixnan(css),1,transp=0)
lengthx = input(3),srcx = input(close)
sumx = 0.
filtx = 0.
//----
max = sma(srcx,lengthx)
ax = sign(change(max))
for i = 0 to lengthx-1
sumx := sumx + ax[i]
alphax = abs(sumx) == lengthx ? 1 : 0
filtx := alphax*max+(1-alphax)*nz(filtx[1],max)
//----
cssx = filtx > filtx[1] ? #FFEB3B : filtx < filtx[1] ? #FFEB3B : na
plot(filtx,"İzSürenStop",fixnan(cssx),1,transp=0)
ema1 = input(14, minval=1, maxval=240, title="EMA UpTrend")
shema = input(true, title="Show EMA Trend is Based On?")
usedEma = ema(close, ema1)
emaUpColor() => hlc3 >= usedEma
emaDownColor() => hlc3 < usedEma
plot(shema and usedEma ? usedEma : na, title="SayımStop13", linewidth=1 )
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Vallahualem
//@version=4
lb = input(50, title="Left Bars", minval=1)
rb = input(20, title="Right Bars", minval=1)
showpivot = input(true, title="Show Pivot Points")
chdashed = input(true, title="Show Old Line as Dashed")
ucolor = input(defval = color.lime, title = "Uptrend line color")
dcolor = input(defval = color.red, title = "Downtrend line color")
mb = lb + rb + 1
float top = na
float bot = na
top := iff(not na(high[mb]), iff(highestbars(high, mb) == -rb, high[rb], na), na) // Pivot High
bot := iff(not na(low[mb]), iff(lowestbars(low, mb) == -rb, low[rb], na), na) // Pivot Low
plotshape(top and showpivot, text="Sat", style=shape.labeldown, color=color.yellow, textcolor=color.black, location=location.abovebar, offset = -rb)
plotshape(bot and showpivot, text="Al", style=shape.labeldown, color=color.yellow, textcolor=color.black, location=location.belowbar, offset = -rb)
ltop = valuewhen(top, top, 1)
bst = 0
bst := top ? 1 : nz(bst[1]) + 1
float t_angle = 0.0
t_angle := t_angle[1]
if not na(ltop) and not na(top)
line tline = na
if ltop > top
tline := line.new(bar_index - bst[1] - rb, high[bst[1] + rb], bar_index - rb, high[rb], color = dcolor, extend = extend.right)
t_angle := (high[bst[1] + rb] - high[rb]) / bst[1]
if t_angle < t_angle[1] and t_angle[1] != 0
line.set_extend(tline[1], extend = extend.none)
if t_angle > t_angle[1] and t_angle[1] != 0
line.set_extend(tline, extend = extend.none)
if ltop <= top
t_angle := 0.0
if chdashed
line.set_style(tline[1], style = line.style_dashed)
lbot = valuewhen(bot, bot, 1)
bsb = 0
bsb := bot ? 1 : nz(bsb[1]) + 1
float b_angle = 0.0
b_angle := b_angle[1]
if not na(lbot) and not na(bot)
line bline = na
if lbot < bot
bline := line.new(bar_index - bsb[1] - rb, low[bsb[1] + rb], bar_index - rb, low[rb], color = ucolor, extend = extend.right)
b_angle := (low[bsb[1] + rb] - low[rb]) / bsb[1]
if b_angle > b_angle[1] and b_angle[1] != 0
line.set_extend(bline[1], extend = extend.none)
if b_angle < b_angle[1] and b_angle[1] != 0
line.set_extend(bline, extend = extend.none)
if lbot >= bot
b_angle := 0.0
if chdashed
line.set_style(bline[1], style = line.style_dashed)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Vallahualem
// @version = 4
//////////////////////////////////////////////////////////////////////////////
// Inputs and global variable declarations
i_srcPrice = input ( close, "SMI Price Source", input.source )
i_SMI_len = input ( 4, "SMI Length", input.integer, minval = 1 )
i_smth1 = input ( 8, "Smooth Length 1", input.integer, minval = 1 )
i_smth2 = input ( 2, "Smooth Length 2", input.integer, minval = 1 )
i_sigLen = input ( 32, "Signal Length", input.integer, minval = 1 )
i_alrtInfo = input ( true, "Show Alert Levels Info", input.bool )
i_alrtHi = input ( 40, "Upper Alert Level", input.float, minval = -100, maxval = 100)
i_midLine = input ( 0, "Midline", input.integer, minval = -100, maxval = 100)
i_alrtLo = input ( -40, "Lower Alert Level", input.float, minval = -100, maxval = 100)
i_alrtLines = input ( false, "Show Alert Level Lines", input.bool )
i_infoBox = input ( true, "Show Info Box", input.bool )
i_decimalP = input ( 2, "Prices Decimal Places", input.integer, minval = 0, maxval = 10)
i_boxOffSet = input ( 5, "Info Box Offset", input.integer, minval = 1, maxval = 50)
ScaleHi = 100
ScaleLo = -100
var label Infobox = na
///////////////////////////////////////////////////////////////////////////////
// Declare Functions
f_truncdNum ( Val, DecPl ) =>
Fact = pow ( 10, DecPl )
int( Val * Fact) / Fact
// decimal truncation
a11(x) => 2 / (x + 1)
// exponentially weighted multiplier
f_reverse_SMI ( P, U, W, X, Y, Z ) =>
V = 0.5
H = highest(W)
L = lowest(W)
D = ema (( P - V * ( H + L )), X )[1]
E = ema ((( a11(X)* ( P - V * ( H + L )))+( D -D*a11(X))), Y )[1]
F = ema ( H - L , X )[1]
G = ema ((( a11(X)*( H -L ) + F*( 1 -a11(X)))), Y )[1]
J = 100 * (( a11(Y)* ( ( a11(X)* ( P - V * ( H + L ))) + ( D - D*a11(X)))) + ( E * ( 1 -a11(Y)) )) / ( V * (a11(Y)*((a11(X)*( H -L ) + F*( 1 -a11(X)))) + ( G*( 1 -a11(Y)))))[1]
K = ema ( ( 100 * (( a11(Y)* ( ( a11(X)* ( P - V * ( H + L ))) + ( D - D*a11(X)))) + ( E * ( 1 -a11(Y)) )) / ( V * (a11(Y)*((a11(X)*( H -L ) + F*( 1 -a11(X)))) + ( G*( 1 -a11(Y)))))), Z )[1]
rawReturn = ( V*U*(a11(Y)*a11(X)*H -a11(Y)*a11(X)*L -a11(Y)*F*a11(X) +a11(Y)*F -G*a11(Y) + G) + 100*(a11(Y)*a11(X)*V*H +a11(Y)*a11(X)*V*L -a11(Y)*D +a11(Y)*D*a11(X) +E*a11(Y) -E)) / ( 100*a11(Y)*a11(X))
return = rawReturn > 0 ? rawReturn : 0
// returns price where Stochastic Momentum Index is equal to input value "U"
// e.g. f_reverse_SMI ( close, 0, 13, 25, 2, 12 )
// would return the next closing price which would make SMI = 0
// the user can infer from this that.....
// closing above this price will cause the Stochastic Momentum Index to cross above the mid line
// and closing below it will cause the Stochastic Momentum Index to cross below the mid line
// This may also be used to give the SMI eq price (the price which would make the SMI equal to its prior value)
// this is done by inputing the prior value of the SMI (SMI[1]) as the "U" value
// e.g. f_reverse_SMI ( close, SMI[1], 13, 25, 2, 12 )
// The user can infer from this that.....
// closing above this price will cause the Stochastic Momentum Index to increase
// and closing below it will cause the Stochastic Momentum Index to decrease
// has a Return filter to replace any values below zero with zero
f_reverse_SMI_cross ( P, W, X, Y, Z ) =>
V = 0.5
H = highest(W)
L = lowest(W)
D = ema (( P - V * ( H + L )), X )[1]
E = ema (((a11(X)* ( P - V * ( H + L )))+( D -D*a11(X))), Y )[1]
F = ema ( H - L , X )[1]
G = ema (((a11(X)*( H -L ) + F*( 1 -a11(X)))), Y )[1]
J = 100 * (( a11(Y)* ( ( a11(X)* ( P - V * ( H + L ))) + ( D - D*a11(X)))) + ( E * ( 1 -a11(Y)) )) / ( V * (a11(Y)*((a11(X)*( H -L ) + F*( 1 -a11(X)))) + ( G*( 1 -a11(Y)))))[1]
K = ema ( ( 100 * (( a11(Y)* ( ( a11(X)* ( P - V * ( H + L ))) + ( D - D*a11(X)))) + ( E * ( 1 -a11(Y)) )) / ( V * (a11(Y)*((a11(X)*( H -L ) + F*( 1 -a11(X)))) + ( G*( 1 -a11(Y)))))), Z )[1]
rawReturn = ( a11(Y)*(100*( a11(Z)*(-a11(X)*V*H -a11(X)*V*L +D -D*a11(X) -a11(X) -E) +a11(X)*V*H +a11(X)*V*L -D +D*a11(X) +E) +V*K*(a11(X)*(-H*a11(Z) +H +L*a11(Z) -L +F*a11(Z) -F) -F*a11(Z) +F +G*a11(Z) -G)) +100*(a11(Z)*E-E) -V*K*G*a11(Z) +V*K*G)/(100*a11(Y)*a11(X)*(-a11(Z)+1))
return = rawReturn > 0 ? rawReturn : 0
// returns price where Stochastic Momentum Index is equal to the signal line
// the user can infer from this that.....
// closing above this price will cause the Stochastic Momentum Index to cross above the signal line
// and closing below it will cause the Stochastic Momentum Index to cross below the signal line
// has a Return filter to replace any values below zero with zero
f_delta ( P, X ) => X - P > 0
f_negVal ( X, D ) => X > 0 ? tostring ( f_truncdNum ( X, D )) : "İmkansız"
text_eq ( p, x, d ) => p > x ? "Boğa Devam (eq) : " + tostring(int(x*pow(10,d))/pow(10,d)) : "Ayı Devam (Eq) :" + tostring(int(x*pow(10,d))/pow(10,d))
f_crossText ( P, X, T, D ) => f_delta ( P, X ) ? "Yukarı Kesme " + T + " : " + f_negVal ( X, D ) + "\n" : "Aşağı Kesme " + T + " : " + f_negVal ( X, D ) + "\n"
//////////////////////////////////////////////////////////////////////////////
// Calculations
SMINumerator = ema ( ema ( i_srcPrice - 0.5 * ( highest (i_SMI_len) + lowest (i_SMI_len)), i_smth1 ), i_smth2 )
SMIDenominator = 0.5 * ema ( ema ( highest (i_SMI_len) - lowest (i_SMI_len), i_smth1 ), i_smth2 )
SMI = 100 * SMINumerator / SMIDenominator
SMI_eq = f_reverse_SMI ( i_srcPrice, SMI[1], i_SMI_len, i_smth1, i_smth2, i_sigLen )
alrtHilineCross = f_reverse_SMI ( i_srcPrice, i_alrtHi, i_SMI_len, i_smth1, i_smth2, i_sigLen )
zerolineCross = f_reverse_SMI ( i_srcPrice, 0, i_SMI_len, i_smth1, i_smth2, i_sigLen )
alrtLolineCross = f_reverse_SMI ( i_srcPrice, i_alrtLo, i_SMI_len, i_smth1, i_smth2, i_sigLen )
signalCross = f_reverse_SMI_cross ( i_srcPrice, i_SMI_len, i_smth1, i_smth2, i_sigLen )
///////////////////////////////////////////////////////////////////////////////
// Compute Info Label
labelXLoc = time_close + ( i_boxOffSet * ( time_close - time_close[1] ) )
crossSignalText = f_crossText ( i_srcPrice, signalCross, "Sinyal", i_decimalP )
SMIeq = text_eq ( i_srcPrice, SMI_eq, i_decimalP )
crossZeroText = f_crossText ( i_srcPrice, zerolineCross, "0 Noktası", i_decimalP )
crossAlrtHiText = f_crossText ( i_srcPrice, alrtHilineCross, "Tepe Alarm", i_decimalP )
crossAlrtLoText = f_crossText ( i_srcPrice, alrtLolineCross, "Dip Alarm", i_decimalP )
infoBoxText = i_alrtInfo ? "Yörük\n\n" + SMIeq + "\n\n" + crossAlrtHiText + "\n" + crossSignalText + "\n" + crossZeroText + "\n" + crossAlrtLoText : "Yörük\n\n" + SMIeq + "\n\n" + crossSignalText + "\n" + crossZeroText
///////////////////////////////////////////////////////////////////////////////
// InfoBox Plot
if i_infoBox
Infobox := label.new ( labelXLoc, close, infoBoxText, xloc.bar_time, yloc.price, #000000ff, label.style_label_left, color.white )
label.delete ( Infobox[1] )
///////////////////////////////////////////////////////////////////////////////
// SMI Plots & Fills
p_alrtHiPlot = plot ( i_alrtLines ? alrtHilineCross : na, "High", color.**ua, 1, plot.style_linebr, transp = 100 )
p_alrtLoPlot = plot ( i_alrtLines ? alrtLolineCross : na, "Low ", color.purple, 1, plot.style_linebr, transp = 100 )
p_SMI_eqPlot = plot ( SMI_eq, "Durum", SMI_eq < i_srcPrice ? color.green: color.red, 2, plot.style_linebr, transp = 0)
p_smiPlot = plot ( signalCross, "SinyalTakip", signalCross < i_srcPrice ? #0ebb23 : #FF0000, 2, plot.style_linebr, transp = 100)
p_MidLinePlot = plot ( zerolineCross, "O Noktası", color.white, 1, plot.style_linebr, transp = 100)
///////////////////////////////////////////////////////////////////////////////
// End
örnek görüntü https://www.tradingview.com/x/hlIwzvCv/
kod örneği
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Vallahualem
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Vallahualem
//@version=3
// ÖZEL PSAR MTF
study("**", overlay=true)
start32 = input(0)
inc32 = input(0.1)
max32 = input(0.2)
start_232 = input(0.1)
inc_232 = input(0.02)
max_232 = input(0.2)
sar132 = sar(start32, inc32, max32)
sar232 = sar(start_232, inc_232, max_232)
y32= sar(0.07,0.07,0.2)
x32 = sar(0.01,0.01,0.2)
z32 = sar(0.03,0.03,0.2)
y5 = security(tickerid, '5', sar132)
y15 = security(tickerid, '15', sar132)
y60 = security(tickerid, '60', sar132)
y240 = security(tickerid, '240', sar132)
y480 = security(tickerid, '480', sar132)
yd = security(tickerid, 'D', sar132)
yw = security(tickerid, 'W', sar132)
acx32 = input(true, title="Adaptive Coloring", type=bool)
plot(y5, title="5Dakika", style=circles, color=acx32?(y5>high?red:yellow):silver, transp=100, linewidth=1)
plot(y15, title="15Dakika", style=circles, color=acx32?(y15>y5?red:yellow):silver, transp=100, linewidth=1)
plot(y60, title="Saatlik", style=circles, color=acx32?(y60>y15?red:yellow):silver, transp=100, linewidth=1)
plot(y240, title="Seanslık", style=circles, color=acx32?(y240>y60?red:yellow):silver, transp=100, linewidth=1)
plot(y480, title="ÇiftSeans", style=circles, color=acx32?(y480>y240?red:yellow):silver, transp=100, linewidth=1)
plot(yd, title="Günlük", style=circles, color=acx32?(yd>y480?red:yellow):silver, transp=100, linewidth=1)
plot(yw, title="Haftalık", style=circles, color=acx32?(yw>yd?red:yellow):silver, transp=100, linewidth=1)
plot(y32, title="Trend", style=circles, color=acx32?(y32>x32?redurple):silver, transp=100, linewidth=1)
plot(x32, title="Trend", style=circles, color=acx32?(x32>z32?redurple):silver, transp=100, linewidth=1)
plot(z32, title="Trend", style=circles, color=acx32?(z32>x32?redurple):silver, transp=100, linewidth=1)
//@version=2
s3232 = sar(0.0,0.01,0.2)
m3232 = sar(0.0,0.19,0.2)
f3232 = sar(0.0,0.001,0.2)
ac = input(true, title="Adaptive Coloring", type=bool)
plot(s3232, title="Olasılık2", style=circles, color=ac?(s3232>close?**ua:**ua):silver, transp=100, linewidth=1)
plot(m3232, title="Olasılık1", style=circles, color=ac?(m3232>close?**ua:**ua):silver, transp=100, linewidth=1)
plot(f3232, title="Olasılık3", style=circles, color=ac?(f3232>close?**ua:**ua):silver, transp=100, linewidth=1)
//Created By ChrisMoody on 7/25/2014
//Simply Enhances Default Parabolic SAR by creating Two Color Options, One for UpTrend, Other for DownTrend
//Ability To Turn On/Off The Up Trending Parabolic SAR, And The Down Trending Parabolic SAR
start44 = input(3, minval=0, maxval=10, title="Start - Default = 2 - Multiplied by .01")
increment44 = input(3, minval=0, maxval=10, title="Step Setting (Sensitivity) - Default = 2 - Multiplied by .01" )
maximum44 = input(3, minval=1, maxval=10, title="Maximum Step (Sensitivity) - Default = 2 - Multiplied by .10")
sus = input(true, "Show Up Trending Parabolic Sar")
sds = input(true, "Show Down Trending Parabolic Sar")
disc = input(false, title="Start and Step settings are *.01 so 2 = .02 etc, Maximum Step is *.10 so 2 = .2")
startCalc = start44 * .01
incrementCalc = increment44 * .01
maximumCalc = maximum44 * .10
sarUp = sar(startCalc, incrementCalc, maximumCalc)
sarDown = sar(startCalc, incrementCalc, maximumCalc)
colUp = close >= sarDown ? lime : na
colDown = close <= sarUp ? fuchsia : na
plot(sus and sarUp ? sarUp : na, title="Vurkaç Al", style=circles, linewidth=2,color=colUp)
plot(sds and sarDown ? sarDown : na, title="Vurkaç Sat", style=circles, linewidth=2,color=colDown)
sistem örneği https://www.tradingview.com/x/VR6Pz44y/
kod örneği
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Vallahualem
//@version=4
// The indicator has the following group of parameters:
//
// Control - Define how the control line (orage) is calulated.
// Threshold - Define the logic on how the thresholds (blue) are calculated.
// |- MINMAX - Use a sliding window with a fixed width in time to calculate the local minimum and maximum of every candle. Mim and Max values are the thresholds.
// |- SUBADD - Subtracts and adds the defined margins to the base line. Those values are the thresholds.
// MinMax Threshold - Define the sources of the min and max values and the time difference for the width of the sliding window.
// SubAdd Threshold - Define the base line and the margins.
// |- Base - The base line where the margins will be applied to calculate the thresholds when the SUBADD method is used.
// |- Margin - The method to calculate +- range values that will be added in the base to calculate the thresholds when the SUBADD method is used.
// Plot - Show and highlight some optional parameters and lines to avoid visual clutter.
//
// -----------------------------------------------------------------------------
// SETUP ================================================== ================================================== ========
study(title = "Trend Explorer",
shorttitle = "***",
overlay = true
)
//
// â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â– ’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â –’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’ â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â– ’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â –’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’ â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’
// INPUTS ================================================== ================================================== =======
ctrMethod = input(defval = "SRC", title = "Method", options = ["SRC", "AVG"], tooltip = "The method to calculate the control line.", group = "Control")
ctrBullTrendSrcType = input(defval = low, title = "Source Bull/Bear Type", type = input.source, inline = "Control Source Type", group = "Control")
ctrBearTrendSrcType = input(defval = high, title = "", type = input.source, tooltip = "The price to check for the bulish/bearish trend reversal.", inline = "Control Source Type", group = "Control")
ctrAvgType = input(defval = "VAR", title = "Average Type", options = ["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"], tooltip = "The method to calculate the moving average for control.", group = "Control")
ctrAvgSrc = input(defval = close, title = "Average Source", type = input.source, tooltip = "The source to calcultae the moving average for control.", group = "Control")
ctrLength = input(defval = 7, title = "Length", type = input.integer, tooltip = "How many candles back to calculate the moving average for control.", group = "Control")
threshMethod = input(defval = "MINMAX", title = "Method", options = ["SUBADD", "MINMAX"], tooltip = "The method to calculate the thresholds. Subtract and Add the margins to the base to get each boundary respectively. Or use the previous local maximum and minumum.", group = "Threshold")
minSrcType = input(defval = low, title = "Source Min/Max Type", type = input.source, inline = "MinMax Source Type", group = "MINMAX Threshold")
maxSrcType = input(defval = high, title = "", type = input.source, tooltip = "The price to use for the min/max calculation (bulish/bearish).", inline = "MinMax Source Type", group = "MINMAX Threshold")
minMaxWindowStartDate = input(defval = timestamp("01 Jun 2021 00:00 UTC+03:00"), title = "Sliding Window Start", type = input.time, tooltip = "Sliding window width is defined in time difference between start and end dates.", group = "MINMAX Threshold")
minMaxWindowEndDate = input(defval = timestamp("01 Sept 2021 00:00 UTC+03:00"), title = "Sliding Window End", type = input.time, tooltip = "Sliding window width is defined in time difference between start and end dates.", group = "MINMAX Threshold")
baseMethod = input(defval = "AVG", title = "Method", options = ["SRC", "AVG"], tooltip = "The method to calculate the base line.", group = "SUBADD Threshold - Base")
baseSource = input(defval = close, title = "Source", type = input.source, tooltip = "The source to be used for the base.", group = "SUBADD Threshold - Base")
baseAvgType = input(defval = "VAR", title = "Average Type", options = ["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"], tooltip = "The method to calculate the moving average for base.", group = "SUBADD Threshold - Base")
baseAvgSrc = input(defval = close, title = "Average Source", type = input.source, tooltip = "The source to calcultae the moving average for base.", group = "SUBADD Threshold - Base")
baseLength = input(defval = 14, title = "Length", type = input.integer, tooltip = "How many candles back to calculate the moving average and/or ATR for base/tolerance.", group = "SUBADD Threshold - Base")
marMethod = input(defval = "ATR", title = "Method", options = ["ATR", "PERC"], tooltip = "The method to calculate the tolerance.", group = "SUBADD Threshold - Margin")
marBullTrendPerc = input(defval = 15.0, title = "Margin Bull/Bear %", type = input.float, minval = 0.1, step = 0.1, inline = "Margin %", group = "SUBADD Threshold - Margin") / 100
marBearTrendPerc = input(defval = 15.0, title = "", type = input.float, minval = 0.1, step = 0.1, tooltip = "The Marginal Percentage to be added on top of the base line.", inline = "Margin %", group = "SUBADD Threshold - Margin") / 100
atrMethod = input(defval = "ATR", title = "ATR Method", options = ["ATR", "MATR"], tooltip = "The method to calculate ATR when length is greater than one.", group = "SUBADD Threshold - Margin")
atrBullTrendMultiplier = input(defval = 5.0, title = "ATR Bull/Bear Multplier", type = input.float, minval = 0.1, step = 0.1, inline = "ATR Multplier", group = "SUBADD Threshold - Margin")
atrBearTrendMultiplier = input(defval = 5.0, title = "", type = input.float, minval = 0.1, step = 0.1, tooltip = "ATR multiplier to be added on top of the base line.", inline = "ATR Multplier", group = "SUBADD Threshold - Margin")
showBase = input(defval = true, title = "Show Base", type = input.bool, tooltip = "Show the base line when threshold method is SUBADD.", group = "Plot")
showThresholds = input(defval = false, title = "Show Thresholds", type = input.bool, tooltip = "Show the threshold lines.", group = "Plot")
threshHighlighting = input(defval = true, title = "Show Threshold Highlighter", type = input.bool, tooltip = "Highlight the area between the thresholds.", group = "Plot")
trendHighlighting = input(defval = true, title = "Show Trend Highlighter", type = input.bool, tooltip = "Highlight the area between the control and the boundary lines.", group = "Plot")
showsignals = input(defval = true, title = "Show Bull/Bear Icons", type = input.bool, tooltip = "Show bull and bear icons when there is a trend reversal.", group = "Plot")
//
// â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â– ’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â –’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’ â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â– ’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â –’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’ â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’
// HELPER FUNCTIONS ================================================== ===============================================
timeframeInSeconds() =>
float seconds = timeframe.multiplier * (
timeframe.isseconds ? 1. :
timeframe.isminutes ? 60. :
timeframe.isdaily ? 60. * 60. * 24. :
timeframe.isweekly ? 60. * 60. * 24. * 7. :
timeframe.ismonthly ? 60. * 60. * 24. * 30.4375 : na)
getBarsBetween(startDate, endDate) =>
int totalSecondsBetween = (max(startDate, endDate) - min(startDate, endDate)) / 1000
ceil(totalSecondsBetween / timeframeInSeconds()) // are round or floor more appropriate than ceil here?
// MOVING AVERAGE FUNCTIONS ================================================== =======================================
vidya(source, length) =>
valpha = 2 / (length + 1)
vud1 = source > source[1] ? source - source[1] : 0
vdd1 = source < source[1] ? source[1] - source : 0
vUD = sum(vud1, 9)
vDD = sum(vdd1, 9)
vCMO = nz((vUD - vDD) / (vUD + vDD))
VAR = 0.0
VAR := nz(valpha * abs(vCMO) * source) + (1 - valpha * abs(vCMO)) * nz(VAR[1])
wwma(source, length) =>
wwalpha = 1 / length
WWMA = 0.0
WWMA := wwalpha * source + (1 - wwalpha) * nz(WWMA[1])
zlema(source, length) =>
zxLag = length / 2 == round(length / 2) ? length / 2 : (length - 1) / 2
zxEMAData = (source + (source - source[zxLag]))
ZLEMA = ema(zxEMAData, length)
tsf(source, length) =>
lrc = linreg(source, length, 0)
lrc1 = linreg(source, length, 1)
lrs = (lrc - lrc1)
TSF = linreg(source, length, 0) + lrs
// GETTER FUNCTIONS ================================================== ===============================================
getAverage(type, source, length) =>
if type == "SMA"
sma(source, length)
else if type == "EMA"
ema(source, length)
else if type == "WMA"
wma(source, length)
else if type == "TMA"
sma(sma(source, ceil(length / 2)), floor(length / 2) + 1)
else if type == "VAR"
vidya(source, length)
else if type == "WWMA"
wwma(source, length)
else if type == "ZLEMA"
zlema(source, length)
else if type == "TSF"
tsf(source, length)
else
na
getMargins(method, price) =>
if (method == "ATR")
atr = atrMethod == "ATR" ? atr(baseLength) : sma(tr, baseLength)
[atrBullTrendMultiplier * atr, atrBearTrendMultiplier * atr]
else if (method == "PERC")
[marBullTrendPerc * price, marBearTrendPerc * price]
else
[0, 0]
getBase(method) =>
if (method == "SRC")
baseSource
else if (method == "AVG")
getAverage(baseAvgType, baseAvgSrc, baseLength)
else
na
getMinMax(barsBack) =>
var minSrcArray = array.new_float(barsBack)
var maxSrcArray = array.new_float(barsBack)
array.shift(minSrcArray)
array.shift(maxSrcArray)
array.push(minSrcArray, minSrcType)
array.push(maxSrcArray, maxSrcType)
[array.min(minSrcArray), array.max(maxSrcArray)]
getThresholds(method, base) =>
if (method == "SUBADD")
[marginBullTrend, marginBearTrend] = getMargins(marMethod, base)
[base - marginBullTrend, base + marginBearTrend]
else if (method == "MINMAX")
var int barsBack = getBarsBetween(minMaxWindowStartDate, minMaxWindowEndDate)
[minThresh, maxThresh] = getMinMax(barsBack)
else
[close, close]
getControls(method) =>
if (method == "SRC")
[ctrBullTrendSrcType, ctrBearTrendSrcType]
else if (method == "AVG")
avg = getAverage(ctrAvgType, ctrAvgSrc, ctrLength)
[avg, avg]
else
[close, close]
//
// â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â– ’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â –’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’ â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â– ’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â –’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’ â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’
// TREND CORE LOGIC ================================================== ===============================================
// The backbone logic to define the trend based on the control and the boundary lines.
// If the control line (orange) crosses the boundary (green or red) then there is a trend reversal.
getTrendAndBoundaries(bullTrendLowThresh, bearTrendHighThresh, bullTrendCtr, bearTrendCtr) =>
var trendDir = 1
bullTrendLowBound = bullTrendLowThresh
bullTrendLowBoundPrev = nz(bullTrendLowBound[1], bullTrendLowBound)
bullTrendLowBound := trendDir == 1 and bullTrendCtr[1] >= bullTrendLowBoundPrev ? max(bullTrendLowBound, bullTrendLowBoundPrev) : bullTrendLowBound
bearTrendHighBound = bearTrendHighThresh
bearTrendHighBoundPrev = nz(bearTrendHighBound[1], bearTrendHighBound)
bearTrendHighBound := trendDir == -1 and bearTrendCtr[1] <= bearTrendHighBoundPrev ? min(bearTrendHighBound, bearTrendHighBoundPrev) : bearTrendHighBound
trendDir := trendDir == 1 and crossunder(bullTrendCtr, bullTrendLowBound) ? -1 : trendDir == -1 and crossover(bearTrendCtr, bearTrendHighBound) ? 1 : trendDir
[trendDir, bullTrendLowBound, bearTrendHighBound]
//
// â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â– ’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â –’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’ â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â– ’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â –’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’ â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’
// EXECUTE LOGIC ================================================== ==================================================
base = getBase(baseMethod)
[bullTrendLowThreshold, bearTrendHighThreshold] = getThresholds(threshMethod, base)
[bullTrendControl, bearTrendControl] = getControls(ctrMethod)
[trendDirection, bullTrendLowBoundary, bearTrendHighBoundary] = getTrendAndBoundaries(bullTrendLowThreshold, bearTrendHighThreshold, bullTrendControl, bearTrendControl)
//
// â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â– ’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â –’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’ â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â– ’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â –’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’ â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’
// STATISTICS ================================================== ================================================== ===
float bullForce = bearTrendControl - bullTrendLowThreshold
float bearForce = bearTrendHighThreshold - bullTrendControl
float bullBearScore = 100. * (bullForce - bearForce) / (bullForce + bearForce)
drawInfoTable() =>
if barstate.islast
float range = bearTrendHighThreshold - bullTrendLowThreshold
float bullStrength = 100. * bullForce / range
float bearStrength = 100. * bearForce / range
var infoTable = table.new(position = position.top_center, columns = 3, rows = 3, frame_color = color.black, frame_width = 2, border_color = color.black, border_width = 1)
table.cell(table_id = infoTable, column = 0, row = 0, text = tostring(bullBearScore, "#.#"), text_color = bullBearScore > 0 ? color.green : color.red, text_size = size.large, bgcolor = color.new(color.black, 95))
table.cell(table_id = infoTable, column = 1, row = 0, text = "BOĞA", text_color = color.white, text_size = size.large, bgcolor = color.new(color.green, 95))
table.cell(table_id = infoTable, column = 2, row = 0, text = "AYI", text_color = color.white, text_size = size.large, bgcolor = color.new(color.red, 95))
table.cell(table_id = infoTable, column = 0, row = 1, text = "GÜÇ", text_color = color.white, text_size = size.large, bgcolor = color.new(color.white, 95))
table.cell(table_id = infoTable, column = 1, row = 1, text = tostring(bullStrength, "#.#"), text_color = color.white, text_size = size.large, bgcolor = color.new(color.green, 95))
table.cell(table_id = infoTable, column = 2, row = 1, text = tostring(bearStrength, "#.#"), text_color = color.white, text_size = size.large, bgcolor = color.new(color.red, 95))
table.cell(table_id = infoTable, column = 0, row = 2, text = "Kazanan", text_color = color.white, text_size = size.large, bgcolor = color.new(color.white, 95))
table.cell(table_id = infoTable, column = 1, row = 2, text = bullBearScore > 25.0 ? "✔ï¸" : "âŒ", text_color = color.white, text_size = size.large, bgcolor = color.new(color.green, 95))
table.cell(table_id = infoTable, column = 2, row = 2, text = bullBearScore < -25.0 ? "✔ï¸" : "âŒ", text_color = color.white, text_size = size.large, bgcolor = color.new(color.red, 95))
//
// â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â– ’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â –’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’ â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â– ’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â –’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’ â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’
// PLOT AND GRAPH INFO ================================================== ============================================
drawInfoTable()
basePlot = plot(showBase and threshMethod == "SUBADD" ? base : na, title = "Base", color = color.blue, linewidth = 2, style = plot.style_linebr)
threshBullPlot = plot(bullTrendLowThreshold, title = "Bull Threshold", color = showThresholds ? color.blue : na, linewidth = 1, style = plot.style_linebr)
threshBearPlot = plot(bearTrendHighThreshold, title = "Bear Threshold", color = showThresholds ? color.blue : na, linewidth = 1, style = plot.style_linebr)
threshFillColor = threshHighlighting ? color.new(color.blue, 95) : na
fill(threshBullPlot, threshBearPlot, color = threshFillColor, title = "Threshold Highlighter")
ctrPlot = plot(trendDirection[1] == 1 ? bullTrendControl : bearTrendControl, title = "BOĞA=AYI", color = color.orange, linewidth = 1, style = plot.style_linebr)
bullTrendLowPlot = plot(trendDirection == 1 ? bullTrendLowBoundary : na, title = "BOĞA", color = color.green, linewidth = 2, style = plot.style_linebr)
bearTrendHighPlot = plot(trendDirection == -1 ? bearTrendHighBoundary : na, title = "AYI", color = color.red, linewidth = 2, style = plot.style_linebr)
longFillColor = trendHighlighting ? (trendDirection == 1 ? color.new(color.green, 90) : color.new(color.white, 95)) : na
shortFillColor = trendHighlighting ? (trendDirection == -1 ? color.new(color.red, 90) : color.new(color.white, 95)) : na
bullSignal = trendDirection == 1 and trendDirection[1] == -1
plotshape(bullSignal and showsignals ? bullTrendLowBoundary : na, title = "A", style = shape.labelup, location = location.absolute, color = color.green, text = "A", textcolor = color.white, size = size.small)
bearSignal = trendDirection == -1 and trendDirection[1] == 1
plotshape(bearSignal and showsignals ? bearTrendHighBoundary : na, title = "S", style = shape.labeldown, location = location.absolute, color = color.red, text = "S", textcolor = color.white, size = size.small)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Vallahualem
src = input(close)
len = input(14)
k = input(2.9652)
dispOR = input(false, title="Display outlier range")
dispBB = input(false, title="Use filtered SMA & MAD to create BB ?")
BBk = input(2.9652, title="BB mult")
median = percentile_nearest_rank(src,len,50)
MAD = percentile_nearest_rank(abs(src - median), len, 50)
up = median + MAD * k
dn = median - MAD * k
outlier = src >= up or src <= dn
sumsrc = 0.0
count = 0
for i = 0 to 5 * len
sumsrc := outlier[i] ? sumsrc : sumsrc + src[i]
count := outlier[i] ? count : count + 1
if count == len
break
mean = sumsrc / count
plot(mean, linewidth=2, color=color.yellow, title="İhlalTakip")
input = input(close),robust = input(true)
//----
b=0.,sc=0.,a=0.
sc := robust ? abs(input - nz(b[1]))/(abs(input - nz(b[1])) + nz(a[1])) : 1
src11 = sc*input+(1-sc)*nz(b[1],input)
//----
n = cum(1)-1
a := cum(abs(src11 - nz(b[1],src11)))/n*(iff(robust,1,0)+sc)
b := src11 > nz(b[1],src11) + a ? src11 : src11 < nz(b[1],src11) - a ? src11 : nz(b[1],src11)
//----
plot(b,color=#00BCD4 ,linewidth=2,transp=0)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// ++ ADDED USER INPUT ++
tf1 = input(title="Timeframe 1", type=input.resolution, defval = "180")
tf2 = input(title="Timeframe 2", type = input.resolution, defval = "360")
tf3 = input(title="Timeframe 3", type = input.resolution, defval = "720")
tf4 = input(title="Timeframe 3", type = input.resolution, defval = "D")
showTf1 = input(title="Show TF1??", type = input.bool, defval = true)
showTf2 = input(title="Show TF2??", type = input.bool, defval = true)
showTf3 = input(title="Show TF3??", type = input.bool, defval = true)
showTf4 = input(title="Show TF4??", type = input.bool, defval = true)
// == HORIZONTAL HIGH/LOW LINES FOR HIGHER TIME FRAMES ==
// Inputs
showMTFLevels = input(title = "Show Multiple Timeframe S/R Levels?", type = input.bool, defval = true, group = "Higher Timeframe Levels",
tooltip = "Displays the highs and lows of higher timeframes to use as support/resistance levels for potential targets.")
tf1Color = input(#B10BF5, title = "TF1", type = input.color, group = "Higher Timeframe Levels", inline = "MTF")
tf2Color = input(#0932FF, title = "??TF2", type = input.color, group = "Higher Timeframe Levels", inline = "MTF")
tf3Color = input(#FFAA00, title = "??TF3", type = input.color, group = "Higher Timeframe Levels", inline = "MTF")
tf4Color = input(#f2f2f2, title = "??TF4", type = input.color, group = "Higher Timeframe Levels", inline = "MTF")
// Calculations
openPrice(tf) => security(syminfo.tickerid, tf, time[1])
lowPrice(tf) => security(syminfo.tickerid, tf, low[1])
highPrice(tf) => security(syminfo.tickerid, tf, high[1])
// TIMEFRAME 2
tf1Low = showMTFLevels and showTf1 ? lowPrice(tf1) : na
tf1High = showMTFLevels and showTf1 ? highPrice(tf1) : na
tf1Open = showMTFLevels and showTf1 ? openPrice(tf1) : na
tf1LineLow = line.new(x1=tf1Open, y1=tf1Low, x2=time, y2=tf1Low, xloc = xloc.bar_time, extend = extend.right, color=tf1Color)
line.delete(tf1LineLow[1])
tf1LineHigh = line.new(x1=tf1Open, y1=tf1High, x2=time, y2=tf1High, xloc = xloc.bar_time, extend = extend.right, color=tf1Color)
line.delete(tf1LineHigh[1])
// TIMEFRAME 2
tf2Low = showMTFLevels and showTf2 ? lowPrice(tf2) : na
tf2High = showMTFLevels and showTf2 ? highPrice(tf2) : na
tf2Open = showMTFLevels and showTf2 ? openPrice(tf2) : na
tf2LineLow = line.new(x1=tf2Open, y1=tf2Low, x2=time, y2=tf2Low, xloc = xloc.bar_time, extend = extend.right, color=tf2Color)
line.delete(tf2LineLow[1])
tf2LineHigh = line.new(x1=tf2Open, y1=tf2High, x2=time, y2=tf2High, xloc = xloc.bar_time, extend = extend.right, color=tf2Color)
line.delete(tf2LineHigh[1])
// TIMEFRAME 3
tf3Low = showMTFLevels and showTf3 ? lowPrice(tf3) : na
tf3High = showMTFLevels and showTf3 ? highPrice(tf3) : na
tf3Open = showMTFLevels and showTf3 ? openPrice(tf3) : na
tf3LineLow = line.new(x1=tf3Open, y1=tf3Low, x2=time, y2=tf3Low, xloc = xloc.bar_time, extend = extend.right, color=tf3Color)
line.delete(tf3LineLow[1])
tf3LineHigh = line.new(x1=tf3Open, y1=tf3High, x2=time, y2=tf3High, xloc = xloc.bar_time, extend = extend.right, color=tf3Color)
line.delete(tf3LineHigh[1])
// TIMEFRAME 4
tf4Low = showMTFLevels and showTf4 ? lowPrice(tf4) : na
tf4High = showMTFLevels and showTf4 ? highPrice(tf4) : na
tf4Open = showMTFLevels and showTf4? openPrice(tf4) : na
tf4LineLow = line.new(x1=tf4Open, y1=tf4Low, x2=time, y2=tf4Low, xloc = xloc.bar_time, extend = extend.right, color=tf4Color)
line.delete(tf4LineLow[1])
tf4LineHigh = line.new(x1=tf4Open, y1=tf4High, x2=time, y2=tf4High, xloc = xloc.bar_time, extend = extend.right, color=tf4Color)
line.delete(tf4LineHigh[1])
//İhlal Durumu
lag = input(1)
source = input(close)
dif = source - source[lag]
periods = input(100, title = "Sample size - Back periods for std. deviation estimate") + 1
//Standard deviation estimator
std = sqrt((sum(pow(dif, 2), periods) - pow(dif[0], 2))/(periods - 2))
//Confidence bands and fills
N1 = input(2)
over1 = hline(N1, color=color.new(#9915FF, 100), linewidth=1, linestyle = hline.style_solid, title = "Upper limit N1")
below1 = hline(-N1, color=color.new(#9915FF, 100), linewidth=1, linestyle=hline.style_solid, title = "Lower limit N1")
N2 = input(3)
over2 = hline(N2, color=color.new(#9915FF, 100), linewidth=1, linestyle = hline.style_solid, title = "Upper limit N2")
below2 = hline(-N2, color=color.new(#9915FF, 100), linewidth=1, linestyle=hline.style_solid, title = "Lower limit N2")
fill(over2, over1, color=color.new(#9915FF, 75), title="Background")
fill(over1, below1, color=color.new(#9915FF, 85), title="Background")
fill(below1, below2, color=color.new(#9915FF, 75), title="Background")
//Plot
c1 = color.from_gradient(dif/std, -0.001, 0.001, #FF2D00, #13FF00)
plot(dif/std, color=color.new(c1, 0), title = "Series", linewidth=1, style = plot.style_columns, trackprice = true)
hline(0, color=color.new(#959595, 0), title = "Zero average")
Yer İmleri