답변완료
문의드립니다.
/*스윙 고/저점을 이용한 자동 추세선 생성 + 추세선 돌파 매수·매도 시스템*/input : len(1); var : sh1(0), sh2(0), shBar1(0), shBar2(0);var : sl1(0), sl2(0), slBar1(0), slBar2(0);var : TL_HighVal1(0), TL_HighVal2(0);var : TL_LowVal1(0), TL_LowVal2(0);var : highTrend(0), lowTrend(0);// 최근 두 스윙고점sh1 = SwingHigh(1, H, len, len, 100);sh2 = SwingHigh(2, H, len, len, 100);shBar1 = SwingHighBar(1, H, len, len, 100);shBar2 = SwingHighBar(2, H, len, len, 100);// 최근 두 스윙저점sl1 = SwingLow(1, L, len, len, 100);sl2 = SwingLow(2, L, len, len, 100);slBar1 = SwingLowBar(1, L, len, len, 100);slBar2 = SwingLowBar(2, L, len, len, 100);// ① 하락추세선 공식 : 두 스윙고점을 연결한 직선의 현재봉 y값if shBar2 > shBar1 and sh1 > 0 and sh2 > 0 then{ TL_HighVal1 = H[shBar2]; TL_HighVal2 = H[shBar1]; highTrend = TL_HighVal2 + (TL_HighVal1 - TL_HighVal2) * (shBar1) / (shBar2 - shBar1);}// ② 상승추세선 공식 : 두 스윙저점을 연결한 직선의 현재봉 y값if slBar2 > slBar1 and sl1 > 0 and sl2 > 0 then{ TL_LowVal1 = L[slBar2]; TL_LowVal2 = L[slBar1]; lowTrend = TL_LowVal2 + (TL_LowVal1 - TL_LowVal2) * (slBar1) / (slBar2 - slBar1);}if C > highTrend and C[1]<= highTrend[1] then{ Buy("추세상향돌파");}if marketposition == 1 then{ exitlong("롱청산",AtStop,low[1]);}######################################################################################################// ? 하락추세선(스윙고점 연결)if shBar2 > shBar1 and sh1 > 0 and sh2 > 0 then{ TL_High = TL_New( sdate[shBar2], stime[shBar2], H[shBar2], sdate[shBar1], stime[shBar1], H[shBar1] ); TL_SetColor(TL_High, Red); TL_SetSize(TL_High, 2);}// ? 상승추세선(스윙저점 연결)if slBar2 > slBar1 and sl1 > 0 and sl2 > 0 then{ TL_Low = TL_New( sdate[slBar2], stime[slBar2], L[slBar2], sdate[slBar1], stime[slBar1], L[slBar1] ); TL_SetColor(TL_Low, Green); TL_SetSize(TL_Low, 2);}########################################################################질문1. 추세선이 왜 중간에 끊어지는지 모르겠습니다. swinghigh를 연결하며 이어져야 할것 같은데 말입니다. 질문2. 진입이 왜 저기서 일어나는지 모르겠습니다. 빨간선을 크로스업했을때 진입을 의도한것인데...질문3. 청산이 왜 2봉전 저가에서 일어나는지 모르겠습니다. 코드는 1봉전 저가인데...항상 감사드립니다.
답변완료
변환 부탁 드립니다.
//트레이딩 뷰 지표입니다....변환 부탁드립니다.//@version=5indicator('[@btc_charlie] Trader XO Macro Trend Scanner', overlay=true)// Variablesvar ok = 0var countBuy = 0var countSell = 0src = input(close, title='OHLC Type')i_fastEMA = input(12, title='Fast EMA')i_slowEMA = input(25, title='Slow EMA')i_defEMA = input(25, title='Consolidated EMA')// Allow the option to show single or double EMAi_bothEMAs = input(title='Show Both EMAs', defval=true)// Define EMAsv_fastEMA = ta.ema(src, i_fastEMA)v_slowEMA = ta.ema(src, i_slowEMA)v_biasEMA = ta.ema(src, i_defEMA)// Color the EMAsemaColor = v_fastEMA > v_slowEMA ? color.green : v_fastEMA < v_slowEMA ? color.red : #FF530D// Plot EMAsplot(i_bothEMAs ? na : v_biasEMA, color=emaColor, linewidth=3, title='Consolidated EMA')plot(i_bothEMAs ? v_fastEMA : na, title='Fast EMA', color=emaColor)plot(i_bothEMAs ? v_slowEMA : na, title='Slow EMA', color=emaColor)// Colour the barsbuy = v_fastEMA > v_slowEMAsell = v_fastEMA < v_slowEMAif buy countBuy += 1 countBuyif buy countSell := 0 countSellif sell countSell += 1 countSellif sell countBuy := 0 countBuybuysignal = countBuy < 2 and countBuy > 0 and countSell < 1 and buy and not buy[1]sellsignal = countSell > 0 and countSell < 2 and countBuy < 1 and sell and not sell[1]barcolor(buysignal ? color.green : na)barcolor(sellsignal ? color.red : na)// Plot Bull/Bearplotshape(buysignal, title='Bull', text='Bull', style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.black, 0), size=size.tiny)plotshape(sellsignal, title='Bear', text='Bear', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.black, 0), size=size.tiny)bull = countBuy > 1bear = countSell > 1barcolor(bull ? color.green : na)barcolor(bear ? color.red : na)// Set Alertsalertcondition(ta.crossover(v_fastEMA, v_slowEMA), title='Bullish EMA Cross', message='Bullish EMA crossover')alertcondition(ta.crossunder(v_fastEMA, v_slowEMA), title='Bearish EMA Cross', message='Bearish EMA Crossover')// Stoch RSI codesmoothK = input.int(3, 'K', minval=1)smoothD = input.int(3, 'D', minval=1)lengthRSI = input.int(14, 'RSI Length', minval=1)lengthStoch = input.int(14, 'Stochastic Length', minval=1)rsi1 = ta.rsi(src, lengthRSI)k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)d = ta.sma(k, smoothD)bandno0 = input.int(80, minval=1, title='Upper Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')bandno2 = input.int(50, minval=1, title='Middle Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')bandno1 = input.int(20, minval=1, title='Lower Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')// AlertscrossoverAlertBgColourMidOnOff = input.bool(title='Crossover Alert Background Colour (Middle Level) [ON/OFF]', group='Crossover Alerts', defval=false)crossoverAlertBgColourOBOSOnOff = input.bool(title='Crossover Alert Background Colour (OB/OS Level) [ON/OFF]', group='Crossover Alerts', defval=false)crossoverAlertBgColourGreaterThanOnOff = input.bool(title='Crossover Alert >input [ON/OFF]', group='Crossover Alerts', defval=false)crossoverAlertBgColourLessThanOnOff = input.bool(title='Crossover Alert <input [ON/OFF]', group='Crossover Alerts', defval=false)maTypeChoice = input.string('EMA', title='MA Type', group='Moving Average', options=['EMA', 'WMA', 'SMA', 'None'])maSrc = input.source(close, title='MA Source', group='Moving Average')maLen = input.int(200, minval=1, title='MA Length', group='Moving Average')maValue = if maTypeChoice == 'EMA' ta.ema(maSrc, maLen)else if maTypeChoice == 'WMA' ta.wma(maSrc, maLen)else if maTypeChoice == 'SMA' ta.sma(maSrc, maLen)else 0crossupCHECK = maTypeChoice == 'None' or open > maValue and maTypeChoice != 'None'crossdownCHECK = maTypeChoice == 'None' or open < maValue and maTypeChoice != 'None'crossupalert = crossupCHECK and ta.crossover(k, d) and (k < bandno2 or d < bandno2)crossdownalert = crossdownCHECK and ta.crossunder(k, d) and (k > bandno2 or d > bandno2)crossupOSalert = crossupCHECK and ta.crossover(k, d) and (k < bandno1 or d < bandno1)crossdownOBalert = crossdownCHECK and ta.crossunder(k, d) and (k > bandno0 or d > bandno0)aboveBandalert = ta.crossunder(k, bandno0)belowBandalert = ta.crossover(k, bandno1)bgcolor(color=crossupalert and crossoverAlertBgColourMidOnOff ? #4CAF50 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert Background Colour (Middle Level)', transp=70)bgcolor(color=crossupOSalert and crossoverAlertBgColourOBOSOnOff ? #fbc02d : crossdownOBalert and crossoverAlertBgColourOBOSOnOff ? #000000 : na, title='Crossover Alert Background Colour (OB/OS Level)', transp=70)bgcolor(color=aboveBandalert and crossoverAlertBgColourGreaterThanOnOff ? #ff0014 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert - K > Upper level', transp=70)bgcolor(color=belowBandalert and crossoverAlertBgColourLessThanOnOff ? #4CAF50 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert - K < Lower level', transp=70)alertcondition(crossupalert or crossdownalert, title='Stoch RSI Crossover', message='STOCH RSI CROSSOVER')
답변완료
글번호 228073 번 추가 문의
앞서 글번호 228073 번에 아래 식을 주셨는데, 그럼 atr 을 500이 아니라 300으로 해서 30일치를 검색하는 식으로 부탁드립니다.1번과 2번으로 나눠 주셨는데, 어떻게 사용하는 것일까요?사용자 함수까지 조건식에 넣어서, 종목검색 창에 붙여 넣으면 되게 부탁드립니다.1 . 사용자함수함수명 : RngCheck반환값형 : 숫자형input : 기준(Numeric),범위(Numeric);var : C0(0),C1(0),C2(0),C3(0),C4(0);var : C5(0),C6(0),C7(0),C8(0),C9(0);var : C10(0),C11(0),C12(0),C13(0),C14(0);var : C15(0),C16(0),C17(0),C18(0),C19(0);C0=IFF(abs(C-기준)>범위,1,0); C1=IFF(abs(C[1]-기준)>범위,1,0); C2=IFF(abs(C[2]-기준)>범위,1,0); C3=IFF(abs(C[3]-기준)>범위,1,0); C4=IFF(abs(C[4]-기준)>범위,1,0); C5=IFF(abs(C[5]-기준)>범위,1,0); C6=IFF(abs(C[6]-기준)>범위,1,0); C7=IFF(abs(C[7]-기준)>범위,1,0); C8=IFF(abs(C[8]-기준)>범위,1,0); C9=IFF(abs(C[9]-기준)>범위,1,0); C10=IFF(abs(C[10]-기준)>범위,1,0); C11=IFF(abs(C[11]-기준)>범위,1,0); C12=IFF(abs(C[12]-기준)>범위,1,0); C13=IFF(abs(C[13]-기준)>범위,1,0); C14=IFF(abs(C[14]-기준)>범위,1,0); C15=IFF(abs(C[15]-기준)>범위,1,0); C16=IFF(abs(C[16]-기준)>범위,1,0); C17=IFF(abs(C[17]-기준)>범위,1,0); C18=IFF(abs(C[18]-기준)>범위,1,0); C19=IFF(abs(C[19]-기준)>범위,1,0); RngCheck = C0+C1+C2+C3+C4+C5+C6+C7+C8+ C9+C10+C11+C12+C13+C14+C15+C16+C17+C18+C19;2input : 기간(1),Rt(1),배수(1);var : at(0),mm(0),rg(0),chk(0),Range중(False),Range거래량(0);var : 전체합(0),Range봉수(0),평균거래량(0);var : 상단(0),양봉(False),돌파(False),거래량급증(False);var : A(0),b1(0),d(0),e(0),f(0),g(0),k(0),j(0),t(0),y(0),r(0),q(0);var : 볼밴라인(0),볼밴돌파(False),볼밴위(False);At = ATR(500);Mm = avg(C, 기간);Rg = At * Rt / 10;Chk = RngChk(Mm, Rg);Range중 = Chk == 0;Range거래량 = iff(Range중, V, 0);전체합 = Accum(Range거래량);Range봉수 = Accum(iff(Range중,1,0));평균거래량 = 전체합 / Range봉수;상단 = Mm + Rg;양봉 = C > O;돌파 = C > 상단;거래량급증 = V > 평균거래량 * 배수;A = BollBandUp(20, 2);B1 = Ema(A, 56);D = BollBandUp(40, 2);E = Ema(D, 56);F = BollBandUp(60, 2);G = Ema(F, 56);K = BollBandUp(90, 2);J = Ema(K, 56);T = BollBandUp(100, 2);Y = Ema(T, 56);R = (B1 + E + G + J + Y) / 5;Q = (C - O) / 3;볼밴라인 = iff(C > O, R - Q, R);볼밴돌파 = H > 볼밴라인;볼밴위 = C > 볼밴라인;if Range중[1] == true && 돌파 && 양봉 && 거래량급증 && (볼밴돌파 or 볼밴위) then var1 = sDate;Else var1 = 0;if CountIf(var1>0,30) >= 1 then Find(var1);