예스스탁
예스스탁 답변
2025-09-12 13:27:43.0
안녕하세요
예스스탁입니다.
// 입력값
input : nATRPeriod(5);
input : nATRMultip(1.5);
vaR : alpha(0),atrValue(0),nLoss(0),xATRTrailingStop(Nan);
var : longCondition(False),shortCondition(False);
var : longSignal(False),shortSignal(False),tx(0);
// ATR 계산
alpha = 1 / nATRPeriod ;
atrValue = IFf(IsNan(atrValue[1]) == true, ma(TrueRange,nATRPeriod) , alpha * TrueRange + (1 - alpha) * IFf(isnan(atrValue[1])==true,0,atrValue[1]));
nLoss = nATRMultip * atrValue;
// Trailing Stop 변수 선언
var1 = iff(IsNan(xATRTrailingStop[1])==true, 0,xATRTrailingStop[1]);
// 로직
if (close > var1 and close[1] > var1) Then
xATRTrailingStop = max(var1, close - nLoss);
else if (close < var1 and close[1] < var1) Then
xATRTrailingStop = min(var1, close + nLoss);
else if (close > var1) Then
xATRTrailingStop = close - nLoss;
else
xATRTrailingStop = close + nLoss;
// 현재 방향
longCondition = close > xATRTrailingStop;
shortCondition = close < xATRTrailingStop;
// 시그널
longSignal = longCondition and longCondition[1] == False; // 롱 전환
shortSignal = shortCondition and shortCondition[1] == False; // 숏 전환
// 차트 표시
plot1(xATRTrailingStop[1],"ATR Trailing Stop",blue);
// 시그널 마커
if longSignal == true Then
{
tx = text_new(sDate,sTime,L,"▲");
Text_SetColor(tx,Green);
Text_SetStyle(tx,2,0);
}
if shortSignal == true Then
{
tx = text_new(sDate,sTime,H,"▼");
Text_SetColor(tx,Red);
Text_SetStyle(tx,2,1);
}
즐거운 하루되세요
> 해암 님이 쓴 글입니다.
> 제목 : 문의드립니다.
> 아래의 트레이딩뷰 수식을 변환부탁드립니다.
입력값은 수정가능하게 부탁드립니다.
항상 감사드립니다. 수고하세요!!!
===============================
//@version=5
indicator("ATR Trailing Stop Strategy (Sylvain Vervoort)", overlay = true)
// 입력값
nATRPeriod = input.int(5, "ATR Period")
nATRMultip = input.float(1.5, "ATR Multiplier")
// ATR 계산
atrValue = ta.atr(nATRPeriod)
nLoss = nATRMultip * atrValue
// Trailing Stop 변수 선언
var float xATRTrailingStop = na
// 로직
if (close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0))
xATRTrailingStop := math.max(nz(xATRTrailingStop[1]), close - nLoss)
else if (close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0))
xATRTrailingStop := math.min(nz(xATRTrailingStop[1]), close + nLoss)
else if (close > nz(xATRTrailingStop[1], 0))
xATRTrailingStop := close - nLoss
else
xATRTrailingStop := close + nLoss
// 현재 방향
longCondition = close > xATRTrailingStop
shortCondition = close < xATRTrailingStop
// 시그널
longSignal = longCondition and not longCondition[1] // 롱 전환
shortSignal = shortCondition and not shortCondition[1] // 숏 전환
// 차트 표시
plot(xATRTrailingStop[1], color=color.blue, title="ATR Trailing Stop", linewidth=2)
// 시그널 마커
plotshape(longSignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.large, text="BUY")
plotshape(shortSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.large, text="SELL")
=======================================================