커뮤니티

문의드립니다.

프로필 이미지
해암
2025-05-09 12:03:12
350
글번호 190682
답변완료
이전 문의드린 수식중 아래의 수식을 적용했더니 선의 색상이 파란색으로만 나오고 green과 red는 구현되지 않습니다. 또한 선이 직선처럼 나와야 하는데 휩소처럼 나옵니다. 다시한번부탁드립니다. ========================== study(title="Average True Range Trailing Stops Strategy, by Sylvain Vervoort", overlay = true) nATRPeriod = input(5) nATRMultip = input(3.5) xATR = atr(nATRPeriod) nLoss = nATRMultip * xATR xATRTrailingStop = iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss), iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss), iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss))) pos = iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1, iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) color = pos == -1 ? red: pos == 1 ? green : blue plot(xATRTrailingStop, color=color, title="ATR Trailing Stop") =============================================== 작성해주신 수식 input : nATRPeriod(5); input : nATRMultip(3.5); var : xATR(0),nLoss(0),xATRTrailingStop(0),ps(0),nz(0),color(0); xATR = atr(nATRPeriod); nLoss = nATRMultip * xATR; nz = iff(xATRTrailingStop[1] == true,0,xATRTrailingStop[1]); xATRTrailingStop = iff(close > nz and close[1] > nz, max(nz, close - nLoss), iff(close < nz and close[1] < nz, min(nz, close + nLoss), iff(close > nz, close - nLoss, close + nLoss))); ps = iff(close[1] < nz and close > nz, 1, iff(close[1] > nz and close < nz, -1, iff(isnan(ps[1]) ==true, 0,ps[1]))) ; color = iff(ps == -1 , red, iff(ps == 1 , green , blue)); plot1(xATRTrailingStop, "ATR Trailing Stop",color); ================== 항상 감사드립니다. 수고하세요!!!
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-05-09 17:46:51

안녕하세요 예스스탁입니다. input : nATRPeriod(5); input : nATRMultip(3.5); var : alpha(0),xATR(0),nLoss(0),xATRTrailingStop(0),ps(0),nz(0),color(0); alpha = 1 / nATRPeriod ; xATR = IFf(IsNan(xATR[1]) == true, ma(TrueRange,nATRPeriod) , alpha * TrueRange + (1 - alpha) * IFf(isnan(xATR[1])==true,0,xATR[1])); nLoss = nATRMultip * xATR; var1 = IFF(IsNan(xATRTrailingStop[1]) == true,0,xATRTrailingStop[1]); xATRTrailingStop = iff(close > var1 and close[1] > var1, max(var1, close - nLoss), iff(close < var1 and close[1] < var1, min(var1, close + nLoss), iff(close > var1, close - nLoss, close + nLoss))); ps = iff(close[1] < var1 and close > var1, 1, iff(close[1] > var1 and close < var1, -1, IFf(IsNaN(ps[1])==true,0,ps[1]))); color = iff(ps == -1 , red ,IFf(ps == 1 , green , blue)); plot1(xATRTrailingStop, "ATR Trailing Stop",color); 즐거운 하루되세요 > 해암 님이 쓴 글입니다. > 제목 : 문의드립니다. > 이전 문의드린 수식중 아래의 수식을 적용했더니 선의 색상이 파란색으로만 나오고 green과 red는 구현되지 않습니다. 또한 선이 직선처럼 나와야 하는데 휩소처럼 나옵니다. 다시한번부탁드립니다. ========================== study(title="Average True Range Trailing Stops Strategy, by Sylvain Vervoort", overlay = true) nATRPeriod = input(5) nATRMultip = input(3.5) xATR = atr(nATRPeriod) nLoss = nATRMultip * xATR xATRTrailingStop = iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss), iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss), iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss))) pos = iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1, iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) color = pos == -1 ? red: pos == 1 ? green : blue plot(xATRTrailingStop, color=color, title="ATR Trailing Stop") =============================================== 작성해주신 수식 input : nATRPeriod(5); input : nATRMultip(3.5); var : xATR(0),nLoss(0),xATRTrailingStop(0),ps(0),nz(0),color(0); xATR = atr(nATRPeriod); nLoss = nATRMultip * xATR; nz = iff(xATRTrailingStop[1] == true,0,xATRTrailingStop[1]); xATRTrailingStop = iff(close > nz and close[1] > nz, max(nz, close - nLoss), iff(close < nz and close[1] < nz, min(nz, close + nLoss), iff(close > nz, close - nLoss, close + nLoss))); ps = iff(close[1] < nz and close > nz, 1, iff(close[1] > nz and close < nz, -1, iff(isnan(ps[1]) ==true, 0,ps[1]))) ; color = iff(ps == -1 , red, iff(ps == 1 , green , blue)); plot1(xATRTrailingStop, "ATR Trailing Stop",color); ================== 항상 감사드립니다. 수고하세요!!!