커뮤니티

Super trend 수식 문의 드립니다.

프로필 이미지
비정성시
2023-11-27 10:06:49
1204
글번호 174335
답변완료
항상 많은 도움 감사드립니다. 많은 수의 트레이더들이 사용하는 supertrend는 버전이 상당히 많은데요. 이 버전은 아직 Q&A에 올라와 있는것을 찾지 못해 수식 변경 문의 드립니다. study("Supertrend", overlay = true, format=format.price, precision=2, resolution="") Periods = input(title="ATR Period", type=input.integer, defval=10) src = input(hl2, title="Source") Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0) changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true) showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true) highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true) atr2 = sma(tr, Periods) atr= changeATR ? atr(Periods) : atr2 up=src-(Multiplier*atr) up1 = nz(up[1],up) up := close[1] > up1 ? max(up,up1) : up dn=src+(Multiplier*atr) dn1 = nz(dn[1], dn) dn := close[1] < dn1 ? min(dn, dn1) : dn trend = 1 trend := nz(trend[1], trend) trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green) buySignal = trend == 1 and trend[1] == -1 plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0) plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0) dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red) sellSignal = trend == -1 and trend[1] == 1 plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0) plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0) mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0) longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor) fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor) alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!") alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!") changeCond = trend != trend[1] alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2023-11-28 13:49:33

안녕하세요 예스스탁입니다. input : Periods(10); input : Multiplier(3.0); input : changeATR(true); input : showsignals(true); input : highlighting(true); var : src(0),alpha(0),atr1(0),atr2(0),atrv(0); var : up(0),up1(0),dn(0),dn1(0); var : trend(0),tx(0); src = (h+l)/2; alpha = 1/Periods; atr1 = iff(IsNan(atr1[1]) == true,ma(TrueRange, Periods), alpha * TrueRange + (1 - alpha) * iff(IsNan(atr1[1])==true,0,atr1[1])); atr2 = ma(TrueRange, Periods); atrv = iff(changeATR ==true,atr1, atr2); up = src-(Multiplier*atrv); up1 = iff(isnan(up[1])==true,up,up[1]); up = iff(close[1] > up1 , max(up,up1), up); dn = src+(Multiplier*atrv); dn1 = iff(isnan(dn[1])==true,dn,dn[1]); dn = iff(close[1] < dn1 , min(dn, dn1) , dn); trend = 1; trend = iff(isnan(trend[1])==true,trend,trend[1]); trend = iff(trend == -1 and close > dn1 , 1 , iff(trend == 1 and close < up1 , -1 , trend)); if trend == 1 Then { plot1(up,"Up Trend",green); NoPlot(2); } Else { NoPlot(1); plot2(dn,"Down Trend",Red); } if trend == 1 and trend[1] == -1 Then { tx = Text_New(sDate,sTime,up,"●"); Text_SetColor(tx,Green); Text_SetStyle(tx,2,2); } if trend == -1 and trend[1] == 1 Then { tx = Text_New(sDate,sTime,dn,"●"); Text_SetColor(tx,Red); Text_SetStyle(tx,2,2); } 즐거운 하루되세요 > 비정성시 님이 쓴 글입니다. > 제목 : Super trend 수식 문의 드립니다. > 항상 많은 도움 감사드립니다. 많은 수의 트레이더들이 사용하는 supertrend는 버전이 상당히 많은데요. 이 버전은 아직 Q&A에 올라와 있는것을 찾지 못해 수식 변경 문의 드립니다. study("Supertrend", overlay = true, format=format.price, precision=2, resolution="") Periods = input(title="ATR Period", type=input.integer, defval=10) src = input(hl2, title="Source") Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0) changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true) showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true) highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true) atr2 = sma(tr, Periods) atr= changeATR ? atr(Periods) : atr2 up=src-(Multiplier*atr) up1 = nz(up[1],up) up := close[1] > up1 ? max(up,up1) : up dn=src+(Multiplier*atr) dn1 = nz(dn[1], dn) dn := close[1] < dn1 ? min(dn, dn1) : dn trend = 1 trend := nz(trend[1], trend) trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green) buySignal = trend == 1 and trend[1] == -1 plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0) plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0) dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red) sellSignal = trend == -1 and trend[1] == 1 plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0) plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0) mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0) longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor) fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor) alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!") alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!") changeCond = trend != trend[1] alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")