OPEN-SOURCE SCRIPT

My script

36

//version=5

indicator(title = "Trader Club 5in1", shorttitle="Trader Club 5in1", overlay=true, format=format.price, precision=2,max_lines_count = 500, max_labels_count = 500, max_bars_back=500)


showEma200 = input(true, title="EMA 200")
showPmax = input(true, title="Pmax")
showLinreg = input(true, title="Linreg")
showMavilim = input(true, title="Mavilim")
showNadaray = input(true, title="Nadaraya Watson")


ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)


//Ema200


timeFrame = input.timeframe(defval = '240',title= 'EMA200 TimeFrame',group = 'EMA200 Settings')
len200 = input.int(200, minval=1, title="Length",group = 'EMA200 Settings')
src200 = input(close, title="Source",group = 'EMA200 Settings')
offset200 = input.int(title="Offset", defval=0, minval=-500, maxval=500,group = 'EMA200 Settings')
out200 = ta.ema(src200, len200)
higherTimeFrame = request.security(syminfo.tickerid,timeFrame,out200[1],barmerge.gaps_on,barmerge.lookahead_on)
ema200Plot = showEma200 ? higherTimeFrame : na
plot(ema200Plot, title="EMA200", offset=offset200)




//Linreq
group1 = "Linreg Settings"
lengthInput = input.int(100, title="Length", minval = 1, maxval = 5000,group = group1)
sourceInput = input.source(close, title="Source")


useUpperDevInput = input.bool(true, title="Upper Deviation", inline = "Upper Deviation", group = group1)
upperMultInput = input.float(2.0, title="", inline = "Upper Deviation", group = group1)
useLowerDevInput = input.bool(true, title="Lower Deviation", inline = "Lower Deviation", group = group1)
lowerMultInput = input.float(2.0, title="", inline = "Lower Deviation", group = group1)

group2 = "Linreg Display Settings"
showPearsonInput = input.bool(true, "Show Pearson's R", group = group2)
extendLeftInput = input.bool(false, "Extend Lines Left", group = group2)
extendRightInput = input.bool(true, "Extend Lines Right", group = group2)
extendStyle = switch
extendLeftInput and extendRightInput => extend.both
extendLeftInput => extend.left
extendRightInput => extend.right
=> extend.none

group3 = "Linreg Color Settings"
colorUpper = input.color(color.new(color.blue, 85), "Linreg Renk", inline = group3, group = group3)
colorLower = input.color(color.new(color.red, 85), "", inline = group3, group = group3)

calcSlope(source, length) =>
max_bars_back(source, 5000)
if not barstate.islast or length <= 1
[float(na), float(na), float(na)]
else
sumX = 0.0
sumY = 0.0
sumXSqr = 0.0
sumXY = 0.0
for i = 0 to length - 1 by 1
val = source
per = i + 1.0
sumX += per
sumY += val
sumXSqr += per * per
sumXY += val * per
slope = (length * sumXY - sumX * sumY) / (length * sumXSqr - sumX * sumX)
average = sumY / length
intercept = average - slope * sumX / length + slope
[slope, average, intercept]

[s, a, i] = calcSlope(sourceInput, lengthInput)
startPrice = i + s * (lengthInput - 1)
endPrice = i
var line baseLine = na
if na(baseLine) and not na(startPrice) and showLinreg
baseLine := line.new(bar_index - lengthInput + 1, startPrice, bar_index, endPrice, width=1, extend=extendStyle, color=color.new(colorLower, 0))
else
line.set_xy1(baseLine, bar_index - lengthInput + 1, startPrice)
line.set_xy2(baseLine, bar_index, endPrice)
na

calcDev(source, length, slope, average, intercept) =>
upDev = 0.0
dnDev = 0.0
stdDevAcc = 0.0
dsxx = 0.0
dsyy = 0.0
dsxy = 0.0
periods = length - 1
daY = intercept + slope * periods / 2
val = intercept
for j = 0 to periods by 1
price = high[j] - val
if price > upDev
upDev := price
price := val - low[j]
if price > dnDev
dnDev := price
price := source[j]
dxt = price - average
dyt = val - daY
price -= val
stdDevAcc += price * price
dsxx += dxt * dxt
dsyy += dyt * dyt
dsxy += dxt * dyt
val += slope
stdDev = math.sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / math.sqrt(dsxx * dsyy)
[stdDev, pearsonR, upDev, dnDev]

