OPEN-SOURCE SCRIPT
Worldclassedge [Patrick nill]

plotshape(long, title="BUY", text="Long▲", style=shape.labelup, textcolor=color.white, size=size.auto, location=location.belowbar, color=color.green)
plotshape(short, title="SELL", text="Short▼", style=shape.labeldown, textcolor=color.white, size=size.auto, location=location.abovebar, color=color.red)
alertcondition(long, title="BUY", message="Long▲")
alertcondition(short, title="SELL", message="Short▼")
// VWAP
anchor = input.string("Session", title="Anchor Period")
MILLIS_IN_DAY = 86400000
dwmBarTime = timeframe.isdwm ? time : request.security(syminfo.tickerid, "D", time)
dwmBarTime := na(dwmBarTime) ? nz(dwmBarTime[1]) : dwmBarTime
var periodStart = time - time
makeMondayZero(dayOfWeek) => (dayOfWeek + 5) % 7
isMidnight(t) => hour(t) == 0 and minute(t) == 0
isSameDay(t1, t2) => dayofmonth(t1) == dayofmonth(t2) and month(t1) == month(t2) and year(t1) == year(t2)
isOvernight() => not (isMidnight(dwmBarTime) or request.security(syminfo.tickerid, "D", isSameDay(time, time_close), lookahead=barmerge.lookahead_on))
tradingDayStart(t) => timestamp(year(t), month(t), dayofmonth(t), 0, 0)
numDaysBetween(t1, t2) =>
diff = math.abs(tradingDayStart(t1) - tradingDayStart(t2))
diff / MILLIS_IN_DAY
tradingDay = isOvernight() ? tradingDayStart(dwmBarTime + MILLIS_IN_DAY) : tradingDayStart(dwmBarTime)
isNewPeriod() =>
var isNew = false
if tradingDay != nz(tradingDay[1])
isNew := switch anchor
"Session" => na(tradingDay[1]) or tradingDay > tradingDay[1]
"Week" => makeMondayZero(dayofweek(periodStart)) + numDaysBetween(periodStart, tradingDay) >= 7
"Month" => month(periodStart) != month(tradingDay) or year(periodStart) != year(tradingDay)
"Year" => year(periodStart) != year(tradingDay)
=> false
isNew
srcVWAP = hlc3
var float sumSrc = 0
var float sumVol = 0
if isNewPeriod()
periodStart := tradingDay
sumSrc := 0
sumVol := 0
if not na(srcVWAP) and not na(volume)
sumSrc += srcVWAP * volume
sumVol += volume
vwapValue = sumSrc / sumVol
plot(vwapValue, title="VWAP", color=color.red, linewidth=3)
// =
enableCloud = input.bool(false, "Enable Cloud")
lenn = input.int(20, "Period")
mult = input.float(2.5, "StdDev Multiplier")
tc = input.int(25, "Gauge Size", minval=3)
upColor = input.color(#00ffbb, "Up Color")
downColor = input.color(#ff1100, "Down Color")
basis = ta.sma(close, lenn)
upper1 = basis + ta.stdev(close, lenn) * mult
lower1 = basis - ta.stdev(close, lenn) * mult
// TP
var int position = 0
if long
position := 1
else if short
position := -1
plotshape(short, title="SELL", text="Short▼", style=shape.labeldown, textcolor=color.white, size=size.auto, location=location.abovebar, color=color.red)
alertcondition(long, title="BUY", message="Long▲")
alertcondition(short, title="SELL", message="Short▼")
// VWAP
anchor = input.string("Session", title="Anchor Period")
MILLIS_IN_DAY = 86400000
dwmBarTime = timeframe.isdwm ? time : request.security(syminfo.tickerid, "D", time)
dwmBarTime := na(dwmBarTime) ? nz(dwmBarTime[1]) : dwmBarTime
var periodStart = time - time
makeMondayZero(dayOfWeek) => (dayOfWeek + 5) % 7
isMidnight(t) => hour(t) == 0 and minute(t) == 0
isSameDay(t1, t2) => dayofmonth(t1) == dayofmonth(t2) and month(t1) == month(t2) and year(t1) == year(t2)
isOvernight() => not (isMidnight(dwmBarTime) or request.security(syminfo.tickerid, "D", isSameDay(time, time_close), lookahead=barmerge.lookahead_on))
tradingDayStart(t) => timestamp(year(t), month(t), dayofmonth(t), 0, 0)
numDaysBetween(t1, t2) =>
diff = math.abs(tradingDayStart(t1) - tradingDayStart(t2))
diff / MILLIS_IN_DAY
tradingDay = isOvernight() ? tradingDayStart(dwmBarTime + MILLIS_IN_DAY) : tradingDayStart(dwmBarTime)
isNewPeriod() =>
var isNew = false
if tradingDay != nz(tradingDay[1])
isNew := switch anchor
"Session" => na(tradingDay[1]) or tradingDay > tradingDay[1]
"Week" => makeMondayZero(dayofweek(periodStart)) + numDaysBetween(periodStart, tradingDay) >= 7
"Month" => month(periodStart) != month(tradingDay) or year(periodStart) != year(tradingDay)
"Year" => year(periodStart) != year(tradingDay)
=> false
isNew
srcVWAP = hlc3
var float sumSrc = 0
var float sumVol = 0
if isNewPeriod()
periodStart := tradingDay
sumSrc := 0
sumVol := 0
if not na(srcVWAP) and not na(volume)
sumSrc += srcVWAP * volume
sumVol += volume
vwapValue = sumSrc / sumVol
plot(vwapValue, title="VWAP", color=color.red, linewidth=3)
// =
enableCloud = input.bool(false, "Enable Cloud")
lenn = input.int(20, "Period")
mult = input.float(2.5, "StdDev Multiplier")
tc = input.int(25, "Gauge Size", minval=3)
upColor = input.color(#00ffbb, "Up Color")
downColor = input.color(#ff1100, "Down Color")
basis = ta.sma(close, lenn)
upper1 = basis + ta.stdev(close, lenn) * mult
lower1 = basis - ta.stdev(close, lenn) * mult
// TP
var int position = 0
if long
position := 1
else if short
position := -1
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.