답변완료
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!")
2023-11-27
1269
글번호 174335
지표
답변완료
CT를 YT로 변환 요청합니다.
1
Input: len(10), len1(70), len2(0.37), s1(2.7), method(1), delay(8)
If method=1 Then
Var1=atr(len)
Var2=atr(len1)
Elseif method=2 Then
Var20=high-low
Var1=mov(Var20,len,s)
Var2=mov(Var20,len1,s)
End If
Cond1=tdate=exitdate(1) And position(1)=1
Cond2=tdate=exitdate(1) And position(1)=-1
If Var1<var2 Then
Var10=1
Else
Var10=0
End If
If hhv(1,Var10,delay)=1 Then
If ttime<1500 Then
If Cond1=False And high<opend+(highd(1)-lowd(1))*len2 Then
Call buy("매수",Atstop,Def,opend+(highd(1)-lowd(1))*len2)
End If
IfCond2=False And low>opend-(highd(1)-lowd(1))*len2 Then
Call sell("매도",Atstop,Def,opend-(highd(1)-lowd(1))*len2)
End If
If Cond1=False And high>opend+(highd(1)-lowd(1))*len2 Then
Call buy("매수1",Atstop,Def,hhv(1,high,delay))
End If
If Cond2=False And low<opend-(highd(1)-lowd(1))*len2 Then
Callsell("매도1",Atstop,Def,llv(1,low,delay))
End If
End if
End If
If position<>0then
Call exitlong("매수청산",Atstop,hhv(1,high,barnumsinceentry+1)-atr(20)*s1)
Call exitshort("매도청산",Atstop,llv(1,low,barnumsinceentry+1)+atr(20)*s1)
End If
2
Input: len(40), len1(1), len2(30), multi(5), delay(5), s1(0.37), s2(2.7)
Var50=bbandtop(close,len,len1,s)
Var49=bbandbot(close,len,len1,s)
Var1=var50-var49
Var2=high-low
Var3=mov(Var2,len2,s)*multi
Cond1= tdate=exitdate(1) And position(1)=1
Cond2= tdate=exitdate(1) And position(1)=-1
If Var1<var3 Then
Var10=1
Else
Var10=0
End If
If hhv(1,Var10,delay)=1 then
If ttime<1500 Then
If Cond1=False And bbandmid(close,len,len1,s)>bbandmid(close,len,len1,s,1) Then
Call buy("매수",Atstop,Def,opend+(highd(1)-lowd(1))*s1)
End If
If Cond2=False And bbandmid(close,len,len1,s)<bbandmid(close,len,len1,s,1) Then
Call sell("매도",Atstop,Def,opend-(highd(1)-lowd(1))*s1)
End If
End If
End If
If position<>0 Then
Call exitlong("매수청산",Atstop,hhv(1,high,barnumsinceentry+1)-atr(20)*s2)
Call exitshort("매도청산",Atstop,llv(1,low,barnumsinceentry+1)+atr(20)*s2)
End If
3(그물망)
Input :len(20), cont(10), stepp(2), multi(2), delay(5), s1(0.37), s2(2.7)
Var50=mov(close,len,s)
Var49=mov(close,len,s)
For i = 1 To cont
If Var50<mov(close,len+stepp*i,s) Then
Var50=mov(close,len+stepp*i,s)
End If
If Var49>mov(close,len+stepp*i,s) Then
Var49=mov(close,len+stepp*i,s)
End If
Next
Var1=var50-var49
Var2=high-low
Var3=mov(Var2,len,s)*multi
Cond1= tdate=exitdate(1) And position(1)=1
Cond2= tdate=exitdate(1) And position(1)=-1
If Var1<var3 Then
Var10=1
Else
Var10=0
End If
If hhv(1,Var10,delay)=1 And hhb(1,Var10,delay)=delay-1 Then
If ttime<1500 Then
If Cond1=False Then
Call buy("매수",Atstop,Def,opend+(highd(1)-lowd(1))*s1)
End If
If Cond2=False Then
Call sell("매도",Atstop,Def,opend-(highd(1)-lowd(1))*s1)
End If
End If
End If
If position<>0 Then
Call exitlong("매수청산",Atstop,hhv(1,high,barnumsinceentry+1)-atr(20)*s2)
Call exitshort("매도청산",Atstop,llv(1,low,barnumsinceentry+1)+atr(20)*s2)
End If
4(adx)
Input: len(21), level(30), delay(2), s1(0.37), s2(2.7)
Var1=adx(len)
Cond1= tdate=exitdate(1) And position(1)=1
Cond2= tdate=exitdate(1) And position(1)=-1
If Var1<level And Var1>var1(delay) Then
If ttime<1500 Then
If Cond1=False Then
Call buy("매수",Atstop,Def,opend+(highd(1)-lowd(1))*s1)
End If
If Cond2=False Then
Call sell("매도",Atstop,Def,opend-(highd(1)-lowd(1))*s1)
End If
End If
End If
If position<>0 Then
Call exitlong("매수청산",Atstop,hhv(1,high,barnumsinceentry+1)-atr(20)*s2)
Call exitshort("매도청산",Atstop,llv(1,low,barnumsinceentry+1)+atr(20)*s2)
End If
5(ID)
Input: delay(9), s1(0.2), s2(2.7), s3(0.49)
Var1=high-low
Var2=mov(Var1,delay,s)
Cond12=False
If ttime<1500 Then
Cond12=high(1)>=high And low(1)<=low And tdate=tdate(1)
End If
If Cond12=True Then
Var10=1
Else
Var10=0
End If
Cond1= tdate=exitdate(1) And position(1)=1
Cond2= tdate=exitdate(1) And position(1)=-1
If hhv(1,Var10,delay)=1 And tdate(hhb(1,Var10,delay))= tdate Then
If ttime<1500 And Cond1=False Then
If opend+(highd(1)-lowd(1))*s1<close Then
Call buy("매수",Atstop,Def,high+var2*s3)
End If
End If
If ttime<1500 And Cond2=False Then
If opend-(highd(1)-lowd(1))*s1>close Then
Call sell("매도",Atstop,Def,low-var2*s3)
End If
End If
End If
If position<>0 Then
Call exitlong("매수청산",Atstop,hhv(1,high,barnumsinceentry+1)-atr(20)*s2)
Call exitshort("매도청산",Atstop,llv(1,low,barnumsinceentry+1)+atr(20)*s2)
End If
6(NR)
Var1=high-low
Cond11=False
Cond11= Var1=llv(1,Var1,len) And ttime<1500
Cond1= tdate=exitdate(1) And position(1)=1
Cond2= tdate=exitdate(1) And position(1)=-1
If ttime<1500 Then
If Cond1=False Then
If Cond11=True And Cond11(1)=False Then
If opend+(highd(1)-lowd(1))*s1<close Then
Call buy("매수",Atstop,Def,high+var1*s3)
End If
End If
End If
If Cond2=False Then
If Cond11=True And Cond11(1)=False Then
If opend-(highd(1)-lowd(1))*s1>close Then
Call sell("매도",Atstop,Def,low-var1*s3)
End If
End If
End If
End If
If position<>0 Then
Call exitlong("매수청산",Atstop,hhv(1,high,barnumsinceentry+1)-atr(20)*s2)
Call exitshort("매도청산",Atstop,llv(1,low,barnumsinceentry+1)+atr(20)*s2)
End If
7(++)
Input: s1(0.37), s2(2.7)
'NR2
If highd(1)-lowd(1)=min(highd(1)-lowd(1),highd(2)-lowd(2)) Then
Cond11=True
Else
Cond11=False
End If
'ID,ID2
If (highd(2)>=highd(1) And lowd(2)<=lowd(1)) _
Or (highd(3)>=highd(2) And lowd(3)<=lowd(2) And _
highd(2)>=highd(1) And lowd(2)<=lowd(1))Then
Cond12=True
Else
Cond12=False
End If
Cond1= tdate=exitdate(1) And position(1)=1
Cond2= tdate=exitdate(1) And position(1)=-1
If ttime<1500 Then
If Cond1=False Then
If Cond11=True Or Cond12=True Then
Call buy("매수",Atstop,Def,opend+(highd(1)-lowd(1))*s1)
end if
End If
If Cond2=False Then
If Cond11=True Or Cond12=True Then
Call sell("매도",Atstop,Def,opend-(highd(1)-lowd(1))*s1)
End If
End If
End If
If position<>0 Then
Call exitlong("매수청산",Atstop,hhv(1,high,barnumsinceentry+1)-atr(20)*s2)
Call exitshort("매도청산",Atstop,llv(1,low,barnumsinceentry+1)+atr(20)*s2)
End If
항상 감사드립니다.
2023-11-26
1696
글번호 174325
시스템