[stdDev, pearsonR, upDev, dnDev] = calcDev(sourceInput, lengthInput, s, a, i)
upperStartPrice = startPrice + (useUpperDevInput ? upperMultInput * stdDev : upDev)
upperEndPrice = endPrice + (useUpperDevInput ? upperMultInput * stdDev : upDev)
var line upper = na
lowerStartPrice = startPrice + (useLowerDevInput ? -lowerMultInput * stdDev : -dnDev)
lowerEndPrice = endPrice + (useLowerDevInput ? -lowerMultInput * stdDev : -dnDev)
var line lower = na
if na(upper) and not na(upperStartPrice) and showLinreg
upper := line.new(bar_index - lengthInput + 1, upperStartPrice, bar_index, upperEndPrice, width=1, extend=extendStyle, color=color.new(colorUpper, 0))
else
line.set_xy1(upper, bar_index - lengthInput + 1, upperStartPrice)
line.set_xy2(upper, bar_index, upperEndPrice)
na
if na(lower) and not na(lowerStartPrice) and showLinreg
lower := line.new(bar_index - lengthInput + 1, lowerStartPrice, bar_index, lowerEndPrice, width=1, extend=extendStyle, color=color.new(colorUpper, 0))
else
line.set_xy1(lower, bar_index - lengthInput + 1, lowerStartPrice)
line.set_xy2(lower, bar_index, lowerEndPrice)
na
showLinregPlotUpper = showLinreg ? upper : na
showLinregPlotLower = showLinreg ? lower : na
showLinregPlotBaseLine = showLinreg ? baseLine : na
linefill.new(showLinregPlotUpper, showLinregPlotBaseLine, color = colorUpper)
linefill.new(showLinregPlotBaseLine, showLinregPlotLower, color = colorLower)

// Pearson's R
var label r = na
label.delete(r[1])
if showPearsonInput and not na(pearsonR) and showLinreg
r := label.new(bar_index - lengthInput + 1, lowerStartPrice, str.tostring(pearsonR, "#.################"), color = color.new(color.white, 100), textcolor=color.new(colorUpper, 0), size=size.normal, style=label.style_label_up)



//Mavilim
group4 = "Mavilim Settings"
mavilimold = input(false, title="Show Previous Version of MavilimW?",group=group4)
fmal=input(3,"First Moving Average length",group = group4)
smal=input(5,"Second Moving Average length",group = group4)
tmal=fmal+smal
Fmal=smal+tmal
Ftmal=tmal+Fmal
Smal=Fmal+Ftmal

M1= ta.wma(close, fmal)
M2= ta.wma(M1, smal)
M3= ta.wma(M2, tmal)
M4= ta.wma(M3, Fmal)
M5= ta.wma(M4, Ftmal)
MAVW= ta.wma(M5, Smal)
col1= MAVW>MAVW[1]
col3= MAVW<MAVW[1]
colorM = col1 ? color.blue : col3 ? color.red : color.yellow

mavwPlot = showMavilim ? MAVW : na
plot(mavwPlot, color=colorM, linewidth=2, title="MAVW")

M12= ta.wma(close, 3)
M22= ta.wma(M12, 5)
M32= ta.wma(M22, 8)
M42= ta.wma(M32, 13)
M52= ta.wma(M42, 21)
MAVW2= ta.wma(M52, 34)


//PMAX

