답변완료
수식 부탁드립니다
지표식 부탁드립니다.
study("Optimized Trend Tracker Bands","OTT Bands", overlay=true,format=format.price, precision=2, resolution="")
src = input(close, title="Source")
length=input(2, "OTT Moving Average Length", minval=1)
percent=input(15, "OTT Optimization Coeff", type=input.float, step=0.1, minval=0)
X3=input(0.2, "OTT UPPER BAND Optimization Coeff", type=input.float, step=0.001, minval=0)
X5=input(0.177, "OTT LOWER BAND Optimization Coeff", type=input.float, step=0.001, minval=0)
showfibolines = input(title="Show OTT Bands Fibonacci Levels?", type=input.bool, defval=false)
showsupport = input(title="Show Support Line?", type=input.bool, defval=false)
highlight = input(title="Show OTT Support Line Color Changes?", type=input.bool, defval=false)
mav = input(title="Moving Average Type", defval="VAR", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])
Var_Func(src,length)=>
valpha=2/(length+1)
vud1=src>src[1] ? src-src[1] : 0
vdd1=src<src[1] ? src[1]-src : 0
vUD=sum(vud1,9)
vDD=sum(vdd1,9)
vCMO=nz((vUD-vDD)/(vUD+vDD))
VAR=0.0
VAR:=nz(valpha*abs(vCMO)*src)+(1-valpha*abs(vCMO))*nz(VAR[1])
VAR=Var_Func(src,length)
Wwma_Func(src,length)=>
wwalpha = 1/ length
WWMA = 0.0
WWMA := wwalpha*src + (1-wwalpha)*nz(WWMA[1])
WWMA=Wwma_Func(src,length)
Zlema_Func(src,length)=>
zxLag = length/2==round(length/2) ? length/2 : (length - 1) / 2
zxEMAData = (src + (src - src[zxLag]))
ZLEMA = ema(zxEMAData, length)
ZLEMA=Zlema_Func(src,length)
Tsf_Func(src,length)=>
lrc = linreg(src, length, 0)
lrc1 = linreg(src,length,1)
lrs = (lrc-lrc1)
TSF = linreg(src, length, 0)+lrs
TSF=Tsf_Func(src,length)
getMA(src, length) =>
ma = 0.0
if mav == "SMA"
ma := sma(src, length)
ma
if mav == "EMA"
ma := ema(src, length)
ma
if mav == "WMA"
ma := wma(src, length)
ma
if mav == "TMA"
ma := sma(sma(src, ceil(length / 2)), floor(length / 2) + 1)
ma
if mav == "VAR"
ma := VAR
ma
if mav == "WWMA"
ma := WWMA
ma
if mav == "ZLEMA"
ma := ZLEMA
ma
if mav == "TSF"
ma := TSF
ma
ma
MAvg=getMA(src, length)
fark=MAvg*percent*0.01
longStop = MAvg - fark
longStopPrev = nz(longStop[1], longStop)
longStop := MAvg > longStopPrev ? max(longStop, longStopPrev) : longStop
shortStop = MAvg + fark
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := MAvg < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dir
MT = dir==1 ? longStop: shortStop
OTT=MAvg>MT ? MT*(200+percent)/200 : MT*(200-percent)/200
OTTC = highlight ? MAvg > MAvg[1] ? color.green : color.red : #0585E1
OTTMAIN=plot(nz(OTT[2]), color= #B800D9, linewidth=2, title="OTT", transp=0)
plot(showsupport ? MAvg : na, color=OTTC, linewidth=2, title="Support Line")
OTTUST=plot(nz(OTT[2])*(1+X3), color=#4500C4, linewidth=2, title="OTT UPPER", transp=0)
OTTUSTYARI=plot(showfibolines ? nz(OTT[2])*(1+X3*0.618) : nz(OTT[2])*(1+X3/2), color=#8400FF, linewidth=1, title="OTT UPPER HALF ", transp=0)
OTTFIBOUST2=plot(showfibolines ? nz(OTT[2])*(1+X3*0.382) : na, color=#C830FF, linewidth=1, title="OTT UPPER HALF ", transp=0)
OTTALT=plot(nz(OTT[2])*(1-X5), color=#00A6FF, linewidth=2, title="OTT LOWER", transp=0)
OTTALTYARI=plot(showfibolines ? nz(OTT[2])*(1-X5*0.618) : nz(OTT[2])*(1-X5/2), color=#007BBD, linewidth=1, title="OTT LOWER HALF", transp=0)
OTTALTFIBO2=plot(showfibolines ? nz(OTT[2])*(1-X5*0.382) : na, color=#024DE3, linewidth=1, title="OTT LOWER HALF", transp=0)
fill(OTTUST, OTTUSTYARI, color=#4500C4, transp=88)
fill(OTTFIBOUST2, OTTUSTYARI , color=#8400FF, transp=88)
fill(OTTUSTYARI, OTTMAIN, color=#C810FF, transp=88)
fill(OTTFIBOUST2, OTTMAIN, color=#C810FF, transp=88)
fill(OTTALT, OTTALTYARI, color=#00A6FF, transp=88)
fill(OTTALTFIBO2, OTTALTYARI , color=#007BBD, transp=88)
fill(OTTALTYARI, OTTMAIN, color=#024DE3, transp=88)
fill(OTTALTFIBO2, OTTMAIN, color=#024DE3, transp=88)
alertcondition(cross(MAvg, OTT[2]), title="Cross Alert", message="OTT - Support Line Crossing!")
alertcondition(crossover(MAvg, OTT[2]), title="Crossover Alarm", message="Support Line BUY SIGNAL!")
alertcondition(crossunder(MAvg, OTT[2]), title="Crossunder Alarm", message="Support Line SELL SIGNAL!")
alertcondition(cross(src, OTT[2]), title="Price Cross Alert", message="OTT - Price Crossing!")
alertcondition(crossover(src, OTT[2]), title="Price Crossover Alarm", message="PRICE OVER OTT - BUY SIGNAL!")
alertcondition(crossunder(src, OTT[2]), title="Price Crossunder Alarm", message="PRICE UNDER OTT - SELL SIGNAL!")
2024-09-27
939
글번호 183802
지표
답변완료
수정부탁드립니다.
변곡점에서 텍스트 표시부탁드립니다.
var:length(150);
Var : uTL1(0),uTL2(0),TL2_exist(0),color(0),uT(0),
종가사용여부(1), // 종가로 계산하려면 1로 설정한다.
TL_NewBit(0), // 1:NewLine 2:SetEndLine
slope(0),mid_idx(0),mid_val(0);
var : TL11(0),TL12(0),TL13(0),TL14(0);
Array:고[10,4](0),저[10,4](0); // 1:가격,2:Index,3:sDate,4:sTime
#==========================================#
Value1 = HiLoLineZigZag(length,종가사용여부,고,저,TL_NewBit);
// HiLoLineZigZag는 사용자함수입니다. 링크에서 내려받으세요..
If Value1 == 1 Then { // 고점
uT = 1;
If TL_NewBit == 1 Then { // 신규
If 고[2,1] < 고[1,1] Then { // 신규 고점이 이전 고점을 상향 돌파
// y = 기울기 * x + 절편
// x = (y - 절편) / 기울기
// y = 고[2,1]
// 절편 = 저[1,1]
slope = (고[1,1] - 저[1,1]) / (고[1,2] - 저[1,2]); // 추세선의 기울기
mid_idx = Floor((고[2,1] - 저[1,1]) / slope); // 고[2,1]과 만나는 지점
mid_val = slope * mid_idx + 저[1,1];
Var1 = Index - (저[1,2] + mid_idx); // 추세선의 중간지점 x좌표
uTL1 = TL_New(저[1,3],저[1,4],저[1,1],sDate[Var1],sTime[Var1],mid_val);
uTL2 = TL_New(sDate[Var1],sTime[Var1],mid_val,고[1,3],고[1,4],고[1,1]);
Var2 = Index - 저[1,2]; // 이전 색깔을 따라감
TL_SetColor(uTL1,color[Var2]);
color = RED; // 상향 돌파했으므로 빨간색으로 전환
TL_SetColor(uTL2,color);
TL2_exist = 1; // 추세선 2개를 연결해서 그린 것이므로 추세선이 2개임을 저장
} Else {
uTL1 = TL_New(저[1,3],저[1,4],저[1,1],고[1,3],고[1,4],고[1,1]);
TL_SetColor(uTL1,color);
TL2_exist = 0;
}
}
If TL_NewBit == 2 Then { // 연장
TL_Delete(uTL1);
If TL2_exist == 1 Then TL_Delete(uTL2); // 추세선이 2개면 두번째 추세선도 삭제
If 고[2,1] < 고[1,1] Then {
slope = (고[1,1] - 저[1,1]) / (고[1,2] - 저[1,2]);
mid_idx = Floor((고[2,1] - 저[1,1]) / slope);
mid_val = slope * mid_idx + 저[1,1];
Var1 = Index - (저[1,2] + mid_idx);
uTL1 = TL_New(저[1,3],저[1,4],저[1,1],sDate[Var1],sTime[Var1],mid_val);
uTL2 = TL_New(sDate[Var1],sTime[Var1],mid_val,고[1,3],고[1,4],고[1,1]);
Var2 = Index - 저[1,2];
TL_SetColor(uTL1,color[Var2]);
color = RED;
TL_SetColor(uTL2,color);
TL2_exist = 1;
} Else {
uTL1 = TL_New(저[1,3],저[1,4],저[1,1],고[1,3],고[1,4],고[1,1]);
TL_SetColor(uTL1,color);
TL2_exist = 0;
}
}
} Else If Value1 == -1 Then { // 저점
uT = -1;
If TL_NewBit == 1 Then { // 신규
If 저[2,1] > 저[1,1] Then {
slope = (저[1,1] - 고[1,1]) / (저[1,2] - 고[1,2]);
mid_idx = Floor((저[2,1] - 고[1,1]) / slope);
mid_val = slope * mid_idx + 고[1,1];
Var1 = Index - (고[1,2] + mid_idx);
uTL1 = TL_New(고[1,3],고[1,4],고[1,1],sDate[Var1],sTime[Var1],mid_val);
uTL2 = TL_New(sDate[Var1],sTime[Var1],mid_val,저[1,3],저[1,4],저[1,1]);
Var2 = Index - 고[1,2];
TL_SetColor(uTL1,color[Var2]);
color = BLUE;
TL_SetColor(uTL2,color);
TL2_exist = 1;
} Else {
uTL1 = TL_New(고[1,3],고[1,4],고[1,1],저[1,3],저[1,4],저[1,1]);
TL_SetColor(uTL1,color);
TL2_exist = 0;
}
}
If TL_NewBit == 2 Then { // 연장
TL_Delete(uTL1);
If TL2_exist == 1 Then TL_Delete(uTL2);
If 저[2,1] > 저[1,1] Then {
slope = (저[1,1] - 고[1,1]) / (저[1,2] - 고[1,2]);
mid_idx = Floor((저[2,1] - 고[1,1]) / slope);
mid_val = slope * mid_idx + 고[1,1];
Var1 = Index - (고[1,2] + mid_idx);
uTL1 = TL_New(고[1,3],고[1,4],고[1,1],sDate[Var1],sTime[Var1],mid_val);
uTL2 = TL_New(sDate[Var1],sTime[Var1],mid_val,저[1,3],저[1,4],저[1,1]);
Var2 = Index - 고[1,2];
TL_SetColor(uTL1,color[Var2]);
color = BLUE;
TL_SetColor(uTL2,color);
TL2_exist = 1;
} Else {
uTL1 = TL_New(고[1,3],고[1,4],고[1,1],저[1,3],저[1,4],저[1,1]);
TL_SetColor(uTL1,color);
TL2_exist = 0;
}
}
}
TL_SetSize(uTL1,6);
TL_SetSize(uTL2,1);
if uT != uT[1] and uT == 1 then
{
TL11 = TL_New(sdate[index-저[1,2]],stime[index-저[1,2]],고[2,1],sdate[index-고[2,2]],stime[index-고[2,2]],고[2,1]);
TL12 = TL_New(sdate[index-저[1,2]],stime[index-저[1,2]],저[1,1],sdate[index-고[2,2]],stime[index-고[2,2]],저[1,1]);
TL13 = TL_New(sdate[index-고[2,2]],stime[index-고[2,2]],고[2,1],sdate[index-고[2,2]],stime[index-고[2,2]],저[1,1]);
TL14 = TL_New(sdate[index-저[1,2]],stime[index-저[1,2]],고[2,1],sdate[index-저[1,2]],stime[index-저[1,2]],저[1,1]);
// PlaySound("C:₩예스트레이더₩data₩Sound₩alert.wav");
TL_SetColor(Tl11,BLUE);
TL_SetColor(Tl12,BLUE);
TL_SetColor(Tl13,BLUE);
TL_SetColor(Tl14,BLUE);
TL_SetSize(Tl11,1);
TL_SetSize(Tl12,1);
TL_SetSize(Tl13,1);
TL_SetSize(Tl14,1);
}
if uT != uT[1] and uT == -1 then
{
TL11 = TL_New(sdate[index-저[2,2]],stime[index-저[2,2]],고[1,1],sdate[index-고[1,2]],stime[index-고[1,2]],고[1,1]);
TL12 = TL_New(sdate[index-저[2,2]],stime[index-저[2,2]],저[2,1],sdate[index-고[1,2]],stime[index-고[1,2]],저[2,1]);
TL13 = TL_New(sdate[index-고[1,2]],stime[index-고[1,2]],고[1,1],sdate[index-고[1,2]],stime[index-고[1,2]],저[2,1]);
TL14 = TL_New(sdate[index-저[2,2]],stime[index-저[2,2]],고[1,1],sdate[index-저[2,2]],stime[index-저[2,2]],저[2,1]);
// PlaySound("C:₩예스트레이더₩data₩Sound₩alert.wav");
TL_SetColor(Tl11,RED);
TL_SetColor(Tl12,RED);
TL_SetColor(Tl13,RED);
TL_SetColor(Tl14,red);
TL_SetSize(Tl11,1);
TL_SetSize(Tl12,1);
TL_SetSize(Tl13,6);
TL_SetSize(Tl14,6);
}
2024-09-27
770
글번호 183796
지표