예스스탁
예스스탁 답변
2023-11-27 10:35:58
안녕하세요
예스스탁입니다.
input : per1(27);
input : mult1(1.6);
input : per2(55);
input : mult2(2);
var : source(0);
var : wper1(0),avrng1(0),smrng1(0);
var : wper2(0),avrng2(0),smrng2(0);
var : smrng(0),filt(0),hband(0),lband(0);
var : longCond(False),shortCond(False),CondIni(0);
var : long(False),short(False);
source = close;
wper1 = per1 * 2 - 1;
avrng1 = ema(abs(source - source[1]), per1);
smrng1 = ema(avrng1, wper1) * mult1;
wper2 = per2 * 2 - 1;
avrng2 = ema(abs(source - source[1]), per2);
smrng2 = ema(avrng1, wper2) * mult2;
smrng = (smrng1 + smrng2) / 2;
// Range Filter
filt = source;
filt = iff(source > iff(IsNan(filt[1])==true,0,filt[1]),
iff(source - smrng < iff(IsNan(filt[1])==true,0,filt[1]), iff(IsNan(filt[1])==true,0,filt[1]), source - smrng),
iff(source + smrng > iff(IsNan(filt[1])==true,0,filt[1]) , iff(IsNan(filt[1])==true,0,filt[1]) , source + smrng));
var : upward(0),downward(0);
upward = 0.0;
upward = iff(filt > filt[1] , iff(IsNan(upward[1])==true,0,upward[1]) + 1 ,Iff(filt < filt[1] , 0 , iff(IsNan(upward[1])==true,0,upward[1])));
downward = 0.0;
downward = iff(filt < filt[1] , iff(IsNan(downward[1])==true,0,downward[1]) + 1 ,IFf(filt > filt[1] , 0 , iff(IsNan(downward[1])==true,0,downward[1])));
hband = filt + smrng;
lband = filt - smrng;
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 = iff(longCond , 1 , IFf(shortCond , -1 , CondIni[1]));
long = longCond and CondIni[1] == -1;
short = shortCond and CondIni[1] == 1;
if long == true Then
Buy("long");
if short == true Then
Sell("short");
즐거운 하루되세요
> 신대륙발견 님이 쓴 글입니다.
> 제목 : 문의 드립니다.
> study(title="Twin Range Filter", overlay=true)
source = input(defval=close, title="Source")
// Smooth Average Range
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
// Range Filter
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
// Plotting
plotshape(long, title="Long", text="Long", style=shape.labelup, textcolor=color.black, size=size.tiny, location=location.belowbar, color=color.lime, transp=0)
plotshape(short, title="Short", text="Short", style=shape.labeldown, textcolor=color.white, size=size.tiny, location=location.abovebar, color=color.red, transp=0)
// Alerts
alertcondition(long, title="Long", message="Long")
alertcondition(short, title="Short", message="Short")
트레이딩뷰 수식인데
예스 시스템식으로 부탁드려요.