예스스탁
예스스탁 답변
2021-02-16 14:12:26
안녕하세요
예스스탁입니다.
input : per(7),mult(2.618);
var : src(0),wper(0),avrng(0),smrng(0),filt(0);
var : upward(0),downward(0),hband(0),lband(0),longCond(False),shortCond(False);
var : CondIni(0),longCondition(False),shortCondition(False);
src = close;
wper = (per*2) - 1;
avrng = ema(abs(src - src[1]), per);
smrng = ema(avrng, wper)*mult;
filt = iff( src > IFf(IsNaN(filt[1]) == true,0,filt[1]),
IFf((src - smrng) < IFf(IsNaN(filt[1]) == true,0,filt[1]), IFf(IsNaN(filt[1]) == true,0,filt[1]), (src - smrng)),
IFf((src + smrng) > IFf(IsNaN(filt[1]) == true,0,filt[1]), IFf(IsNaN(filt[1]) == true,0,filt[1]), (src + smrng)));
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 = 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;
// Strategy
longCond = src > filt ;
shortCond = src < filt;
CondIni = iff(longCond , 1 , IFf(shortCond , -1 , CondIni));
longCondition = longCond and CondIni[1] == -1;
shortCondition = shortCond and CondIni[1] == 1;
if longCondition Then
buy("B");
if shortCondition Then
ExitLong("X");
즐거운 하루되세요
> 짜왕 님이 쓴 글입니다.
> 제목 : 변환부탁드립니다
> 트레이딩뷰 스크립트 변환요청드립니다
nz=
시리즈에 들어 있는 NaN 밸류를 제로 (또는 주어진 값) 로 바꿉니다.
src = input(defval=close, title="Source")
per = input(defval=7, minval=1, title="Sampling Period")
mult = input(defval=2.618, minval=0, title="Multiplier")
smoothrng(x, t, m)=>
wper = (t*2) - 1
avrng = ema(abs(x - x[1]), t)
smoothrng = ema(avrng, wper)*m
smoothrng
smrng = smoothrng(src, per, mult)
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(src, 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
// Strategy
longCond = na
shortCond = na
longCond := ((src > filt)
shortCond := ((src < filt)
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1
strategy.entry("buy",strategy.long,qty=strategy.equity/close*trade_leverage,when=longCondition)
strategy.close("buy",when=shortCondition)