group5 = "PMAX Settings"
pmaxsrc = input(hl2, title="Source",group = group5)
Periods = input.int(title="ATR Length", defval=10,group = group5)
Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0,group = group5)
mav = input(title="Moving Average Type", defval="EMA",group = group5)
length =input.int(9, title="Moving Average Length",minval = 1,group = group5)
changeATR= input.bool(title="Change ATR Calculation Method ?", defval=true,group = group5)
Normalize= input.bool(title="Normalize ATR ?", defval=false,group = group5)
showsupport = input.bool(title="Show Moving Average?", defval=true,group = group5)
showsignalsk = input.bool(title="Show Crossing Signals?", defval=true,group = group5)
showsignalsc = input.bool(title="Show Price/Pmax Crossing Signals?", defval=false,group = group5)
highlighting = input.bool(title="Highlighter On/Off ?", defval=false,group = group5)
atr2 = ta.sma(ta.tr, Periods)
atr= changeATR ? ta.atr(Periods) : atr2
valpha=2/(length+1)
vud1=pmaxsrc>pmaxsrc[1] ? pmaxsrc-pmaxsrc[1] : 0
vdd1=pmaxsrc<pmaxsrc[1] ? pmaxsrc[1]-pmaxsrc : 0
vUD=math.sum(vud1,9)
vDD=math.sum(vdd1,9)
vCMO=nz((vUD-vDD)/(vUD+vDD))
VAR=0.0
VAR:=nz(valpha*math.abs(vCMO)*pmaxsrc)+(1-valpha*math.abs(vCMO))*nz(VAR[1])
wwalpha = 1/ length
WWMA = 0.0
WWMA := wwalpha*pmaxsrc + (1-wwalpha)*nz(WWMA[1])
zxLag = length/2==math.round(length/2) ? length/2 : (length - 1) / 2
zxEMAData = (pmaxsrc + (pmaxsrc - pmaxsrc[zxLag]))
ZLEMA = ta.ema(zxEMAData, length)
lrc = ta.linreg(pmaxsrc, length, 0)
lrc1 = ta.linreg(pmaxsrc,length,1)
lrs = (lrc-lrc1)
TSF = ta.linreg(pmaxsrc, length, 0)+lrs
getMA(pmaxsrc, length) =>
ma = 0.0
if mav == "SMA"
ma := ta.sma(pmaxsrc, length)
ma

if mav == "EMA"
ma := ta.ema(pmaxsrc, length)
ma

if mav == "WMA"
ma := ta.wma(pmaxsrc, length)
ma

if mav == "TMA"
ma := ta.sma(ta.sma(pmaxsrc, math.ceil(length / 2)), math.floor(length / 2) + 1)
ma

if mav == "VAR"
ma := VAR
ma

if mav == "WWMA"
ma := WWMA
ma

if mav == "ZLEMA"
ma := ZLEMA
ma

if mav == "TSF"
ma := TSF
ma
ma

MAvg=getMA(pmaxsrc, length)
longStop = Normalize ? MAvg - Multiplier*atr/close : MAvg - Multiplier*atr
longStopPrev = nz(longStop[1], longStop)
longStop := MAvg > longStopPrev ? math.max(longStop, longStopPrev) : longStop
shortStop = Normalize ? MAvg + Multiplier*atr/close : MAvg + Multiplier*atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := MAvg < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dir
PMax = dir==1 ? longStop: shortStop
// plot(showsupport ? MAvg : na, color=#0585E1, linewidth=2, title="EMA9")
pmaxPlot = showPmax ? PMax : na
pALL=plot(pmaxPlot, color=color.new(#FF5252, transp = 0), linewidth=2, title="PMax")
alertcondition(ta.cross(MAvg, PMax), title="Cross Alert", message="PMax - Moving Avg Crossing!")
alertcondition(ta.crossover(MAvg, PMax), title="Crossover Alarm", message="Moving Avg BUY SIGNAL!")
alertcondition(ta.crossunder(MAvg, PMax), title="Crossunder Alarm", message="Moving Avg SELL SIGNAL!")
alertcondition(ta.cross(pmaxsrc, PMax), title="Price Cross Alert", message="PMax - Price Crossing!")
alertcondition(ta.crossover(pmaxsrc, PMax), title="Price Crossover Alarm", message="PRICE OVER PMax - BUY SIGNAL!")
alertcondition(ta.crossunder(pmaxsrc, PMax), title="Price Crossunder Alarm", message="PRICE UNDER PMax - SELL SIGNAL!")
buySignalk = ta.crossover(MAvg, PMax)
plotshape(buySignalk and showsignalsk and showPmax ? PMax*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, transp = 0), textcolor=color.white)
sellSignallk = ta.crossunder(MAvg, PMax)
plotshape(sellSignallk and showsignalsk and showPmax ? PMax*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, transp = 0), textcolor=color.white)
// buySignalc = ta.crossover(pmaxsrc, PMax)
// plotshape(buySignalc and showsignalsc ? PMax*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=#0F18BF, textcolor=color.white)
// sellSignallc = ta.crossunder(pmaxsrc, PMax)
// plotshape(sellSignallc and showsignalsc ? PMax*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=#0F18BF, textcolor=color.white)
// mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0,display=display.none)
longFillColor = highlighting ? (MAvg>PMax ? color.new(color.green, transp = 90) : na) : na
shortFillColor = highlighting ? (MAvg<PMax ? color.new(color.red, transp = 90) : na) : na
// fill(mPlot, pALL, title="UpTrend Highligter", color=longFillColor)
// fill(mPlot, pALL, title="DownTrend Highligter", color=shortFillColor)



