OPEN-SOURCE SCRIPT
Kripto Fema ind

/ This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org/MPL/2.0/
// © Femayakup
//version=5
indicator(title = "Kripto Fema ind", shorttitle="Kripto Fema ind", 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 Ayarları"
pmaxsrc = input(hl2, title="Source",group = group5)
Periods = input.int(title="ATR Length", defval=12,group = group5)
Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=4.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=#fbff04, linewidth=2, title="EMA9")
pALL=plot(PMax, color=color.new(color.red, 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 ? 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 ? 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)
//-----------------------------------------------------------------------------}
//////////////////////////////////////////////////////////////////////////////////
enableD = input (true, "DIVERGANCE ON/OFF" , group="INDICATORS ON/OFF")
//DIVERGANCE
prd1 = input.int (defval=5 , title='PIVOT PERIOD' , minval=1, maxval=50 , group="DIVERGANCE")
source = input.string(defval='HIGH/LOW' , title='SOURCE FOR PIVOT POINTS' , options=['CLOSE', 'HIGH/LOW'] , group="DIVERGANCE")
searchdiv = input.string(defval='REGULAR/HIDDEN', title='DIVERGANCE TYPE' , options=['REGULAR', 'HIDDEN', 'REGULAR/HIDDEN'], group="DIVERGANCE")
showindis = input.string(defval='FULL' , title='SHOW INDICATORS NAME' , options=['FULL', 'FIRST LETTER', "DON'T SHOW"] , group="DIVERGANCE")
showlimit = input.int(1 , title='MINIMUM NUMBER OF DIVERGANCES', minval=1, maxval=11 , group="DIVERGANCE")
maxpp = input.int (defval=20 , title='MAXIMUM PIVOT POINTS TO CHECK', minval=1, maxval=20 , group="DIVERGANCE")
maxbars = input.int (defval=200 , title='MAXIMUM BARS TO CHECK' , minval=30, maxval=200 , group="DIVERGANCE")
showlast = input (defval=false , title='SHOW ONLY LAST DIVERGANCE' , group="DIVERGANCE")
dontconfirm = input (defval=false , title="DON'T WAIT FOR CONFORMATION" , group="DIVERGANCE")
showlines = input (defval=false , title='SHOW DIVERGANCE LINES' , group="DIVERGANCE")
showpivot = input (defval=false , title='SHOW PIVOT POINTS' , group="DIVERGANCE")
calcmacd = input (defval=true , title='MACD' , group="DIVERGANCE")
calcmacda = input (defval=true , title='MACD HISTOGRAM' , group="DIVERGANCE")
calcrsi = input (defval=true , title='RSI' , group="DIVERGANCE")
calcstoc = input (defval=true , title='STOCHASTIC' , group="DIVERGANCE")
calccci = input (defval=true , title='CCI' , group="DIVERGANCE")
calcmom = input (defval=true , title='MOMENTUM' , group="DIVERGANCE")
calcobv = input (defval=true , title='OBV' , group="DIVERGANCE")
calcvwmacd = input (true , title='VWMACD' , group="DIVERGANCE")
calccmf = input (true , title='CHAIKIN MONEY FLOW' , group="DIVERGANCE")
calcmfi = input (true , title='MONEY FLOW INDEX' , group="DIVERGANCE")
calcext = input (false , title='CHECK EXTERNAL INDICATOR' , group="DIVERGANCE")
externalindi = input (defval=close , title='EXTERNAL INDICATOR' , group="DIVERGANCE")
pos_reg_div_col = input (defval=#ffffff , title='POSITIVE REGULAR DIVERGANCE' , group="DIVERGANCE")
neg_reg_div_col = input (defval=#00def6 , title='NEGATIVE REGULAR DIVERGANCE' , group="DIVERGANCE")
pos_hid_div_col = input (defval=#00ff0a , title='POSITIVE HIDDEN DIVERGANCE' , group="DIVERGANCE")
neg_hid_div_col = input (defval=#ff0015 , title='NEGATIVE HIDDEN DIVERGANCE' , group="DIVERGANCE")
reg_div_l_style_ = input.string(defval='SOLID' , title='REGULAR DIVERGANCE LINESTYLE' , options=['SOLID', 'DASHED', 'DOTTED'] , group="DIVERGANCE")
hid_div_l_style_ = input.string(defval='SOLID' , title='HIDDEN DIVERGANCE LINESTYLE' , options=['SOLID', 'DASHED', 'DOTTED'] , group="DIVERGANCE")
reg_div_l_width = input.int (defval=2 , title='REGULAR DIVERGANCE LINEWIDTH' , minval=1, maxval=5 , group="DIVERGANCE")
hid_div_l_width = input.int (defval=2 , title='HIDDEN DIVERGANCE LINEWIDTH' , minval=1, maxval=5 , group="DIVERGANCE")
showmas = input.bool (defval=false , title='SHOW MOVING AVERAGES (50 & 200)', inline='MA' , group="DIVERGANCE")
cma1col = input.color (defval=#ffffff , title='' , inline='MA' , group="DIVERGANCE")
cma2col = input.color (defval=#00def6 , title='' , inline='MA' , group="DIVERGANCE")
//PLOTS
plot(showmas ? ta.sma(close, 50) : na, color=showmas ? cma1col : na)
plot(showmas ? ta.sma(close, 200) : na, color=showmas ? cma2col : na)
var reg_div_l_style = reg_div_l_style_ == 'SOLID' ? line.style_solid : reg_div_l_style_ == 'DASHED' ? line.style_dashed : line.style_dotted
var hid_div_l_style = hid_div_l_style_ == 'SOLID' ? line.style_solid : hid_div_l_style_ == 'DASHED' ? line.style_dashed : line.style_dotted
rsi = ta.rsi(close, 14)
[macd, signal, deltamacd] = ta.macd(close, 12, 26, 9)
moment = ta.mom(close, 10)
cci = ta.cci(close, 10)
Obv = ta.obv
stk = ta.sma(ta.stoch(close, high, low, 14), 3)
maFast = ta.vwma(close, 12)
maSlow = ta.vwma(close, 26)
vwmacd = maFast - maSlow
Cmfm = (close - low - (high - close)) / (high - low)
Cmfv = Cmfm * volume
cmf = ta.sma(Cmfv, 21) / ta.sma(volume, 21)
Mfi = ta.mfi(close, 14)
var indicators_name = array.new_string(11)
var div_colors = array.new_color(4)
if barstate.isfirst and enableD
array.set(indicators_name, 0, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 1, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 2, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 3, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 4, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 5, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 6, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 7, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 8, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 9, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 10, showindis == "DON'T SHOW" ? '' : '')
array.set(div_colors, 0, pos_reg_div_col)
array.set(div_colors, 1, neg_reg_div_col)
array.set(div_colors, 2, pos_hid_div_col)
array.set(div_colors, 3, neg_hid_div_col)
float ph1 = ta.pivothigh(source == 'CLOSE' ? close : high, prd1, prd1)
float pl1 = ta.pivotlow(source == 'CLOSE' ? close : low, prd1, prd1)
plotshape(ph1 and showpivot, text='H', style=shape.labeldown, color=color.new(color.white, 100), textcolor=#00def6, location=location.abovebar, offset=-prd1)
plotshape(pl1 and showpivot, text='L', style=shape.labelup, color=color.new(color.white, 100), textcolor=#ffffff, location=location.belowbar, offset=-prd1)
var int maxarraysize = 20
var ph_positions = array.new_int(maxarraysize, 0)
var pl_positions = array.new_int(maxarraysize, 0)
var ph_vals = array.new_float(maxarraysize, 0.)
var pl_vals = array.new_float(maxarraysize, 0.)
if ph1
array.unshift(ph_positions, bar_index)
array.unshift(ph_vals, ph1)
if array.size(ph_positions) > maxarraysize
array.pop(ph_positions)
array.pop(ph_vals)
if pl1
array.unshift(pl_positions, bar_index)
array.unshift(pl_vals, pl1)
if array.size(pl_positions) > maxarraysize
array.pop(pl_positions)
array.pop(pl_vals)
positive_regular_positive_hidden_divergence(src, cond) =>
divlen = 0
prsc = source == 'CLOSE' ? close : low
if dontconfirm or src > src[1] or close > close[1]
startpoint = dontconfirm ? 0 : 1
for x = 0 to maxpp - 1 by 1
len = bar_index - array.get(pl_positions, x) + prd1
if array.get(pl_positions, x) == 0 or len > maxbars
break
if len > 5 and (cond == 1 and src[startpoint] > src[len] and prsc[startpoint] < nz(array.get(pl_vals, x)) or cond == 2 and src[startpoint] < src[len] and prsc[startpoint] > nz(array.get(pl_vals, x)))
slope1 = (src[startpoint] - src[len]) / (len - startpoint)
virtual_line1 = src[startpoint] - slope1
slope2 = (close[startpoint] - close[len]) / (len - startpoint)
virtual_line2 = close[startpoint] - slope2
arrived = true
for y = 1 + startpoint to len - 1 by 1
if src[y] < virtual_line1 or nz(close[y]) < virtual_line2
arrived := false
break
virtual_line1 -= slope1
virtual_line2 -= slope2
virtual_line2
if arrived
divlen := len
break
divlen
negative_regular_negative_hidden_divergence(src, cond) =>
divlen = 0
prsc = source == 'CLOSE' ? close : high
if dontconfirm or src < src[1] or close < close[1]
startpoint = dontconfirm ? 0 : 1
for x = 0 to maxpp - 1 by 1
len = bar_index - array.get(ph_positions, x) + prd1
if array.get(ph_positions, x) == 0 or len > maxbars
break
if len > 5 and (cond == 1 and src[startpoint] < src[len] and prsc[startpoint] > nz(array.get(ph_vals, x)) or cond == 2 and src[startpoint] > src[len] and prsc[startpoint] < nz(array.get(ph_vals, x)))
slope1 = (src[startpoint] - src[len]) / (len - startpoint)
virtual_line1 = src[startpoint] - slope1
slope2 = (close[startpoint] - nz(close[len])) / (len - startpoint)
virtual_line2 = close[startpoint] - slope2
arrived = true
for y = 1 + startpoint to len - 1 by 1
if src[y] > virtual_line1 or nz(close[y]) > virtual_line2
arrived := false
break
virtual_line1 -= slope1
virtual_line2 -= slope2
virtual_line2
if arrived
divlen := len
break
divlen
//CALCULATIONS
calculate_divs(cond, indicator_1) =>
divs = array.new_int(4, 0)
array.set(divs, 0, cond and (searchdiv == 'REGULAR' or searchdiv == 'REGULAR/HIDDEN') ? positive_regular_positive_hidden_divergence(indicator_1, 1) : 0)
array.set(divs, 1, cond and (searchdiv == 'REGULAR' or searchdiv == 'REGULAR/HIDDEN') ? negative_regular_negative_hidden_divergence(indicator_1, 1) : 0)
array.set(divs, 2, cond and (searchdiv == 'HIDDEN' or searchdiv == 'REGULAR/HIDDEN') ? positive_regular_positive_hidden_divergence(indicator_1, 2) : 0)
array.set(divs, 3, cond and (searchdiv == 'HIDDEN' or searchdiv == 'REGULAR/HIDDEN') ? negative_regular_negative_hidden_divergence(indicator_1, 2) : 0)
divs
var all_divergences = array.new_int(44)
array_set_divs(div_pointer, index) =>
for x = 0 to 3 by 1
array.set(all_divergences, index * 4 + x, array.get(div_pointer, x))
array_set_divs(calculate_divs(calcmacd , macd) , 0)
array_set_divs(calculate_divs(calcmacda , deltamacd) , 1)
array_set_divs(calculate_divs(calcrsi , rsi) , 2)
array_set_divs(calculate_divs(calcstoc , stk) , 3)
array_set_divs(calculate_divs(calccci , cci) , 4)
array_set_divs(calculate_divs(calcmom , moment) , 5)
array_set_divs(calculate_divs(calcobv , Obv) , 6)
array_set_divs(calculate_divs(calcvwmacd, vwmacd) , 7)
array_set_divs(calculate_divs(calccmf , cmf) , 8)
array_set_divs(calculate_divs(calcmfi , Mfi) , 9)
array_set_divs(calculate_divs(calcext , externalindi), 10)
total_div = 0
for x = 0 to array.size(all_divergences) - 1 by 1
total_div += math.round(math.sign(array.get(all_divergences, x)))
total_div
if total_div < showlimit
array.fill(all_divergences, 0)
var pos_div_lines = array.new_line(0)
var neg_div_lines = array.new_line(0)
var pos_div_labels = array.new_label(0)
var neg_div_labels = array.new_label(0)
delete_old_pos_div_lines() =>
if array.size(pos_div_lines) > 0
for j = 0 to array.size(pos_div_lines) - 1 by 1
line.delete(array.get(pos_div_lines, j))
array.clear(pos_div_lines)
delete_old_neg_div_lines() =>
if array.size(neg_div_lines) > 0
for j = 0 to array.size(neg_div_lines) - 1 by 1
line.delete(array.get(neg_div_lines, j))
array.clear(neg_div_lines)
delete_old_pos_div_labels() =>
if array.size(pos_div_labels) > 0
for j = 0 to array.size(pos_div_labels) - 1 by 1
label.delete(array.get(pos_div_labels, j))
array.clear(pos_div_labels)
delete_old_neg_div_labels() =>
if array.size(neg_div_labels) > 0
for j = 0 to array.size(neg_div_labels) - 1 by 1
label.delete(array.get(neg_div_labels, j))
array.clear(neg_div_labels)
delete_last_pos_div_lines_label(n) =>
if n > 0 and array.size(pos_div_lines) >= n
asz = array.size(pos_div_lines)
for j = 1 to n by 1
line.delete(array.get(pos_div_lines, asz - j))
array.pop(pos_div_lines)
if array.size(pos_div_labels) > 0
label.delete(array.get(pos_div_labels, array.size(pos_div_labels) - 1))
array.pop(pos_div_labels)
delete_last_neg_div_lines_label(n) =>
if n > 0 and array.size(neg_div_lines) >= n
asz = array.size(neg_div_lines)
for j = 1 to n by 1
line.delete(array.get(neg_div_lines, asz - j))
array.pop(neg_div_lines)
if array.size(neg_div_labels) > 0
label.delete(array.get(neg_div_labels, array.size(neg_div_labels) - 1))
array.pop(neg_div_labels)
pos_reg_div_detected = false
neg_reg_div_detected = false
pos_hid_div_detected = false
neg_hid_div_detected = false
var last_pos_div_lines = 0
var last_neg_div_lines = 0
var remove_last_pos_divs = false
var remove_last_neg_divs = false
if pl1
remove_last_pos_divs := false
last_pos_div_lines := 0
last_pos_div_lines
if ph1
remove_last_neg_divs := false
last_neg_div_lines := 0
last_neg_div_lines
divergence_text_top = ''
divergence_text_bottom = ''
distances = array.new_int(0)
dnumdiv_top = 0
dnumdiv_bottom = 0
top_label_col = color.white
bottom_label_col = color.white
old_pos_divs_can_be_removed = true
old_neg_divs_can_be_removed = true
startpoint = dontconfirm ? 0 : 1
for x = 0 to 10 by 1
div_type = -1
for y = 0 to 3 by 1
if array.get(all_divergences, x * 4 + y) > 0
div_type := y
if y % 2 == 1
dnumdiv_top += 1
top_label_col := array.get(div_colors, y)
top_label_col
if y % 2 == 0
dnumdiv_bottom += 1
bottom_label_col := array.get(div_colors, y)
bottom_label_col
if not array.includes(distances, array.get(all_divergences, x * 4 + y))
array.push(distances, array.get(all_divergences, x * 4 + y))
new_line = showlines ? line.new(x1=bar_index - array.get(all_divergences, x * 4 + y), y1=source == 'CLOSE' ? close[array.get(all_divergences, x * 4 + y)] : y % 2 == 0 ? low[array.get(all_divergences, x * 4 + y)] : high[array.get(all_divergences, x * 4 + y)], x2=bar_index - startpoint, y2=source == 'CLOSE' ? close[startpoint] : y % 2 == 0 ? low[startpoint] : high[startpoint], color=array.get(div_colors, y), style=y < 2 ? reg_div_l_style : hid_div_l_style, width=y < 2 ? reg_div_l_width : hid_div_l_width) : na
if y % 2 == 0
if old_pos_divs_can_be_removed
old_pos_divs_can_be_removed := false
if not showlast and remove_last_pos_divs
delete_last_pos_div_lines_label(last_pos_div_lines)
last_pos_div_lines := 0
last_pos_div_lines
if showlast
delete_old_pos_div_lines()
array.push(pos_div_lines, new_line)
last_pos_div_lines += 1
remove_last_pos_divs := true
remove_last_pos_divs
if y % 2 == 1
if old_neg_divs_can_be_removed
old_neg_divs_can_be_removed := false
if not showlast and remove_last_neg_divs
delete_last_neg_div_lines_label(last_neg_div_lines)
last_neg_div_lines := 0
last_neg_div_lines
if showlast
delete_old_neg_div_lines()
array.push(neg_div_lines, new_line)
last_neg_div_lines += 1
remove_last_neg_divs := true
remove_last_neg_divs
if y == 0
pos_reg_div_detected := true
pos_reg_div_detected
if y == 1
neg_reg_div_detected := true
neg_reg_div_detected
if y == 2
pos_hid_div_detected := true
pos_hid_div_detected
if y == 3
neg_hid_div_detected := true
neg_hid_div_detected
if div_type >= 0
divergence_text_top += (div_type % 2 == 1 ? showindis != "DON'T SHOW" ? array.get(indicators_name, x) + '\n' : '' : '')
divergence_text_bottom += (div_type % 2 == 0 ? showindis != "DON'T SHOW" ? array.get(indicators_name, x) + '\n' : '' : '')
divergence_text_bottom
if showindis != "DON'T SHOW"
if dnumdiv_top > 0
divergence_text_top += str.tostring(dnumdiv_top)
divergence_text_top
if dnumdiv_bottom > 0
divergence_text_bottom += str.tostring(dnumdiv_bottom)
divergence_text_bottom
if divergence_text_top != ''
if showlast
delete_old_neg_div_labels()
array.push(neg_div_labels, label.new(x=bar_index, y=math.max(high, high[1]), color=top_label_col, style=label.style_diamond, size = size.auto))
if divergence_text_bottom != ''
if showlast
delete_old_pos_div_labels()
array.push(pos_div_labels, label.new(x=bar_index, y=math.min(low, low[1]), color=bottom_label_col, style=label.style_diamond, size = size.auto))
// POSITION AND SIZE
PosTable = input.string(defval="Bottom Right", title="Position", options=["Top Right", "Middle Right", "Bottom Right", "Top Center", "Middle Center", "Bottom Center", "Top Left", "Middle Left", "Bottom Left"], group="Table Location & Size", inline="1")
SizTable = input.string(defval="Auto", title="Size", options=["Auto", "Huge", "Large", "Normal", "Small", "Tiny"], group="Table Location & Size", inline="1")
Pos1Table = PosTable == "Top Right" ? position.top_right : PosTable == "Middle Right" ? position.middle_right : PosTable == "Bottom Right" ? position.bottom_right : PosTable == "Top Center" ? position.top_center : PosTable == "Middle Center" ? position.middle_center : PosTable == "Bottom Center" ? position.bottom_center : PosTable == "Top Left" ? position.top_left : PosTable == "Middle Left" ? position.middle_left : position.bottom_left
Siz1Table = SizTable == "Auto" ? size.auto : SizTable == "Huge" ? size.huge : SizTable == "Large" ? size.large : SizTable == "Normal" ? size.normal : SizTable == "Small" ? size.small : size.tiny
tbl = table.new(Pos1Table, 21, 16, border_width = 1, border_color = color.gray, frame_color = color.gray, frame_width = 1)
// Kullanıcı tarafından belirlenecek yeşil ve kırmızı zaman dilimi sayısı
greenThreshold = input.int(5, minval=1, maxval=10, title="Yeşil Zaman Dilimi Sayısı", group="Alarm Ayarları")
redThreshold = input.int(5, minval=1, maxval=10, title="Kırmızı Zaman Dilimi Sayısı", group="Alarm Ayarları")
// TIMEFRAMES OPTIONS
box01 = input.bool(true, "TF[01]", inline = "01", group="Select Timeframe")
tf01 = input.timeframe("1", "", inline = "01", group="Select Timeframe")
box02 = input.bool(false, "TF[02]", inline = "02", group="Select Timeframe")
tf02 = input.timeframe("3", "", inline = "02", group="Select Timeframe")
box03 = input.bool(true, "TF[03]", inline = "03", group="Select Timeframe")
tf03 = input.timeframe("5", "", inline = "03", group="Select Timeframe")
box04 = input.bool(true, "TF[04]", inline = "04", group="Select Timeframe")
tf04 = input.timeframe("15", "", inline = "04", group="Select Timeframe")
box05 = input.bool(false, "TF[05]", inline = "05", group="Select Timeframe")
tf05 = input.timeframe("30", "", inline = "05", group="Select Timeframe")
box06 = input.bool(true, "TF[06]", inline = "01", group="Select Timeframe")
tf06 = input.timeframe("60", "", inline = "01", group="Select Timeframe")
box07 = input.bool(false, "TF[07]", inline = "02", group="Select Timeframe")
tf07 = input.timeframe("120", "", inline = "02", group="Select Timeframe")
box08 = input.bool(false, "TF[08]", inline = "03", group="Select Timeframe")
tf08 = input.timeframe("180", "", inline = "03", group="Select Timeframe")
box09 = input.bool(true, "TF[09]", inline = "04", group="Select Timeframe")
tf09 = input.timeframe("240", "", inline = "04", group="Select Timeframe")
box10 = input.bool(false, "TF[10]", inline = "05", group="Select Timeframe")
tf10 = input.timeframe("D", "", inline = "05", group="Select Timeframe")
// indicator('Tillson FEMA', overlay=true)
length1 = input(1, 'FEMA Length')
a1 = input(0.7, 'Volume Factor')
e1 = ta.ema((high + low + 2 * close) / 4, length1)
e2 = ta.ema(e1, length1)
e3 = ta.ema(e2, length1)
e4 = ta.ema(e3, length1)
e5 = ta.ema(e4, length1)
e6 = ta.ema(e5, length1)
c1 = -a1 * a1 * a1
c2 = 3 * a1 * a1 + 3 * a1 * a1 * a1
c3 = -6 * a1 * a1 - 3 * a1 - 3 * a1 * a1 * a1
c4 = 1 + 3 * a1 + a1 * a1 * a1 + 3 * a1 * a1
FEMA = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3
tablocol1 = FEMA > FEMA[1]
tablocol3 = FEMA < FEMA[1]
color_1 = col1 ? color.rgb(149, 219, 35): col3 ? color.rgb(238, 11, 11) : color.yellow
plot(FEMA, color=color_1, linewidth=3, title='FEMA')
tilson1 = FEMA
tilson1a =FEMA[1]
// DEFINITION OF VALUES
symbol = ticker.modify(syminfo.tickerid, syminfo.session)
tfArr = array.new<string>(na)
tilson1Arr = array.new<float>(na)
tilson1aArr = array.new<float>(na)
// DEFINITIONS OF RSI & CCI FUNCTIONS APPENDED IN THE TIMEFRAME OPTIONS
cciNcciFun(tf, flg) =>
[tilson_, tilson1a_] = request.security(symbol, tf, [tilson1, tilson1a])
if flg and (barstate.isrealtime ? true : timeframe.in_seconds(timeframe.period) <= timeframe.in_seconds(tf))
array.push(tfArr, na(tf) ? timeframe.period : tf)
array.push(tilson1Arr, tilson_)
array.push(tilson1aArr, tilson1a_)
cciNcciFun(tf01, box01), cciNcciFun(tf02, box02), cciNcciFun(tf03, box03), cciNcciFun(tf04, box04),
cciNcciFun(tf05, box05), cciNcciFun(tf06, box06), cciNcciFun(tf07, box07), cciNcciFun(tf08, box08),
cciNcciFun(tf09, box09), cciNcciFun(tf10, box10)
// TABLE AND CELLS CONFIG
// Post Timeframe in format
tfTxt(x)=>
out = x
if not str.contains(x, "S") and not str.contains(x, "M") and
not str.contains(x, "W") and not str.contains(x, "D")
if str.tonumber(x)%60 == 0
out := str.tostring(str.tonumber(x)/60)+"H"
else
out := x + "m"
out
if barstate.islast
table.clear(tbl, 0, 0, 20, 15)
// TITLES
table.cell(tbl, 0, 0, "⏱", text_color=color.white, text_size=Siz1Table, bgcolor=#000000)
table.cell(tbl, 1, 0, "FEMA("+str.tostring(length1)+")", text_color=#FFFFFF, text_size=Siz1Table, bgcolor=#000000)
j = 1
greenCounter = 0 // Yeşil zaman dilimlerini saymak için bir sayaç
redCounter = 0
if array.size(tilson1Arr) > 0
for i = 0 to array.size(tilson1Arr) - 1
if not na(array.get(tilson1Arr, i))
//config values in the cells
TF_VALUE = array.get(tfArr,i)
tilson1VALUE = array.get(tilson1Arr, i)
tilson1aVALUE = array.get(tilson1aArr, i)
SIGNAL1 = tilson1VALUE >= tilson1aVALUE ? "▲" : tilson1VALUE <= tilson1aVALUE ? "▼" : na
// Yeşil oklar ve arka planı ayarla
greenArrowColor1 = SIGNAL1 == "▲" ? color.rgb(0, 255, 0) : color.rgb(255, 0, 0)
greenBgColor1 = SIGNAL1 == "▲" ? color.rgb(25, 70, 22) : color.rgb(93, 22, 22)
allGreen = tilson1VALUE >= tilson1aVALUE
allRed = tilson1VALUE <= tilson1aVALUE
// Determine background color for time text
timeBgColor = allGreen ? #194616 : (allRed ? #5D1616 : #000000)
txtColor = allGreen ? #00FF00 : (allRed ? #FF4500 : color.white)
if allGreen
greenCounter := greenCounter + 1
redCounter := 0
else if allRed
redCounter := redCounter + 1
greenCounter := 0
else
redCounter := 0
greenCounter := 0
// Dinamik pair değerini oluşturma
pair = "USDT_" + syminfo.basecurrency + "USDT"
// Bot ID için kullanıcı girişi
bot_id = input.int(12387976, title="Bot ID", minval=0,group ='3Comas Message', inline = '1') // Varsayılan değeri 12387976 olan bir tamsayı girişi alır
// E-posta tokenı için kullanıcı girişi
email_token = input("cd4111d4-549a-4759-a082-e8f45c91fa47", title="Email Token",group ='3Comas Message', inline = '1')
// USER INPUT FOR DELAY
delay_seconds = input.int(0, title="Delay Seconds", minval=0, maxval=86400,group ='3Comas Message', inline = '1')
// Dinamik mesajın oluşturulması
message = '{ "message_type": "bot", "bot_id": ' + str.tostring(bot_id) + ', "email_token": "' + email_token + '", "delay_seconds": ' + str.tostring(delay_seconds) + ', "pair": "' + pair + '"}'
// Kullanıcının belirlediği yeşil veya kırmızı zaman dilimi sayısına ulaşıldığında alarmı tetikle
if greenCounter >= greenThreshold
alert(message, alert.freq_once_per_bar_close)
// if redCounter >= redThreshold
// alert(message, alert.freq_once_per_bar_close)
// Kullanıcının belirlediği yeşil veya kırmızı zaman dilimi sayısına ulaşıldığında alarmı tetikle
// if greenCounter >= greenThreshold
// alert("Yeşil zaman dilimi sayısı " + str.tostring(greenThreshold) + " adede ulaştı", alert.freq_once_per_bar_close)
// if redCounter >= redThreshold
// alert("Kırmızı zaman dilimi sayısı " + str.tostring(redThreshold) + " adede ulaştı", alert.freq_once_per_bar_close)
table.cell(tbl, 0, j, tfTxt(TF_VALUE), text_color=txtColor, text_halign=text.align_left, text_size=Siz1Table, bgcolor=timeBgColor)
table.cell(tbl, 1, j, str.tostring(tilson1VALUE, "#.#######")+SIGNAL1, text_color=greenArrowColor1, text_halign=text.align_right, text_size=Siz1Table, bgcolor=greenBgColor1)
j += 1
prd = input.int(defval=10, title='Pivot Period', minval=4, maxval=30, group='Setup')
ppsrc = input.string(defval='High/Low', title='Source', options=['High/Low', 'Close/Open'], group='Setup')
maxnumpp = input.int(defval=20, title=' Maximum Number of Pivot', minval=5, maxval=100, group='Setup')
ChannelW = input.int(defval=10, title='Maximum Channel Width %', minval=1, group='Setup')
maxnumsr = input.int(defval=5, title=' Maximum Number of S/R', minval=1, maxval=10, group='Setup')
min_strength = input.int(defval=2, title=' Minimum Strength', minval=1, maxval=10, group='Setup')
labelloc = input.int(defval=20, title='Label Location', group='Colors', tooltip='Positive numbers reference future bars, negative numbers reference histical bars')
linestyle = input.string(defval='Dashed', title='Line Style', options=['Solid', 'Dotted', 'Dashed'], group='Colors')
linewidth = input.int(defval=2, title='Line Width', minval=1, maxval=4, group='Colors')
resistancecolor = input.color(defval=color.red, title='Resistance Color', group='Colors')
supportcolor = input.color(defval=color.lime, title='Support Color', group='Colors')
showpp = input(false, title='Show Point Points')
float src1 = ppsrc == 'High/Low' ? high : math.max(close, open)
float src2 = ppsrc == 'High/Low' ? low : math.min(close, open)
float ph = ta.pivothigh(src1, prd, prd)
float pl = ta.pivotlow(src2, prd, prd)
plotshape(ph and showpp, text='H', style=shape.labeldown, color=na, textcolor=color.new(color.red, 0), location=location.abovebar, offset=-prd)
plotshape(pl and showpp, text='L', style=shape.labelup, color=na, textcolor=color.new(color.lime, 0), location=location.belowbar, offset=-prd)
Lstyle = linestyle == 'Dashed' ? line.style_dashed : linestyle == 'Solid' ? line.style_solid : line.style_dotted
//calculate maximum S/R channel zone width
prdhighest = ta.highest(300)
prdlowest = ta.lowest(300)
cwidth = (prdhighest - prdlowest) * ChannelW / 100
var pivotvals = array.new_float(0)
if ph or pl
array.unshift(pivotvals, ph ? ph : pl)
if array.size(pivotvals) > maxnumpp // limit the array size
array.pop(pivotvals)
get_sr_vals(ind) =>
float lo = array.get(pivotvals, ind)
float hi = lo
int numpp = 0
for y = 0 to array.size(pivotvals) - 1 by 1
float cpp = array.get(pivotvals, y)
float wdth = cpp <= lo ? hi - cpp : cpp - lo
if wdth <= cwidth // fits the max channel width?
if cpp <= hi
lo := math.min(lo, cpp)
else
hi := math.max(hi, cpp)
numpp += 1
numpp
[hi, lo, numpp]
var sr_up_level = array.new_float(0)
var sr_dn_level = array.new_float(0)
sr_strength = array.new_float(0)
find_loc(strength) =>
ret = array.size(sr_strength)
for i = ret > 0 ? array.size(sr_strength) - 1 : na to 0 by 1
if strength <= array.get(sr_strength, i)
break
ret := i
ret
ret
check_sr(hi, lo, strength) =>
ret = true
for i = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by 1
//included?
if array.get(sr_up_level, i) >= lo and array.get(sr_up_level, i) <= hi or array.get(sr_dn_level, i) >= lo and array.get(sr_dn_level, i) <= hi
if strength >= array.get(sr_strength, i)
array.remove(sr_strength, i)
array.remove(sr_up_level, i)
array.remove(sr_dn_level, i)
ret
else
ret := false
ret
break
ret
var sr_lines = array.new_line(11, na)
var sr_labels = array.new_label(11, na)
for x = 1 to 10 by 1
rate = 100 * (label.get_y(array.get(sr_labels, x)) - close) / close
label.set_text(array.get(sr_labels, x), text=str.tostring(label.get_y(array.get(sr_labels, x))) + '(' + str.tostring(rate, '#.##') + '%)')
label.set_x(array.get(sr_labels, x), x=bar_index + labelloc)
label.set_color(array.get(sr_labels, x), color=label.get_y(array.get(sr_labels, x)) >= close ? color.red : color.lime)
label.set_textcolor(array.get(sr_labels, x), textcolor=label.get_y(array.get(sr_labels, x)) >= close ? color.white : color.black)
label.set_style(array.get(sr_labels, x), style=label.get_y(array.get(sr_labels, x)) >= close ? label.style_label_down : label.style_label_up)
line.set_color(array.get(sr_lines, x), color=line.get_y1(array.get(sr_lines, x)) >= close ? resistancecolor : supportcolor)
if ph or pl
//because of new calculation, remove old S/R levels
array.clear(sr_up_level)
array.clear(sr_dn_level)
array.clear(sr_strength)
//find S/R zones
for x = 0 to array.size(pivotvals) - 1 by 1
[hi, lo, strength] = get_sr_vals(x)
if check_sr(hi, lo, strength)
loc = find_loc(strength)
// if strength is in first maxnumsr sr then insert it to the arrays
if loc < maxnumsr and strength >= min_strength
array.insert(sr_strength, loc, strength)
array.insert(sr_up_level, loc, hi)
array.insert(sr_dn_level, loc, lo)
// keep size of the arrays = 5
if array.size(sr_strength) > maxnumsr
array.pop(sr_strength)
array.pop(sr_up_level)
array.pop(sr_dn_level)
for x = 1 to 10 by 1
line.delete(array.get(sr_lines, x))
label.delete(array.get(sr_labels, x))
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by 1
float mid = math.round_to_mintick((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2)
rate = 100 * (mid - close) / close
array.set(sr_labels, x + 1, label.new(x=bar_index + labelloc, y=mid, text=str.tostring(mid) + '(' + str.tostring(rate, '#.##') + '%)', color=mid >= close ? color.red : color.lime, textcolor=mid >= close ? color.white : color.black, style=mid >= close ? label.style_label_down : label.style_label_up))
array.set(sr_lines, x + 1, line.new(x1=bar_index, y1=mid, x2=bar_index - 1, y2=mid, extend=extend.both, color=mid >= close ? resistancecolor : supportcolor, style=Lstyle, width=linewidth))
f_crossed_over() =>
ret = false
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by 1
float mid = math.round_to_mintick((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2)
if close[1] <= mid and close > mid
ret := true
ret
ret
f_crossed_under() =>
ret = false
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by 1
float mid = math.round_to_mintick((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2)
if close[1] >= mid and close < mid
ret := true
ret
ret
alertcondition(f_crossed_over(), title='Resistance Broken', message='Resistance Broken')
alertcondition(f_crossed_under(), title='Support Broken', message='Support Broken')
// © Femayakup
//version=5
indicator(title = "Kripto Fema ind", shorttitle="Kripto Fema ind", 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 Ayarları"
pmaxsrc = input(hl2, title="Source",group = group5)
Periods = input.int(title="ATR Length", defval=12,group = group5)
Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=4.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=#fbff04, linewidth=2, title="EMA9")
pALL=plot(PMax, color=color.new(color.red, 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 ? 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 ? 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)
//-----------------------------------------------------------------------------}
//////////////////////////////////////////////////////////////////////////////////
enableD = input (true, "DIVERGANCE ON/OFF" , group="INDICATORS ON/OFF")
//DIVERGANCE
prd1 = input.int (defval=5 , title='PIVOT PERIOD' , minval=1, maxval=50 , group="DIVERGANCE")
source = input.string(defval='HIGH/LOW' , title='SOURCE FOR PIVOT POINTS' , options=['CLOSE', 'HIGH/LOW'] , group="DIVERGANCE")
searchdiv = input.string(defval='REGULAR/HIDDEN', title='DIVERGANCE TYPE' , options=['REGULAR', 'HIDDEN', 'REGULAR/HIDDEN'], group="DIVERGANCE")
showindis = input.string(defval='FULL' , title='SHOW INDICATORS NAME' , options=['FULL', 'FIRST LETTER', "DON'T SHOW"] , group="DIVERGANCE")
showlimit = input.int(1 , title='MINIMUM NUMBER OF DIVERGANCES', minval=1, maxval=11 , group="DIVERGANCE")
maxpp = input.int (defval=20 , title='MAXIMUM PIVOT POINTS TO CHECK', minval=1, maxval=20 , group="DIVERGANCE")
maxbars = input.int (defval=200 , title='MAXIMUM BARS TO CHECK' , minval=30, maxval=200 , group="DIVERGANCE")
showlast = input (defval=false , title='SHOW ONLY LAST DIVERGANCE' , group="DIVERGANCE")
dontconfirm = input (defval=false , title="DON'T WAIT FOR CONFORMATION" , group="DIVERGANCE")
showlines = input (defval=false , title='SHOW DIVERGANCE LINES' , group="DIVERGANCE")
showpivot = input (defval=false , title='SHOW PIVOT POINTS' , group="DIVERGANCE")
calcmacd = input (defval=true , title='MACD' , group="DIVERGANCE")
calcmacda = input (defval=true , title='MACD HISTOGRAM' , group="DIVERGANCE")
calcrsi = input (defval=true , title='RSI' , group="DIVERGANCE")
calcstoc = input (defval=true , title='STOCHASTIC' , group="DIVERGANCE")
calccci = input (defval=true , title='CCI' , group="DIVERGANCE")
calcmom = input (defval=true , title='MOMENTUM' , group="DIVERGANCE")
calcobv = input (defval=true , title='OBV' , group="DIVERGANCE")
calcvwmacd = input (true , title='VWMACD' , group="DIVERGANCE")
calccmf = input (true , title='CHAIKIN MONEY FLOW' , group="DIVERGANCE")
calcmfi = input (true , title='MONEY FLOW INDEX' , group="DIVERGANCE")
calcext = input (false , title='CHECK EXTERNAL INDICATOR' , group="DIVERGANCE")
externalindi = input (defval=close , title='EXTERNAL INDICATOR' , group="DIVERGANCE")
pos_reg_div_col = input (defval=#ffffff , title='POSITIVE REGULAR DIVERGANCE' , group="DIVERGANCE")
neg_reg_div_col = input (defval=#00def6 , title='NEGATIVE REGULAR DIVERGANCE' , group="DIVERGANCE")
pos_hid_div_col = input (defval=#00ff0a , title='POSITIVE HIDDEN DIVERGANCE' , group="DIVERGANCE")
neg_hid_div_col = input (defval=#ff0015 , title='NEGATIVE HIDDEN DIVERGANCE' , group="DIVERGANCE")
reg_div_l_style_ = input.string(defval='SOLID' , title='REGULAR DIVERGANCE LINESTYLE' , options=['SOLID', 'DASHED', 'DOTTED'] , group="DIVERGANCE")
hid_div_l_style_ = input.string(defval='SOLID' , title='HIDDEN DIVERGANCE LINESTYLE' , options=['SOLID', 'DASHED', 'DOTTED'] , group="DIVERGANCE")
reg_div_l_width = input.int (defval=2 , title='REGULAR DIVERGANCE LINEWIDTH' , minval=1, maxval=5 , group="DIVERGANCE")
hid_div_l_width = input.int (defval=2 , title='HIDDEN DIVERGANCE LINEWIDTH' , minval=1, maxval=5 , group="DIVERGANCE")
showmas = input.bool (defval=false , title='SHOW MOVING AVERAGES (50 & 200)', inline='MA' , group="DIVERGANCE")
cma1col = input.color (defval=#ffffff , title='' , inline='MA' , group="DIVERGANCE")
cma2col = input.color (defval=#00def6 , title='' , inline='MA' , group="DIVERGANCE")
//PLOTS
plot(showmas ? ta.sma(close, 50) : na, color=showmas ? cma1col : na)
plot(showmas ? ta.sma(close, 200) : na, color=showmas ? cma2col : na)
var reg_div_l_style = reg_div_l_style_ == 'SOLID' ? line.style_solid : reg_div_l_style_ == 'DASHED' ? line.style_dashed : line.style_dotted
var hid_div_l_style = hid_div_l_style_ == 'SOLID' ? line.style_solid : hid_div_l_style_ == 'DASHED' ? line.style_dashed : line.style_dotted
rsi = ta.rsi(close, 14)
[macd, signal, deltamacd] = ta.macd(close, 12, 26, 9)
moment = ta.mom(close, 10)
cci = ta.cci(close, 10)
Obv = ta.obv
stk = ta.sma(ta.stoch(close, high, low, 14), 3)
maFast = ta.vwma(close, 12)
maSlow = ta.vwma(close, 26)
vwmacd = maFast - maSlow
Cmfm = (close - low - (high - close)) / (high - low)
Cmfv = Cmfm * volume
cmf = ta.sma(Cmfv, 21) / ta.sma(volume, 21)
Mfi = ta.mfi(close, 14)
var indicators_name = array.new_string(11)
var div_colors = array.new_color(4)
if barstate.isfirst and enableD
array.set(indicators_name, 0, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 1, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 2, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 3, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 4, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 5, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 6, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 7, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 8, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 9, showindis == "DON'T SHOW" ? '' : '')
array.set(indicators_name, 10, showindis == "DON'T SHOW" ? '' : '')
array.set(div_colors, 0, pos_reg_div_col)
array.set(div_colors, 1, neg_reg_div_col)
array.set(div_colors, 2, pos_hid_div_col)
array.set(div_colors, 3, neg_hid_div_col)
float ph1 = ta.pivothigh(source == 'CLOSE' ? close : high, prd1, prd1)
float pl1 = ta.pivotlow(source == 'CLOSE' ? close : low, prd1, prd1)
plotshape(ph1 and showpivot, text='H', style=shape.labeldown, color=color.new(color.white, 100), textcolor=#00def6, location=location.abovebar, offset=-prd1)
plotshape(pl1 and showpivot, text='L', style=shape.labelup, color=color.new(color.white, 100), textcolor=#ffffff, location=location.belowbar, offset=-prd1)
var int maxarraysize = 20
var ph_positions = array.new_int(maxarraysize, 0)
var pl_positions = array.new_int(maxarraysize, 0)
var ph_vals = array.new_float(maxarraysize, 0.)
var pl_vals = array.new_float(maxarraysize, 0.)
if ph1
array.unshift(ph_positions, bar_index)
array.unshift(ph_vals, ph1)
if array.size(ph_positions) > maxarraysize
array.pop(ph_positions)
array.pop(ph_vals)
if pl1
array.unshift(pl_positions, bar_index)
array.unshift(pl_vals, pl1)
if array.size(pl_positions) > maxarraysize
array.pop(pl_positions)
array.pop(pl_vals)
positive_regular_positive_hidden_divergence(src, cond) =>
divlen = 0
prsc = source == 'CLOSE' ? close : low
if dontconfirm or src > src[1] or close > close[1]
startpoint = dontconfirm ? 0 : 1
for x = 0 to maxpp - 1 by 1
len = bar_index - array.get(pl_positions, x) + prd1
if array.get(pl_positions, x) == 0 or len > maxbars
break
if len > 5 and (cond == 1 and src[startpoint] > src[len] and prsc[startpoint] < nz(array.get(pl_vals, x)) or cond == 2 and src[startpoint] < src[len] and prsc[startpoint] > nz(array.get(pl_vals, x)))
slope1 = (src[startpoint] - src[len]) / (len - startpoint)
virtual_line1 = src[startpoint] - slope1
slope2 = (close[startpoint] - close[len]) / (len - startpoint)
virtual_line2 = close[startpoint] - slope2
arrived = true
for y = 1 + startpoint to len - 1 by 1
if src[y] < virtual_line1 or nz(close[y]) < virtual_line2
arrived := false
break
virtual_line1 -= slope1
virtual_line2 -= slope2
virtual_line2
if arrived
divlen := len
break
divlen
negative_regular_negative_hidden_divergence(src, cond) =>
divlen = 0
prsc = source == 'CLOSE' ? close : high
if dontconfirm or src < src[1] or close < close[1]
startpoint = dontconfirm ? 0 : 1
for x = 0 to maxpp - 1 by 1
len = bar_index - array.get(ph_positions, x) + prd1
if array.get(ph_positions, x) == 0 or len > maxbars
break
if len > 5 and (cond == 1 and src[startpoint] < src[len] and prsc[startpoint] > nz(array.get(ph_vals, x)) or cond == 2 and src[startpoint] > src[len] and prsc[startpoint] < nz(array.get(ph_vals, x)))
slope1 = (src[startpoint] - src[len]) / (len - startpoint)
virtual_line1 = src[startpoint] - slope1
slope2 = (close[startpoint] - nz(close[len])) / (len - startpoint)
virtual_line2 = close[startpoint] - slope2
arrived = true
for y = 1 + startpoint to len - 1 by 1
if src[y] > virtual_line1 or nz(close[y]) > virtual_line2
arrived := false
break
virtual_line1 -= slope1
virtual_line2 -= slope2
virtual_line2
if arrived
divlen := len
break
divlen
//CALCULATIONS
calculate_divs(cond, indicator_1) =>
divs = array.new_int(4, 0)
array.set(divs, 0, cond and (searchdiv == 'REGULAR' or searchdiv == 'REGULAR/HIDDEN') ? positive_regular_positive_hidden_divergence(indicator_1, 1) : 0)
array.set(divs, 1, cond and (searchdiv == 'REGULAR' or searchdiv == 'REGULAR/HIDDEN') ? negative_regular_negative_hidden_divergence(indicator_1, 1) : 0)
array.set(divs, 2, cond and (searchdiv == 'HIDDEN' or searchdiv == 'REGULAR/HIDDEN') ? positive_regular_positive_hidden_divergence(indicator_1, 2) : 0)
array.set(divs, 3, cond and (searchdiv == 'HIDDEN' or searchdiv == 'REGULAR/HIDDEN') ? negative_regular_negative_hidden_divergence(indicator_1, 2) : 0)
divs
var all_divergences = array.new_int(44)
array_set_divs(div_pointer, index) =>
for x = 0 to 3 by 1
array.set(all_divergences, index * 4 + x, array.get(div_pointer, x))
array_set_divs(calculate_divs(calcmacd , macd) , 0)
array_set_divs(calculate_divs(calcmacda , deltamacd) , 1)
array_set_divs(calculate_divs(calcrsi , rsi) , 2)
array_set_divs(calculate_divs(calcstoc , stk) , 3)
array_set_divs(calculate_divs(calccci , cci) , 4)
array_set_divs(calculate_divs(calcmom , moment) , 5)
array_set_divs(calculate_divs(calcobv , Obv) , 6)
array_set_divs(calculate_divs(calcvwmacd, vwmacd) , 7)
array_set_divs(calculate_divs(calccmf , cmf) , 8)
array_set_divs(calculate_divs(calcmfi , Mfi) , 9)
array_set_divs(calculate_divs(calcext , externalindi), 10)
total_div = 0
for x = 0 to array.size(all_divergences) - 1 by 1
total_div += math.round(math.sign(array.get(all_divergences, x)))
total_div
if total_div < showlimit
array.fill(all_divergences, 0)
var pos_div_lines = array.new_line(0)
var neg_div_lines = array.new_line(0)
var pos_div_labels = array.new_label(0)
var neg_div_labels = array.new_label(0)
delete_old_pos_div_lines() =>
if array.size(pos_div_lines) > 0
for j = 0 to array.size(pos_div_lines) - 1 by 1
line.delete(array.get(pos_div_lines, j))
array.clear(pos_div_lines)
delete_old_neg_div_lines() =>
if array.size(neg_div_lines) > 0
for j = 0 to array.size(neg_div_lines) - 1 by 1
line.delete(array.get(neg_div_lines, j))
array.clear(neg_div_lines)
delete_old_pos_div_labels() =>
if array.size(pos_div_labels) > 0
for j = 0 to array.size(pos_div_labels) - 1 by 1
label.delete(array.get(pos_div_labels, j))
array.clear(pos_div_labels)
delete_old_neg_div_labels() =>
if array.size(neg_div_labels) > 0
for j = 0 to array.size(neg_div_labels) - 1 by 1
label.delete(array.get(neg_div_labels, j))
array.clear(neg_div_labels)
delete_last_pos_div_lines_label(n) =>
if n > 0 and array.size(pos_div_lines) >= n
asz = array.size(pos_div_lines)
for j = 1 to n by 1
line.delete(array.get(pos_div_lines, asz - j))
array.pop(pos_div_lines)
if array.size(pos_div_labels) > 0
label.delete(array.get(pos_div_labels, array.size(pos_div_labels) - 1))
array.pop(pos_div_labels)
delete_last_neg_div_lines_label(n) =>
if n > 0 and array.size(neg_div_lines) >= n
asz = array.size(neg_div_lines)
for j = 1 to n by 1
line.delete(array.get(neg_div_lines, asz - j))
array.pop(neg_div_lines)
if array.size(neg_div_labels) > 0
label.delete(array.get(neg_div_labels, array.size(neg_div_labels) - 1))
array.pop(neg_div_labels)
pos_reg_div_detected = false
neg_reg_div_detected = false
pos_hid_div_detected = false
neg_hid_div_detected = false
var last_pos_div_lines = 0
var last_neg_div_lines = 0
var remove_last_pos_divs = false
var remove_last_neg_divs = false
if pl1
remove_last_pos_divs := false
last_pos_div_lines := 0
last_pos_div_lines
if ph1
remove_last_neg_divs := false
last_neg_div_lines := 0
last_neg_div_lines
divergence_text_top = ''
divergence_text_bottom = ''
distances = array.new_int(0)
dnumdiv_top = 0
dnumdiv_bottom = 0
top_label_col = color.white
bottom_label_col = color.white
old_pos_divs_can_be_removed = true
old_neg_divs_can_be_removed = true
startpoint = dontconfirm ? 0 : 1
for x = 0 to 10 by 1
div_type = -1
for y = 0 to 3 by 1
if array.get(all_divergences, x * 4 + y) > 0
div_type := y
if y % 2 == 1
dnumdiv_top += 1
top_label_col := array.get(div_colors, y)
top_label_col
if y % 2 == 0
dnumdiv_bottom += 1
bottom_label_col := array.get(div_colors, y)
bottom_label_col
if not array.includes(distances, array.get(all_divergences, x * 4 + y))
array.push(distances, array.get(all_divergences, x * 4 + y))
new_line = showlines ? line.new(x1=bar_index - array.get(all_divergences, x * 4 + y), y1=source == 'CLOSE' ? close[array.get(all_divergences, x * 4 + y)] : y % 2 == 0 ? low[array.get(all_divergences, x * 4 + y)] : high[array.get(all_divergences, x * 4 + y)], x2=bar_index - startpoint, y2=source == 'CLOSE' ? close[startpoint] : y % 2 == 0 ? low[startpoint] : high[startpoint], color=array.get(div_colors, y), style=y < 2 ? reg_div_l_style : hid_div_l_style, width=y < 2 ? reg_div_l_width : hid_div_l_width) : na
if y % 2 == 0
if old_pos_divs_can_be_removed
old_pos_divs_can_be_removed := false
if not showlast and remove_last_pos_divs
delete_last_pos_div_lines_label(last_pos_div_lines)
last_pos_div_lines := 0
last_pos_div_lines
if showlast
delete_old_pos_div_lines()
array.push(pos_div_lines, new_line)
last_pos_div_lines += 1
remove_last_pos_divs := true
remove_last_pos_divs
if y % 2 == 1
if old_neg_divs_can_be_removed
old_neg_divs_can_be_removed := false
if not showlast and remove_last_neg_divs
delete_last_neg_div_lines_label(last_neg_div_lines)
last_neg_div_lines := 0
last_neg_div_lines
if showlast
delete_old_neg_div_lines()
array.push(neg_div_lines, new_line)
last_neg_div_lines += 1
remove_last_neg_divs := true
remove_last_neg_divs
if y == 0
pos_reg_div_detected := true
pos_reg_div_detected
if y == 1
neg_reg_div_detected := true
neg_reg_div_detected
if y == 2
pos_hid_div_detected := true
pos_hid_div_detected
if y == 3
neg_hid_div_detected := true
neg_hid_div_detected
if div_type >= 0
divergence_text_top += (div_type % 2 == 1 ? showindis != "DON'T SHOW" ? array.get(indicators_name, x) + '\n' : '' : '')
divergence_text_bottom += (div_type % 2 == 0 ? showindis != "DON'T SHOW" ? array.get(indicators_name, x) + '\n' : '' : '')
divergence_text_bottom
if showindis != "DON'T SHOW"
if dnumdiv_top > 0
divergence_text_top += str.tostring(dnumdiv_top)
divergence_text_top
if dnumdiv_bottom > 0
divergence_text_bottom += str.tostring(dnumdiv_bottom)
divergence_text_bottom
if divergence_text_top != ''
if showlast
delete_old_neg_div_labels()
array.push(neg_div_labels, label.new(x=bar_index, y=math.max(high, high[1]), color=top_label_col, style=label.style_diamond, size = size.auto))
if divergence_text_bottom != ''
if showlast
delete_old_pos_div_labels()
array.push(pos_div_labels, label.new(x=bar_index, y=math.min(low, low[1]), color=bottom_label_col, style=label.style_diamond, size = size.auto))
// POSITION AND SIZE
PosTable = input.string(defval="Bottom Right", title="Position", options=["Top Right", "Middle Right", "Bottom Right", "Top Center", "Middle Center", "Bottom Center", "Top Left", "Middle Left", "Bottom Left"], group="Table Location & Size", inline="1")
SizTable = input.string(defval="Auto", title="Size", options=["Auto", "Huge", "Large", "Normal", "Small", "Tiny"], group="Table Location & Size", inline="1")
Pos1Table = PosTable == "Top Right" ? position.top_right : PosTable == "Middle Right" ? position.middle_right : PosTable == "Bottom Right" ? position.bottom_right : PosTable == "Top Center" ? position.top_center : PosTable == "Middle Center" ? position.middle_center : PosTable == "Bottom Center" ? position.bottom_center : PosTable == "Top Left" ? position.top_left : PosTable == "Middle Left" ? position.middle_left : position.bottom_left
Siz1Table = SizTable == "Auto" ? size.auto : SizTable == "Huge" ? size.huge : SizTable == "Large" ? size.large : SizTable == "Normal" ? size.normal : SizTable == "Small" ? size.small : size.tiny
tbl = table.new(Pos1Table, 21, 16, border_width = 1, border_color = color.gray, frame_color = color.gray, frame_width = 1)
// Kullanıcı tarafından belirlenecek yeşil ve kırmızı zaman dilimi sayısı
greenThreshold = input.int(5, minval=1, maxval=10, title="Yeşil Zaman Dilimi Sayısı", group="Alarm Ayarları")
redThreshold = input.int(5, minval=1, maxval=10, title="Kırmızı Zaman Dilimi Sayısı", group="Alarm Ayarları")
// TIMEFRAMES OPTIONS
box01 = input.bool(true, "TF[01]", inline = "01", group="Select Timeframe")
tf01 = input.timeframe("1", "", inline = "01", group="Select Timeframe")
box02 = input.bool(false, "TF[02]", inline = "02", group="Select Timeframe")
tf02 = input.timeframe("3", "", inline = "02", group="Select Timeframe")
box03 = input.bool(true, "TF[03]", inline = "03", group="Select Timeframe")
tf03 = input.timeframe("5", "", inline = "03", group="Select Timeframe")
box04 = input.bool(true, "TF[04]", inline = "04", group="Select Timeframe")
tf04 = input.timeframe("15", "", inline = "04", group="Select Timeframe")
box05 = input.bool(false, "TF[05]", inline = "05", group="Select Timeframe")
tf05 = input.timeframe("30", "", inline = "05", group="Select Timeframe")
box06 = input.bool(true, "TF[06]", inline = "01", group="Select Timeframe")
tf06 = input.timeframe("60", "", inline = "01", group="Select Timeframe")
box07 = input.bool(false, "TF[07]", inline = "02", group="Select Timeframe")
tf07 = input.timeframe("120", "", inline = "02", group="Select Timeframe")
box08 = input.bool(false, "TF[08]", inline = "03", group="Select Timeframe")
tf08 = input.timeframe("180", "", inline = "03", group="Select Timeframe")
box09 = input.bool(true, "TF[09]", inline = "04", group="Select Timeframe")
tf09 = input.timeframe("240", "", inline = "04", group="Select Timeframe")
box10 = input.bool(false, "TF[10]", inline = "05", group="Select Timeframe")
tf10 = input.timeframe("D", "", inline = "05", group="Select Timeframe")
// indicator('Tillson FEMA', overlay=true)
length1 = input(1, 'FEMA Length')
a1 = input(0.7, 'Volume Factor')
e1 = ta.ema((high + low + 2 * close) / 4, length1)
e2 = ta.ema(e1, length1)
e3 = ta.ema(e2, length1)
e4 = ta.ema(e3, length1)
e5 = ta.ema(e4, length1)
e6 = ta.ema(e5, length1)
c1 = -a1 * a1 * a1
c2 = 3 * a1 * a1 + 3 * a1 * a1 * a1
c3 = -6 * a1 * a1 - 3 * a1 - 3 * a1 * a1 * a1
c4 = 1 + 3 * a1 + a1 * a1 * a1 + 3 * a1 * a1
FEMA = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3
tablocol1 = FEMA > FEMA[1]
tablocol3 = FEMA < FEMA[1]
color_1 = col1 ? color.rgb(149, 219, 35): col3 ? color.rgb(238, 11, 11) : color.yellow
plot(FEMA, color=color_1, linewidth=3, title='FEMA')
tilson1 = FEMA
tilson1a =FEMA[1]
// DEFINITION OF VALUES
symbol = ticker.modify(syminfo.tickerid, syminfo.session)
tfArr = array.new<string>(na)
tilson1Arr = array.new<float>(na)
tilson1aArr = array.new<float>(na)
// DEFINITIONS OF RSI & CCI FUNCTIONS APPENDED IN THE TIMEFRAME OPTIONS
cciNcciFun(tf, flg) =>
[tilson_, tilson1a_] = request.security(symbol, tf, [tilson1, tilson1a])
if flg and (barstate.isrealtime ? true : timeframe.in_seconds(timeframe.period) <= timeframe.in_seconds(tf))
array.push(tfArr, na(tf) ? timeframe.period : tf)
array.push(tilson1Arr, tilson_)
array.push(tilson1aArr, tilson1a_)
cciNcciFun(tf01, box01), cciNcciFun(tf02, box02), cciNcciFun(tf03, box03), cciNcciFun(tf04, box04),
cciNcciFun(tf05, box05), cciNcciFun(tf06, box06), cciNcciFun(tf07, box07), cciNcciFun(tf08, box08),
cciNcciFun(tf09, box09), cciNcciFun(tf10, box10)
// TABLE AND CELLS CONFIG
// Post Timeframe in format
tfTxt(x)=>
out = x
if not str.contains(x, "S") and not str.contains(x, "M") and
not str.contains(x, "W") and not str.contains(x, "D")
if str.tonumber(x)%60 == 0
out := str.tostring(str.tonumber(x)/60)+"H"
else
out := x + "m"
out
if barstate.islast
table.clear(tbl, 0, 0, 20, 15)
// TITLES
table.cell(tbl, 0, 0, "⏱", text_color=color.white, text_size=Siz1Table, bgcolor=#000000)
table.cell(tbl, 1, 0, "FEMA("+str.tostring(length1)+")", text_color=#FFFFFF, text_size=Siz1Table, bgcolor=#000000)
j = 1
greenCounter = 0 // Yeşil zaman dilimlerini saymak için bir sayaç
redCounter = 0
if array.size(tilson1Arr) > 0
for i = 0 to array.size(tilson1Arr) - 1
if not na(array.get(tilson1Arr, i))
//config values in the cells
TF_VALUE = array.get(tfArr,i)
tilson1VALUE = array.get(tilson1Arr, i)
tilson1aVALUE = array.get(tilson1aArr, i)
SIGNAL1 = tilson1VALUE >= tilson1aVALUE ? "▲" : tilson1VALUE <= tilson1aVALUE ? "▼" : na
// Yeşil oklar ve arka planı ayarla
greenArrowColor1 = SIGNAL1 == "▲" ? color.rgb(0, 255, 0) : color.rgb(255, 0, 0)
greenBgColor1 = SIGNAL1 == "▲" ? color.rgb(25, 70, 22) : color.rgb(93, 22, 22)
allGreen = tilson1VALUE >= tilson1aVALUE
allRed = tilson1VALUE <= tilson1aVALUE
// Determine background color for time text
timeBgColor = allGreen ? #194616 : (allRed ? #5D1616 : #000000)
txtColor = allGreen ? #00FF00 : (allRed ? #FF4500 : color.white)
if allGreen
greenCounter := greenCounter + 1
redCounter := 0
else if allRed
redCounter := redCounter + 1
greenCounter := 0
else
redCounter := 0
greenCounter := 0
// Dinamik pair değerini oluşturma
pair = "USDT_" + syminfo.basecurrency + "USDT"
// Bot ID için kullanıcı girişi
bot_id = input.int(12387976, title="Bot ID", minval=0,group ='3Comas Message', inline = '1') // Varsayılan değeri 12387976 olan bir tamsayı girişi alır
// E-posta tokenı için kullanıcı girişi
email_token = input("cd4111d4-549a-4759-a082-e8f45c91fa47", title="Email Token",group ='3Comas Message', inline = '1')
// USER INPUT FOR DELAY
delay_seconds = input.int(0, title="Delay Seconds", minval=0, maxval=86400,group ='3Comas Message', inline = '1')
// Dinamik mesajın oluşturulması
message = '{ "message_type": "bot", "bot_id": ' + str.tostring(bot_id) + ', "email_token": "' + email_token + '", "delay_seconds": ' + str.tostring(delay_seconds) + ', "pair": "' + pair + '"}'
// Kullanıcının belirlediği yeşil veya kırmızı zaman dilimi sayısına ulaşıldığında alarmı tetikle
if greenCounter >= greenThreshold
alert(message, alert.freq_once_per_bar_close)
// if redCounter >= redThreshold
// alert(message, alert.freq_once_per_bar_close)
// Kullanıcının belirlediği yeşil veya kırmızı zaman dilimi sayısına ulaşıldığında alarmı tetikle
// if greenCounter >= greenThreshold
// alert("Yeşil zaman dilimi sayısı " + str.tostring(greenThreshold) + " adede ulaştı", alert.freq_once_per_bar_close)
// if redCounter >= redThreshold
// alert("Kırmızı zaman dilimi sayısı " + str.tostring(redThreshold) + " adede ulaştı", alert.freq_once_per_bar_close)
table.cell(tbl, 0, j, tfTxt(TF_VALUE), text_color=txtColor, text_halign=text.align_left, text_size=Siz1Table, bgcolor=timeBgColor)
table.cell(tbl, 1, j, str.tostring(tilson1VALUE, "#.#######")+SIGNAL1, text_color=greenArrowColor1, text_halign=text.align_right, text_size=Siz1Table, bgcolor=greenBgColor1)
j += 1
prd = input.int(defval=10, title='Pivot Period', minval=4, maxval=30, group='Setup')
ppsrc = input.string(defval='High/Low', title='Source', options=['High/Low', 'Close/Open'], group='Setup')
maxnumpp = input.int(defval=20, title=' Maximum Number of Pivot', minval=5, maxval=100, group='Setup')
ChannelW = input.int(defval=10, title='Maximum Channel Width %', minval=1, group='Setup')
maxnumsr = input.int(defval=5, title=' Maximum Number of S/R', minval=1, maxval=10, group='Setup')
min_strength = input.int(defval=2, title=' Minimum Strength', minval=1, maxval=10, group='Setup')
labelloc = input.int(defval=20, title='Label Location', group='Colors', tooltip='Positive numbers reference future bars, negative numbers reference histical bars')
linestyle = input.string(defval='Dashed', title='Line Style', options=['Solid', 'Dotted', 'Dashed'], group='Colors')
linewidth = input.int(defval=2, title='Line Width', minval=1, maxval=4, group='Colors')
resistancecolor = input.color(defval=color.red, title='Resistance Color', group='Colors')
supportcolor = input.color(defval=color.lime, title='Support Color', group='Colors')
showpp = input(false, title='Show Point Points')
float src1 = ppsrc == 'High/Low' ? high : math.max(close, open)
float src2 = ppsrc == 'High/Low' ? low : math.min(close, open)
float ph = ta.pivothigh(src1, prd, prd)
float pl = ta.pivotlow(src2, prd, prd)
plotshape(ph and showpp, text='H', style=shape.labeldown, color=na, textcolor=color.new(color.red, 0), location=location.abovebar, offset=-prd)
plotshape(pl and showpp, text='L', style=shape.labelup, color=na, textcolor=color.new(color.lime, 0), location=location.belowbar, offset=-prd)
Lstyle = linestyle == 'Dashed' ? line.style_dashed : linestyle == 'Solid' ? line.style_solid : line.style_dotted
//calculate maximum S/R channel zone width
prdhighest = ta.highest(300)
prdlowest = ta.lowest(300)
cwidth = (prdhighest - prdlowest) * ChannelW / 100
var pivotvals = array.new_float(0)
if ph or pl
array.unshift(pivotvals, ph ? ph : pl)
if array.size(pivotvals) > maxnumpp // limit the array size
array.pop(pivotvals)
get_sr_vals(ind) =>
float lo = array.get(pivotvals, ind)
float hi = lo
int numpp = 0
for y = 0 to array.size(pivotvals) - 1 by 1
float cpp = array.get(pivotvals, y)
float wdth = cpp <= lo ? hi - cpp : cpp - lo
if wdth <= cwidth // fits the max channel width?
if cpp <= hi
lo := math.min(lo, cpp)
else
hi := math.max(hi, cpp)
numpp += 1
numpp
[hi, lo, numpp]
var sr_up_level = array.new_float(0)
var sr_dn_level = array.new_float(0)
sr_strength = array.new_float(0)
find_loc(strength) =>
ret = array.size(sr_strength)
for i = ret > 0 ? array.size(sr_strength) - 1 : na to 0 by 1
if strength <= array.get(sr_strength, i)
break
ret := i
ret
ret
check_sr(hi, lo, strength) =>
ret = true
for i = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by 1
//included?
if array.get(sr_up_level, i) >= lo and array.get(sr_up_level, i) <= hi or array.get(sr_dn_level, i) >= lo and array.get(sr_dn_level, i) <= hi
if strength >= array.get(sr_strength, i)
array.remove(sr_strength, i)
array.remove(sr_up_level, i)
array.remove(sr_dn_level, i)
ret
else
ret := false
ret
break
ret
var sr_lines = array.new_line(11, na)
var sr_labels = array.new_label(11, na)
for x = 1 to 10 by 1
rate = 100 * (label.get_y(array.get(sr_labels, x)) - close) / close
label.set_text(array.get(sr_labels, x), text=str.tostring(label.get_y(array.get(sr_labels, x))) + '(' + str.tostring(rate, '#.##') + '%)')
label.set_x(array.get(sr_labels, x), x=bar_index + labelloc)
label.set_color(array.get(sr_labels, x), color=label.get_y(array.get(sr_labels, x)) >= close ? color.red : color.lime)
label.set_textcolor(array.get(sr_labels, x), textcolor=label.get_y(array.get(sr_labels, x)) >= close ? color.white : color.black)
label.set_style(array.get(sr_labels, x), style=label.get_y(array.get(sr_labels, x)) >= close ? label.style_label_down : label.style_label_up)
line.set_color(array.get(sr_lines, x), color=line.get_y1(array.get(sr_lines, x)) >= close ? resistancecolor : supportcolor)
if ph or pl
//because of new calculation, remove old S/R levels
array.clear(sr_up_level)
array.clear(sr_dn_level)
array.clear(sr_strength)
//find S/R zones
for x = 0 to array.size(pivotvals) - 1 by 1
[hi, lo, strength] = get_sr_vals(x)
if check_sr(hi, lo, strength)
loc = find_loc(strength)
// if strength is in first maxnumsr sr then insert it to the arrays
if loc < maxnumsr and strength >= min_strength
array.insert(sr_strength, loc, strength)
array.insert(sr_up_level, loc, hi)
array.insert(sr_dn_level, loc, lo)
// keep size of the arrays = 5
if array.size(sr_strength) > maxnumsr
array.pop(sr_strength)
array.pop(sr_up_level)
array.pop(sr_dn_level)
for x = 1 to 10 by 1
line.delete(array.get(sr_lines, x))
label.delete(array.get(sr_labels, x))
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by 1
float mid = math.round_to_mintick((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2)
rate = 100 * (mid - close) / close
array.set(sr_labels, x + 1, label.new(x=bar_index + labelloc, y=mid, text=str.tostring(mid) + '(' + str.tostring(rate, '#.##') + '%)', color=mid >= close ? color.red : color.lime, textcolor=mid >= close ? color.white : color.black, style=mid >= close ? label.style_label_down : label.style_label_up))
array.set(sr_lines, x + 1, line.new(x1=bar_index, y1=mid, x2=bar_index - 1, y2=mid, extend=extend.both, color=mid >= close ? resistancecolor : supportcolor, style=Lstyle, width=linewidth))
f_crossed_over() =>
ret = false
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by 1
float mid = math.round_to_mintick((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2)
if close[1] <= mid and close > mid
ret := true
ret
ret
f_crossed_under() =>
ret = false
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by 1
float mid = math.round_to_mintick((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2)
if close[1] >= mid and close < mid
ret := true
ret
ret
alertcondition(f_crossed_over(), title='Resistance Broken', message='Resistance Broken')
alertcondition(f_crossed_under(), title='Support Broken', message='Support Broken')
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.