Professional Documents
Culture Documents
0 at
https://mozilla.org/MPL/2.0/
// © Vikas
//@version=4
//www.stockfinz.com
quickEMA = ema(close, 9)
plot(series=quickEMA, color=color.green, linewidth=2)
per1 = input(defval=27, minval=1, title="Fast period")
mult1 = input(defval=1.6, minval=0.1, title="Fast range")
per2 = input(defval=55, minval=1, title="Slow period")
mult2 = input(defval=2, minval=0.1, title="Slow range")
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ema(abs(x - x[1]), t)
smoothrng = ema(avrng, wper) * m
smoothrng
smrng1 = smoothrng(source, per1, mult1)
smrng2 = smoothrng(source, per2, mult2)
smrng = (smrng1 + smrng2) / 2
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x -
r :
x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
rngfilt
filt = rngfilt(source, smrng)
upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 :
nz(downward[1])
hband = filt + smrng
lband = filt - smrng
longCond = bool(na)
shortCond = bool(na)
longCond := source > filt and source > source[1] and upward > 0 or source > filt
and source < source[1] and upward > 0
shortCond := source < filt and source < source[1] and downward > 0 or source <
filt and source > source[1] and downward > 0
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
long = longCond and CondIni[1] == -1
short = shortCond and CondIni[1] == 1
plotshape(long, title="BUY", text="BUY", style=shape.labelup,
textcolor=color.white, size=size.auto, location=location.belowbar,
color=color.green, transp=0)
plotshape(short, title="SELL", text="SELL", style=shape.labeldown,
textcolor=color.white, size=size.auto, location=location.abovebar,
color=color.red, transp=0)
alertcondition(long, title="BUY", message="BUY")
alertcondition(short, title="SELL", message="SELL")
anchor = input(defval = "Session", title="Anchor Period", type=input.string)
MILLIS_IN_DAY = 86400000
dwmBarTime = timeframe.isdwm ? time : time("D")
if na(dwmBarTime)
dwmBarTime := nz(dwmBarTime[1])
var periodStart = time - time // zero
isMidnight(t) =>
hour(t) == 0 and minute(t) == 0
isOvernight() =>
not (isMidnight(dwmBarTime) or security(syminfo.tickerid, "D", isSameDay(time,
time_close), lookahead=true))
tradingDayStart(t) =>
y = year(t)
m = month(t)
d = dayofmonth(t)
timestamp(y, m, d, 0, 0)
y2 = year(time2)
m2 = month(time2)
d2 = dayofmonth(time2)
isNewPeriod() =>
isNew = false
if tradingDay != nz(tradingDay[1])
if anchor == "Session"
isNew := na(tradingDay[1]) or tradingDay > tradingDay[1]
if anchor == "Week"
DAYS_IN_WEEK = 7
isNew := makeMondayZero(dayofweek(periodStart)) +
numDaysBetween(periodStart, tradingDay) >= DAYS_IN_WEEK
if anchor == "Month"
isNew := month(periodStart) != month(tradingDay) or
year(periodStart) != year(tradingDay)
if anchor == "Year"
isNew := year(periodStart) != year(tradingDay)
isNew
src = hlc3
sumSrc = float(na)
sumVol = float(na)
sumSrc := nz(sumSrc[1], 0)
sumVol := nz(sumVol[1], 0)
if isNewPeriod()
periodStart := tradingDay
sumSrc := 0.0
sumVol := 0.0
//EOS