Trading View Indicator Codes
Trading View Indicator Codes
//
@versio
n=5
indicator('TriexDev - SuperBuySellTrend (PLUS+)', overlay=true, format=format.price, precision=2)
// The ATR is then a moving average, generally using 10/14 days, of the
// true ranges.
// Config
pivot_offset_input = input.int(group='Label offsets', title='Pivot', defval=-5, inline='labeloffset')
label_offset_input = input.int(group='Label offsets', title='MA/HiLo', defval=5, inline='labeloffset')
// Vector candles inspired from TradersReality
// Price, Volume, Support, Resistance Analysis (PVSRA)
// PVSRA helps determine if the Marker Makers are bearish or bullish, and if their price movement is in the "run
bool overridesym = input.bool(group='PVSRA', title='Override chart symbol?', defval=false, inline='pvsra')
string pvsra_sym = input.symbol(group='PVSRA', title='', defval='INDEX:BTCUSD', tooltip='You can use INDEX:BTCUSD
example \'(BINANCE:BTCUSDT+COINBASE:BTCUSD)\'. Note that adding too many will slow things down.', inline='pvsra')
// EMA
showEmas = input.bool(group='EMAs', title='Show EMAs?', defval=true, inline='showemas')
labelEmas = input.bool(group='EMAs', title='EMA Labels?', defval=false, inline='showemas')
threeEmaColor = input.color(group='EMAs', title='50', defval=color.rgb(31, 188, 211, 0), inline='emacolors')
fourEmaColor = input.color(group='EMAs', title='200', defval=color.rgb(255, 255, 255, 0), inline='emacolors')
fiveEmaColor = input.color(group='EMAs', title='800', defval=color.rgb(50, 34, 144, 0), inline='emacolors')
EmaCloudColor = input.color(group='EMAs', title='EMA Cloud', defval=color.rgb(155, 47, 174, 60), inline='emacloud
EmaCloudBorderColor = input.color(group='EMAs', title='Border', defval=color.rgb(18, 137, 123, 100), inline='emac
// Pivot Points
showDayHighLow = input.bool(group='Daily High/low', title='Show Hi/Lo: Daily?', defval=true, inline='highlow')
showWeekHighLow = input.bool(group='Daily High/low', title='Weekly?', defval=true, inline='highlow')
showDayHighLowLabels = input.bool(group='Daily High/low', title='Show labels?', defval=true, inline='highlow')
// Psy Levels
bool showPsy = timeframe.isminutes and (timeframe.multiplier == 60 or timeframe.multiplier == 30 or timeframe.mul
or timeframe.multiplier == 3 or timeframe.multiplier == 1)
bool show_psylevels = input.bool(group='Weekly Psy Levels (valid tf 1h/30min/15min/5min/3min/1min)', defval=true,
and showPsy
bool show_psylabel = input.bool(group='Weekly Psy Levels (valid tf 1h/30min/15min/5min/3min/1min)', defval=true,
tooltip="The Psy High/Low will only show on these timeframes: 1h/30min/15min/5min/3min/1min. It is disabled on al
requires a candle to start at the correct time for Sydney but in other timeframes the data does not have values a
session.") and show_psylevels
bool showallPsy = false//input.bool(Weekly Psy Levels (valid tf 1h/30min/15min/5min/3min/1min), defval=false, tit
inline='psyconf')
color psycolH = input.color(group='Weekly Psy Levels (valid tf 1h/30min/15min/5min/3min/1min)', title='Psy Hi Col
inline='psyconf1')
color psycolL = input.color(group='Weekly Psy Levels (valid tf 1h/30min/15min/5min/3min/1min)', title='Psy Low Co
inline='psyconf1')
var string psy_gmt = "GMT+3"
// Functions
// new_bar: check if we're on a new bar within the session in a given resolution
new_bar(res) =>
ta.change(time(res)) != 0
//Right_Label
r_label(ry, rtext, rstyle, rcolor, valid) =>
if valid and barstate.isrealtime
rLabel = label.new(x=label_x_offset, y=ry, text=rtext, xloc=xloc.bar_time, style=rstyle, textcolor=rcolor, textal
label.delete(rLabel[1])
draw_line(x_series, res, tag, xColor, xStyle, xWidth, xExtend, isLabelValid, xLabelOffset) =>
var line x_line = na
label.delete(pivot_label[1])
if not barstate.islast
line.set_x2(pivot_line, x=bar_index)
else
line.set_xloc(pivot_line, levelsstart, time_close + 1 * 86400000, xloc=xloc.bar_time)
pivot_line
gmtD = gmt_off_val
current_session = time(res, sessionString, gmtD) - sessStartAdjustMilis
if not na(current_session)
pivot_line = line.new(current_session, pivot_level, timenow, pivot_level, xloc=xloc.bar_time, extend=pivotExtend,
width=pivotWidth)
line.delete(pivot_line[1])
if isLabelValid
pivot_label = label.new(label_offset, pivot_level, tag, xloc=xloc.bar_time, style=label.style_none, textcolor=piv
label.delete(pivot_label[1])
pivot_line
if sessXorcalc
for i = 0 to lookbackOrBars by 1
orX_h := i == 0 ? high : math.max(high[i], orX_h)
orX_l := i == 0 ? low : math.min(low[i], orX_l)
orX_l
[orX_l, orX_h]
////////////
//calculate sess and sessorcalc function
///////////
// calcSessAndSessOr(sessXTime, showX_or, lookbackMinsX, lookbackOrBarsX) =>
// int sessX = time(timeframe.period, sessXTime)
// bool sessXorcalc = sessX[lookbackOrBarsX] and na(sessX[lookbackOrBarsX + 1]) and showX_or
// [sessX, sessXorcalc]
// EMAs
threeEmaLength = 50
fourEmaLength = 200
fiveEmaLength = 800
// Daily H/L
weekHigh = f_security(syminfo.tickerid, 'W', high, false)
weekLow = f_security(syminfo.tickerid, 'W', low, false)
plot(validDHLTimeFrame and showDayHighLow and (showDayHighLow ? true : isToday) ? dayHigh : na, linewidth=1, colo
style=plot.style_linebr, title="YDay Hi")
plot(validDHLTimeFrame and showDayHighLow and (showDayHighLow ? true : isToday) ? dayLow : na, linewidth=1, color
style=plot.style_linebr, title="YDay Lo")
r_label(dayHigh, 'YDay Hi', label.style_none, color.blue, validDHLTimeFrame and showDayHighLow and showDayHighLow
r_label(dayLow, 'YDay Lo', label.style_none, color.blue, validDHLTimeFrame and showDayHighLow and showDayHighLowL
plot(validWHLTimeFrame and showWeekHighLow and (showWeekHighLow ? true : isThisWeek) ? weekHigh : na, linewidth=1
style=plot.style_linebr, title="LWeek Hi")
plot(validWHLTimeFrame and showWeekHighLow and (showWeekHighLow ? true : isThisWeek) ? weekLow : na, linewidth=1,
style=plot.style_linebr, title="LWeek Lo")
r_label(weekHigh, 'LWeek Hi', label.style_none, color.green, validWHLTimeFrame and showWeekHighLow and showDayHig
valid
r_label(weekLow, 'LWeek Lo', label.style_none, color.green, validWHLTimeFrame and showWeekHighLow and showDayHigh
// PVSRA
// From MT4 source:
// Situation "Climax"
// Bars with volume >= 200% of the average volume of the 10 previous chart TFs, and bars
// where the product of candle spread x candle volume is >= the highest for the 10 previous
// chart time TFs.
// Default Colors: Bull bars are green and bear bars are red.
r_label(high - (high - low) / 2, 'PVSRA Override Active!', label.style_none, color.orange, overridesym) //ry, rte
// CUColor = color.lime
CUColor = input.color(group='PVSRA', title='Climax Up Color', defval=color.lime, inline='pvsra') // Climax up (bu
would be weird hence up down
// alternate choice green or lime
// CUColor = input.c
CDColor = input.color(group='PVSRA', title='Climax Down Color', defval=color.red, inline='pvsra') // Climax down
// default red
NUColor = #999999
NDColor = #4d4d4d
// candleColor = iff(climax,iff(isBull,CUColor,CDColor),iff(aboveA,iff(isBull,AUColor,ADColor),iff(isBull,NUColor
iff_5 = va == 2 ? AUColor : NUColor
iff_6 = va == 1 ? CUColor : iff_5
iff_7 = va == 2 ? ADColor : NDColor
iff_8 = va == 1 ? CDColor : iff_7
candleColor = isBull ? iff_6 : iff_8
barcolor(candleColor)
alertcondition(va > 0, title='Alert on Vector Candle', message='{{ticker}} Vector Candle on the {{interval}}')
// Daily open
daily_open = request.security(syminfo.tickerid, 'D', open, lookahead=barmerge.lookahead_on)
// Date & time variables
current_year = year(timenow)
current_month = month(timenow)
current_weekofyear = weekofyear(timenow)
current_dayofmonth = dayofmonth(timenow)
current_dayofweek = dayofweek(timenow)
// Opens (re-test previous values, so we take the closing price as that is defining the upcoming open price)
// Labels
if show_label9 and barstate.isrealtime
if show_rectangle9
r_label(daily_open, 'Daily Open', label.style_none, sess9col, validTimeFrame)
//************//
// Psy Levels //
//************//
calc_psy_hilo(gmtoffsetPsy) =>
//so basically because the session is 8 hours and we are looking at a 4 hour resolution we only need to take the
//we use the gmt offset to adjust the 0000-0800 session to Sydney open which is at 2100 during dst and at 2000 ot
in_session = time('240', '0000-0800:1', gmtoffsetPsy)
new_session = in_session and not in_session[1]
float psy_high = 0.0
float psy_low = 100000000000.0
//TODO cannot plot as max plots per script exceeded : removed market sessions plots
plot(showPsy and show_psylevels and showallPsy ? psy_high : na, color=psycolH, style=plot.style_line, linewidth=1
offset=psy_plot_offset)
plot(showPsy and show_psylevels and showallPsy ? psy_low : na, color=psycolL, style=plot.style_line, linewidth=1,
offset=psy_plot_offset)
//if barstate.isnew
psy_calc_start = timestamp(psy_gmt, year, month, dayofweek.wednesday, 00, 00, 00)
psy_calc_end = timestamp(psy_gmt, year, month, dayofweek.wednesday, 08, 00, 00)
time_now_gmt = time('D', '0000-0800:1', psy_gmt)
psy_calc_inProgress = not na(time_now_gmt - psy_calc_start >= 0) and not na(time_now_gmt - psy_calc_end <= 0)
stylePsy = line.style_solid
psy_hi_label = 'Psy-Hi' //+tostring(gmtoffsetxxx)//tostring((timenow-
timestamp(syminfo.timezone,year(time,syminfo.timezone),month(time,syminfo.timezone),dayofmonth(time,syminfo.timez
me,syminfo.timezone),second(time,syminfo.timezone)))/(1000*60*60))+" "+syminfo.timezone//+str.format("{0,date,h a
timestamp(year,month,dayofmonth,hour,minute,second)) + " "+syminfo.timezone
psy_lo_label = 'Psy-Lo'
if psy_calc_inProgress
//stylePsy := line.style_dashed //this does not work for style correctly but it does for the label which is odd
psy_hi_label := 'Psy-Hi calculating...'
psy_lo_label := 'Psy-Lo calculating...' //+tostring(psy_calc_inProgress)
psy_lo_label
if showallPsy
r_label(psy_high, psy_hi_label, label.style_none, psycolH, validTimeFrame and show_psylabel)
r_label(psy_low, psy_lo_label, label.style_none, psycolL, validTimeFrame and show_psylabel)
showallPsy //just here to trick if-else into working
else
if show_psylevels
draw_linelabel_gmt_custSession(psy_high, 'D', '0000-0800:1', psy_hi_label, psycolH, stylePsy, 1, extend.none, sho
label_x_offset, 0, psy_gmt)
draw_linelabel_gmt_custSession(psy_low, 'D', '0000-0800:1', psy_lo_label, psycolL, stylePsy, 1, extend.none, show
label_x_offset, 0, psy_gmt)
showallPsy //just here to trick if-else into working
// Bollinger Bands
lengthBB = input.int(20, minval=1, group="Bollinger Bands")
srcBB = input(close, title="Source", group="Bollinger Bands")
multBB = input.float(2.0, minval=0.001, maxval=50, title="StdDev", group="Bollinger Bands")
basisBB = toggleBBon ? ta.sma(srcBB, lengthBB) : 0
devBB = toggleBBon ? multBB * ta.stdev(srcBB, lengthBB) : 0
upperBB = toggleBBon ? basisBB + devBB : 0
lowerBB = toggleBBon ? basisBB - devBB : 0
offsetBB = toggleBBon ? input.int(0, "Offset", minval = -500, maxval = 500, group="Bollinger Bands") : 0
plot(basisBB, "Basis", color=#FF6D00, offset = offsetBB)
p1 = plot(upperBB, "Upper", color=#2962FF, offset = offsetBB)
p2 = plot(lowerBB, "Lower", color=#2962FF, offset = offsetBB)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))
// Up/Down Volume Analysis
lowerTimeframeTooltip = "The indicator scans lower timeframe data to approximate Up/Down volume. By default, the
inputs override this with a custom timeframe.
\n\nHigher timeframes provide more historical data, but the data will be less precise."
useCustomTimeframeInput = input.bool(false, "Use custom timeframe", tooltip = lowerTimeframeTooltip)
lowerTimeframeInput = input.timeframe("1", "Timeframe")
upAndDownVolume() =>
posVol = 0.0
negVol = 0.0
switch
close > open => posVol += volume
close < open => negVol -= volume
close >= close[1] => posVol += volume
close < close[1] => negVol -= volume
[posVol, negVol]
lowerTimeframe = switch
useCustomTimeframeInput => lowerTimeframeInput
timeframe.isintraday => "1"
timeframe.isdaily => "5"
=> "60"
[upVolumeArray, downVolumeArray] = request.security_lower_tf(syminfo.tickerid, lowerTimeframe, upAndDownVolume())
var cumVol = 0.
cumVol += nz(volume)
if barstate.islast and cumVol == 0
runtime.error("The data vendor doesn't provide volume data for this symbol.")