OPEN-SOURCE SCRIPT

Worldclassedge [Patrick nill]

479
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

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.