AI Gold N
AI Gold N
// Functions
supertrend(_src, factor, atrLen) =>
atr = ta.atr(atrLen)
upperBand = _src + factor * atr
lowerBand = _src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ?
lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ?
upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
[superTrend, direction]
// Get Components
ocAvg = math.avg(open, close)
ema1 = ta.ema(high, 9)
ema2 = ta.ema(high, 12)
ema3 = ta.ema(high, 15)
ema4 = ta.ema(high, 18)
sma1 = ta.sma(close, 5)
sma2 = ta.sma(close, 6)
sma3 = ta.sma(close, 7)
sma4 = ta.sma(close, 8)
sma5 = ta.sma(close, 9)
sma6 = ta.sma(close, 10)
sma7 = ta.sma(close, 11)
sma8 = ta.sma(close, 12)
sma9 = ta.sma(close, 13)
sma10 = ta.sma(close, 14)
sma11 = ta.sma(close, 15)
sma12 = ta.sma(close, 16)
sma13 = ta.sma(close, 17)
sma14 = ta.sma(close, 18)
sma15 = ta.sma(close, 19)
sma16 = ta.sma(close, 20)
psar = ta.sar(0.02, 0.02, 0.2)
[supertrend, direction] = supertrend(close, sensitivity, 11)
barsL = 10
barsR = 10
pivotHigh = fixnan(ta.pivothigh(barsL, barsR)[1])
pivotLow = fixnan(ta.pivotlow(barsL, barsR)[1])
// Colors
green = #2BBC4D, green2 = #00DD00
red = #C51D0B, red2 = #DD0000
emaCloudColor = emaCloud ? (close > supertrend ? #71CD6D : #D75131) : na
emaEnergyColor(ma) => emaEnergy ? (close >= ma ? green : red) : na
// Plots
p1 = plot(ema1, "", na, editable=false)
p2 = plot(ema2, "", emaCloudColor, editable=false)
p3 = plot(ema3, "", emaCloudColor, editable=false)
p4 = plot(ema4, "", na, editable=false)
fill(p1, p2, emaCloud ? (ema2 > ema3 ? color.new(#D75131, 80) : color.new(#71CD6D,
80)) : na)
fill(p4, p3, emaCloud ? (ema2 < ema3 ? color.new(#D75131, 80) : color.new(#71CD6D,
80)) : na)
fill(p2, p3, emaCloud ? color.new(emaCloudColor, 35) : na)
plot(sma1, "", emaEnergyColor(sma1), editable=false)
plot(sma2, "", emaEnergyColor(sma2), editable=false)
plot(sma3, "", emaEnergyColor(sma3), editable=false)
plot(sma4, "", emaEnergyColor(sma4), editable=false)
plot(sma5, "", emaEnergyColor(sma5), editable=false)
plot(sma6, "", emaEnergyColor(sma6), editable=false)
plot(sma7, "", emaEnergyColor(sma7), editable=false)
plot(sma8, "", emaEnergyColor(sma8), editable=false)
plot(sma9, "", emaEnergyColor(sma9), editable=false)
plot(sma10, "", emaEnergyColor(sma10), editable=false)
plot(sma11, "", emaEnergyColor(sma11), editable=false)
plot(sma12, "", emaEnergyColor(sma12), editable=false)
plot(sma13, "", emaEnergyColor(sma13), editable=false)
plot(sma14, "", emaEnergyColor(sma14), editable=false)
plot(sma15, "", emaEnergyColor(sma15), editable=false)
plot(sma16, "", emaEnergyColor(sma16), editable=false)
barcolor(close > supertrend ? #2BE300 : red2)
countBull = ta.barssince(bull)
countBear = ta.barssince(bear)
// Alerts
alertcondition(bull or bear, "AI Signal Alert", "AI Signals Gold\nAlert Triggered
on {{ticker}} @ {{close}}")
alertcondition(bull, "Alert Buy", "AI Signals Gold\nBuy {{ticker}} @ {{close}}")
alertcondition(bear, "Alert Sell", "AI Signals Gold\nSell {{ticker}} @ {{close}}")
alertcondition(ta.crossover(close, pivotHigh), "Broke Resistance", "AI Signals
Gold\nBroke Resistance on {{ticker}} @ {{close}}")
alertcondition(ta.crossunder(close, pivotLow), "Broke Support", "AI Signals Gold\
nBroke Support on {{ticker}} @ {{close}}")
prd = (10)
ppsrc = ('High/Low')
maxnumpp = (20)
ChannelW = (10)
maxnumsr = (5)
min_strength = (2)
labelloc = (0)
linestyle = input.string(defval='Dashed', title='Line Style', options=['Solid',
'Dotted', 'Dashed'], group="S & R")
linewidth = input.int(defval=2, title='Line Width', minval=1, maxval=4, group="S &
R")
resistancecolor = (color.rgb(255,0,146,0))
supportcolor = (color.rgb(0,186,255,0))
showpp = (false)
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?
lo := cpp <= lo ? cpp : lo
hi := cpp > lo ? cpp : hi
numpp += 1
numpp
[hi, lo, numpp]
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
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.rgb(0,186,255,100) : color.rgb(255,0,146,100))
label.set_textcolor(array.get(sr_labels, x),
textcolor=label.get_y(array.get(sr_labels, x)) >= close ?
color.rgb(0,186,255,100) : color.rgb(0,186,255,100))
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))
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
// Security function
secSMA(_res) =>
request.security(syminfo.tickerid, showDashboard ? _res : timeframe.period,
ta.sma(ohlc4, 200) < close, lookahead=barmerge.lookahead_on)
//}
// 2. 15min
trend15min = secSMA(showDashboard ? '15' : '15') ? 'Bullish??' : 'Bearish??'
// 3. 1hr
trend1hr = secSMA(showDashboard ? '60' : '15') ? 'Bullish??' : 'Bearish??'
// 4. 4hr
trend4hr = secSMA(showDashboard ? '240' : '15') ? 'Bullish??' : 'Bearish??'
// 5. 1D
trend1d = secSMA(showDashboard ? '1D' : '15') ? 'Bullish??' : 'Bearish??'
// 2. 3min
trend3min = secSMA(advDash and showDashboard ? '3' : '15') ? 'Bullish??' :
'Bearish??'
// 3. 5min
trend5min = secSMA(advDash and showDashboard ? '5' : '15') ? 'Bullish??' :
'Bearish??'
// 4. 10min
trend10min = secSMA(advDash and showDashboard ? '10' : '15') ? 'Bullish??' :
'Bearish??'
// 5. 30min
trend30min = secSMA(advDash and showDashboard ? '30' : '15') ? 'Bullish??' :
'Bearish??'
// 6. 2hr
trend12hr = secSMA(advDash and showDashboard ? '720' : '15') ? 'Bullish??' :
'Bearish??'
// 7. 12hr
trend2hr = secSMA(advDash and showDashboard ? '120' : '15') ? 'Bullish??' :
'Bearish??'
// RSI condition
rsiCond = rsiTrend < 30 ? 'Oversold (' + str.tostring(math.round(rsiTrend, 2)) +
')' : rsiTrend > 70 ? 'Overbought (' + str.tostring(math.round(rsiTrend, 2)) +
')' : 'Healthy (' + str.tostring(math.round(rsiTrend, 2)) + ')'
// ATR function
atrTrend = ta.atr(14)
atrTrendCond = atrTrend > ta.ema(ta.sma(atrTrend, 100), 100) ? 'Trending' :
'Ranging'
label dashboard = na
if showDashboard
dashboard := label.new(x=time + btime * xDashBoard, y=(ta.highest(20) +
ta.lowest(20)) / 2, text='??discord.gg/indicator??' + '\n\nCurrent Trend: ' +
trendCurrent + '\nPrice condition: ' + rsiCond + '\nVolume: ' +
str.tostring(math.round(volume * close, 2)) + ' ' + syminfo.currency + '\
nVolatility: ' + atrTrendCond + '\n\n_____________________' + (advDash ? '\n\
n1min: ' + trend1min : '') + (advDash ? '\n3min: ' + trend3min : '') + (advDash ?
'\n5min: ' + trend5min : '') + (advDash ? '\n10min: ' + trend10min : '') + '\
n15min: ' + trend15min + (advDash ? '\n30min: ' + trend30min : '') + '\n1hr: ' +
trend1hr + (advDash ? '\n2hr: ' + trend2hr : '') + '\n4hr: ' + trend4hr +
(advDash ? '\n12hr: ' + trend12hr : '') + '\nDaily: ' + trend1d, color=color.black,
textcolor=color.white, style=label.style_label_left, xloc=xloc.bar_time,
yloc=yloc.price, textalign=text.align_left)
dashboard
label.delete(dashboard[1])