예스스탁
예스스탁 답변
2025-07-02 15:28:02
안녕하세요
예스스탁입니다.
input : atr_factor(5.0);
var : src(0),d(0),n(0);
var : xClose(0),xOpen(0),xHigh(0),xLow(0);
#Heiken Ashi 시고저종
if index == 0 then
{
xClose = (O+H+L+C)/4;
xOpen = open;
xHigh = MaxList( high, xOpen, xClose);
xLow = MinList( low, xOpen,xClose);
}
else
{
xClose = (O+H+L+C)/4;
xOpen = (xOpen [1] + xClose [1])/2 ;
xHigh = MaxList(High, xOpen, xClose) ;
xLow = MinList(Low, xOpen, xClose) ;
}
// For standard deviation
d = 20;
n = 20;
src = xClose;
// Volatility function
var : x(0),y(0),z(0),vol(0);
var : uptrend(true),mx(xClose),mn(xClose),stop(0),TF(False);
var : len(0),sum(0),tr(0),atr(0),atrM(0),value(0);
x = exp(std(log(xClose / xClose[1]), n) * d);
y = src * pow(x, 2);
z = src / pow(x, 2);
vol = (xClose - lowest(z,n)) / (highest(y,n)-lowest(z,n))*100;
len = max(1, min(2000, abs(int(106 * (iff(isnan(vol) == true , 1 , vol / 100))))));
atr = 0;
tr = max(xhigh - xlow, abs(xhigh - xclose[1]), abs(xlow - xclose[1]));
atr = (tr + (len - 1) * iff(IsNan(atr[1])==true,0,atr[1])) / len;
atrM = wma(atr, len) * atr_factor - std(atr, len);
mx = max(mx, src);
mn = min(mn, src);
value = iff(uptrend , max(stop, mx - atrM) , min(stop, mn + atrM));
stop = iff(IsNan(value) == true, src,value);
uptrend = src - stop >= 0.0;
if uptrend != uptrend[1] Then
{
mx = src;
mn = src;
stop = iff(uptrend , mx - atrM , mn + atrM);
}
var : down(False),up(False),tx(0);
// Conditions
down = uptrend != uptrend[1] and uptrend == False;
up = uptrend != uptrend[1] and uptrend == true;
// Drawings
if down == true Then
{
tx = text_new(sDate,stime,stop,"■");
Text_SetStyle(tx,2,2);
Text_SetColor(tx,Red);
}
if up == true Then
{
tx = text_new(sDate,stime,stop,"■");
Text_SetStyle(tx,2,2);
Text_SetColor(tx,Green);
}
plot1(stop, "Volatility Calibrated ATR",iff(uptrend , green , Red));
즐거운 하루되세요
> 해암 님이 쓴 글입니다.
> 제목 : 문의드립니다.
> 아래의 트레이딩뷰 수식을 변경 부탁드립니다.
===================
indicator(shorttitle="[-_-] VCATR", title="[-_-] Volatility Calibrated ATR", overlay=true)
src = input.source(close, "Source")
atr_factor = input.float(5.0, "ATR Factor", minval=0.25, step=0.25)
// For standard deviation
d = 20
n = 20
// Volatility function
vol_f() =>
x = math.exp(ta.stdev(math.log(close / close[1]), n) * d)
y = src * math.pow(x, 2)
z = src / math.pow(x, 2)
ta.stoch(close, y, z, n)
// ATR
atr_f(length) =>
sum = 0.0
tr = math.max(high - low, math.abs(high - close[1]), math.abs(low - close[1]))
sum := (tr + (length - 1) * nz(sum[1])) / length
sum
// Calibrator function
main_f(source, atr_factor) =>
var bool uptrend = true
var float max = src
var float min = src
var float stop = 0.0
vol = vol_f()
len = math.max(1, math.min(2000, math.abs(int(106 * (na(vol) ? 1 : vol / 100)))))
atr = atr_f(len)
atrM = ta.wma(atr, len) * atr_factor - ta.stdev(atr, len)
max := math.max(max, src)
min := math.min(min, src)
stop := nz(uptrend ? math.max(stop, max - atrM) : math.min(stop, min + atrM), src)
uptrend := src - stop >= 0.0
if uptrend != nz(uptrend[1], true)
max := src
min := src
stop := uptrend ? max - atrM : min + atrM
[stop, uptrend]
// Request Heikin Ashi data
[stop, uptrend] = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, main_f(src, atr_factor))
// Conditions
down = uptrend != uptrend[1] and not uptrend
up = uptrend != uptrend[1] and uptrend
// Drawings
plotshape(down, style=shape.square, color=color.red, size=size.tiny, title="Downtrend begins")
plotshape(up, style=shape.square, color=color.green, size=size.tiny, location=location.belowbar, title="Uptrend begins")
plot(stop, color=uptrend ? color.new(color.green, 50) : color.new(color.red, 50), linewidth=2, title="Volatility Calibrated ATR")
====================
항상 감사드립니다. 수고하세요!!!