group6 = "NADARAYA WATSON Settings"
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
h = input.float(8.,'Bandwidth', minval = 0,group = group6)
mult = input.float(3., minval = 0,group = group6)
src = input(close, 'Source',group = group6)

repaint = input(true, 'Repainting Smoothing', tooltip = 'Repainting is an effect where the indicators historical output is subject to change over time. Disabling repainting will cause the indicator to output the endpoints of the calculations',group = group6)

//Style
upCss = input.color(color.teal, 'Colors', inline = 'inline1', group = group6)
dnCss = input.color(color.red, '', inline = 'inline1', group = group6)

//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
//Gaussian window
gauss(x, h) => math.exp(-(math.pow(x, 2)/(h * h * 2)))

//-----------------------------------------------------------------------------}
//Append lines
//-----------------------------------------------------------------------------{
n = bar_index

var ln = array.new_line(0)

if barstate.isfirst and repaint
for i = 0 to 499
array.push(ln,line.new(na,na,na,na))

//-----------------------------------------------------------------------------}
//End point method
//-----------------------------------------------------------------------------{
var coefs = array.new_float(0)
var den = 0.

if barstate.isfirst and not repaint
for i = 0 to 499
w = gauss(i, h)
coefs.push(w)

den := coefs.sum()

out = 0.
if not repaint
for i = 0 to 499
out += src * coefs.get(i)
out /= den
mae = ta.sma(math.abs(src - out), 499) * mult

upperN = out + mae
lowerN = out - mae

//-----------------------------------------------------------------------------}
//Compute and display NWE
//-----------------------------------------------------------------------------{
float y2 = na
float y1 = na

nwe = array.new<float>(0)
if barstate.islast and repaint
sae = 0.
//Compute and set NWE point
for i = 0 to math.min(499,n - 1)
sum = 0.
sumw = 0.
//Compute weighted mean
for j = 0 to math.min(499,n - 1)
w = gauss(i - j, h)
sum += src[j] * w
sumw += w

y2 := sum / sumw
sae += math.abs(src - y2)
nwe.push(y2)

sae := sae / math.min(499,n - 1) * mult
for i = 0 to math.min(499,n - 1)
if i%2 and showNadaray
line.new(n-i+1, y1 + sae, n-i, nwe.get(i) + sae, color = upCss)
line.new(n-i+1, y1 - sae, n-i, nwe.get(i) - sae, color = dnCss)

if src > nwe.get(i) + sae and src[i+1] < nwe.get(i) + sae and showNadaray
label.new(n-i, src, '▼', color = color(na), style = label.style_label_down, textcolor = dnCss, textalign = text.align_center)
if src < nwe.get(i) - sae and src[i+1] > nwe.get(i) - sae and showNadaray
label.new(n-i, src, '▲', color = color(na), style = label.style_label_up, textcolor = upCss, textalign = text.align_center)

y1 := nwe.get(i)

//-----------------------------------------------------------------------------}
//Dashboard
//-----------------------------------------------------------------------------{
var tb = table.new(position.top_right, 1, 1
, bgcolor = #1e222d
, border_color = #373a46
, border_width = 1
, frame_color = #373a46
, frame_width = 1)

if repaint
tb.cell(0, 0, 'Repainting Mode Enabled', text_color = color.white, text_size = size.small)

//-----------------------------------------------------------------------------}
//Plot
//-----------------------------------------------------------------------------}
// plot(repaint ? na : out + mae, 'Upper', upCss)
// plot(repaint ? na : out - mae, 'Lower', dnCss)

//Crossing Arrows
// plotshape(ta.crossunder(close, out - mae) ? low : na, "Crossunder", shape.labelup, location.absolute, color(na), 0 , text = '▲', textcolor = upCss, size = size.tiny)
// plotshape(ta.crossover(close, out + mae) ? high : na, "Crossover", shape.labeldown, location.absolute, color(na), 0 , text = '▼', textcolor = dnCss, size = size.tiny)

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

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.