커뮤니티

수식 부탁드립니다

프로필 이미지
사노소이
2024-09-27 13:50:56
940
글번호 183802
답변완료
지표식 부탁드립니다. 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!")
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2024-09-27 15:22:35

안녕하세요 예스스탁입니다. 사용자함수 2개를 먼저 만드신 후에 지표식 만들어서 적용하시면 됩니다. 1. 사용자함수명: var_func 반환값형 : 숫자형 input : src1(Numeric),length(Numeric); var : valpha1(0),vud11(0),vdd11(0),vUD1(0),vDD1(0),vCMO1(0); valpha1 = 2 / (length + 1); vud11 = iff(src1 > src1[1] , src1 - src1[1] , 0); vdd11 = iff(src1 < src1[1] , src1[1] - src1 , 0); vUD1 = AccumN(vud11, 9); vDD1 = AccumN(vdd11, 9); vCMO1 = iff(isnan((vUD1 - vDD1) / (vUD1 + vDD1))==true,0,(vUD1 - vDD1) / (vUD1 + vDD1)); var_func = iff(IsNan(valpha1 * abs(vCMO1) * src1) == true,0,valpha1 * abs(vCMO1) * src1) + (1 - valpha1 * abs(vCMO1)) * iff(IsNan(var_func[1]),0,var_func[1]); 2. 사용자함수명: getMA 반환값형 : 숫자형 input : src(Numeric),length(Numeric),method(Numeric); var : DEMA(0),wwalpha(0),wwma(0),zxLag(0),zxEMAData(0),ZLEMA(0),HMA(0); if method == 1 then getMA = ma(src, length); if method == 2 then getMA = ema(src, length); if method == 3 then getMA = wma(src, length); if method == 4 then { DEMA = 2 * ema(src, length) - ema(ema(src, length), length); getMA = DEMA; } if method == 5 then getMA = ma(ma(src, Ceiling(length / 2)), floor(length / 2) + 1); if method == 6 then getMA = Var_func(src,length); if method == 7 then { wwalpha = 1 / length; WWMA = wwalpha * src + (1 - wwalpha) * iff(IsNan(WWMA[1]) == False,WWMA[1],0); getMA = WWMA; } if method == 8 then { zxLag = iff(length / 2 == round(length / 2,0) , length / 2 , (length - 1) / 2); zxEMAData = src + src - src[zxLag]; ZLEMA = ema(zxEMAData, length); getMA = ZLEMA; } if method == 9 then getMA = LRL(src,length)+LRS(src,length); if method == 10 then { HMA = wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length),0)); getMA = HMA; } 3. 지표 input : length(2); input : percent(15); input : X3(0.2); input : X5(0.177); input : mav(1); # 1:SMA, 2:EMA, 3:WMA, 4:DEMA, 5:TMA, 6:VAR, 7:WWMA, 8:ZLEMA, 9:TSF, 10:HULL var : src(0),MAvg(0),fark(0),longStop(0),longStopPrev(0),shortStop(0),shortStopPrev(0); var : dir(0),mt(0),OTT(0),OTTC(0); src = close; MAvg = getMA(src, length,mav); fark=MAvg*percent*0.01; longStop = MAvg - fark; longStopPrev = iff(IsNan(longStop[1])==true, longStop,longStop[1]); longStop = iff(MAvg > longStopPrev , max(longStop, longStopPrev) , longStop); shortStop = MAvg + fark; shortStopPrev = iff(isnan(shortStop[1])==true, shortStop,shortStop[1]); shortStop = iff(MAvg < shortStopPrev , min(shortStop, shortStopPrev) , shortStop); dir = 1; dir = iff(IsNan(dir[1])==true, dir,dir[1]); dir = iff(dir == -1 and MAvg > shortStopPrev , 1 , IFf(dir == 1 and MAvg < longStopPrev , -1 , dir)); MT = iff(dir == 1 , longStop , shortStop); OTT=iff(MAvg>MT , MT*(200+percent)/200 , MT*(200-percent)/200); OTTC = iff(MAvg > MAvg[1] , green , red); plot1(OTT[2],"OTT",Black); plot2(MAvg, "Support Line",OTTC); plot3(OTT[2]*(1+X3),"OTT UPPER"); plot4(OTT[2]*(1+X3*0.618),"OTT UPPER HALF "); plot5(OTT[2]*(1+X3*0.382),"OTT UPPER HALF "); plot6(OTT[2]*(1-X5),"OTT LOWER"); plot7(OTT[2]*(1-X5*0.618),"OTT LOWER HALF"); plot8(OTT[2]*(1-X5*0.382),"OTT LOWER HALF"); 즐거운 하루되세요 > 사노소이 님이 쓴 글입니다. > 제목 : 수식 부탁드립니다 > 지표식 부탁드립니다. 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!")