커뮤니티

지표식 부탁드립니다.

프로필 이미지
고도산
2025-06-02 21:34:10
254
글번호 191359
답변완료
TradomgView 식을 변환해보았는데 원래와 모양이 다르군요. 수정을 부탁드립니다. 미리 감사드립니다. //@version=6 indicator('#SwingArm ATR Trend', overlay = true, timeframe = '') //{ // # Author: Jose Azcarate //} // inputs // //{ trailType = input.string('modified', 'Trailtype', options = ['modified', 'unmodified']) ATRPeriod = input(28, 'ATR Period') ATRFactor = input(5, 'ATR Factor') show_fib_entries = input(true, 'Show Fib Entries?') //norm_o = security(tickerid(syminfo.prefix,syminfo.ticker), timeframe.period, open) //norm_h = security(tickerid(syminfo.prefix,syminfo.ticker), timeframe.period, high) //norm_l = security(tickerid(syminfo.prefix,syminfo.ticker), timeframe.period, low) //norm_c = security(tickerid(syminfo.prefix,syminfo.ticker), timeframe.period, close) norm_o = open norm_h = high norm_l = low norm_c = close //} //////// FUNCTIONS ////////////// //{ // Wilders ma // Wild_ma(_src, _malength) => _wild = 0.0 _wild := nz(_wild[1]) + (_src - nz(_wild[1])) / _malength _wild /////////// TRUE RANGE CALCULATIONS ///////////////// HiLo = math.min(norm_h - norm_l, 1.5 * nz(ta.sma(norm_h - norm_l, ATRPeriod))) HRef = norm_l <= norm_h[1] ? norm_h - norm_c[1] : norm_h - norm_c[1] - 0.5 * (norm_l - norm_h[1]) LRef = norm_h >= norm_l[1] ? norm_c[1] - norm_l : norm_c[1] - norm_l - 0.5 * (norm_l[1] - norm_h) trueRange = trailType == 'modified' ? math.max(HiLo, HRef, LRef) : math.max(norm_h - norm_l, math.abs(norm_h - norm_c[1]), math.abs(norm_l - norm_c[1])) //} /////////// TRADE LOGIC //////////////////////// //{ loss = ATRFactor * Wild_ma(trueRange, ATRPeriod) Up = norm_c - loss Dn = norm_c + loss TrendUp = Up TrendDown = Dn Trend = 1 TrendUp := norm_c[1] > TrendUp[1] ? math.max(Up, TrendUp[1]) : Up TrendDown := norm_c[1] < TrendDown[1] ? math.min(Dn, TrendDown[1]) : Dn Trend := norm_c > TrendDown[1] ? 1 : norm_c < TrendUp[1] ? -1 : nz(Trend[1], 1) trail = Trend == 1 ? TrendUp : TrendDown ex = 0.0 ex := ta.crossover(Trend, 0) ? norm_h : ta.crossunder(Trend, 0) ? norm_l : Trend == 1 ? math.max(ex[1], norm_h) : Trend == -1 ? math.min(ex[1], norm_l) : ex[1] //} // //////// PLOT TP and SL ///////////// //{ plot(trail, 'Trailingstop', style = plot.style_line, color = Trend == 1 ? color.red : Trend == -1 ? color.green : na) plot(ex, 'Extremum', style = plot.style_circles, color = Trend == 1 ? color.fuchsia : Trend == -1 ? color.lime : na) //} ////// FIBONACCI LEVELS /////////// //{ state = Trend == 1 ? 'long' : 'short' fib1Level = 61.8 fib2Level = 78.6 fib3Level = 88.6 f1 = ex + (trail - ex) * fib1Level / 100 f2 = ex + (trail - ex) * fib2Level / 100 f3 = ex + (trail - ex) * fib3Level / 100 l100 = trail + 0 Fib1 = plot(f1, 'Fib 1', style = plot.style_line, color = color.new(color.yellow, 0)) Fib2 = plot(f2, 'Fib 2', style = plot.style_line, color = color.new(color.yellow, 0)) Fib3 = plot(f3, 'Fib 3', style = plot.style_line, color = color.new(color.yellow, 0)) L100 = plot(l100, 'l100', style = plot.style_line, color = color.new(color.yellow, 0)) fill(Fib1, Fib2, color = state == 'long' ? color.new(color.red, 70) : state == 'short' ? color.new(color.green, 70) : na) fill(Fib2, Fib3, color = state == 'long' ? color.new(color.red, 50) : state == 'short' ? color.new(color.green, 50) : na) fill(Fib3, L100, color = state == 'long' ? color.new(color.red, 30) : state == 'short' ? color.new(color.green, 30) : na) l1 = state[1] == 'long' and ta.crossunder(norm_c, f1[1]) l2 = state[1] == 'long' and ta.crossunder(norm_c, f2[1]) l3 = state[1] == 'long' and ta.crossunder(norm_c, f3[1]) s1 = state[1] == 'short' and ta.crossover(norm_c, f1[1]) s2 = state[1] == 'short' and ta.crossover(norm_c, f2[1]) s3 = state[1] == 'short' and ta.crossover(norm_c, f3[1]) atr = ta.sma(trueRange, 14) /////////// FIB PLOTS /////////////////. plotshape(show_fib_entries and l1 ? low - atr : na, 'LS1', style = shape.triangleup, location = location.belowbar, color = color.new(color.yellow, 0), size = size.tiny) plotshape(show_fib_entries and l2 ? low - 1.5 * atr : na, 'LS2', style = shape.triangleup, location = location.belowbar, color = color.new(color.yellow, 0), size = size.tiny) plotshape(show_fib_entries and l3 ? low - 2 * atr : na, 'LS3', style = shape.triangleup, location = location.belowbar, color = color.new(color.yellow, 0), size = size.tiny) plotshape(show_fib_entries and s1 ? high + atr : na, 'SS1', style = shape.triangledown, location = location.abovebar, color = color.new(color.purple, 0), size = size.tiny) plotshape(show_fib_entries and s2 ? high + 1.5 * atr : na, 'SS2', style = shape.triangledown, location = location.abovebar, color = color.new(color.purple, 0), size = size.tiny) plotshape(show_fib_entries and s3 ? high + 2 * atr : na, 'SS3', style = shape.triangledown, location = location.abovebar, color = color.new(color.purple, 0), size = size.tiny) //}
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-06-02 22:12:10

안녕하세요 예스스탁입니다. input : trailType(1); #1: modified 2:unmodified input : ATRPeriod(28); input : ATRFactor(5); input : show_fib_entries(true); var : norm_o(0),norm_h(0),norm_l(0),norm_c(0); var : TR(0); norm_o = open; norm_h = high; norm_l = low; norm_c = close; var : _wild(0),HiLo(0),HRef(0),LRef(0),loss(0); var : up(0),dn(0); /////////// TRUE RANGE CALCULATIONS ///////////////// HiLo = min(norm_h - norm_l, 1.5 * iff(isnan(ma(norm_h - norm_l, ATRPeriod)) ==true,0,ma(norm_h - norm_l, ATRPeriod))); HRef = iff(norm_l <= norm_h[1] , norm_h - norm_c[1] , norm_h - norm_c[1] - 0.5 * (norm_l - norm_h[1])); LRef = iff(norm_h >= norm_l[1] , norm_c[1] - norm_l , norm_c[1] - norm_l - 0.5 * (norm_l[1] - norm_h)); TR = iff(trailType == 1 , max(HiLo, HRef, LRef), max(norm_h - norm_l, abs(norm_h - norm_c[1]), abs(norm_l - norm_c[1]))); _wild = 0.0; _wild = IFF(IsNan(_wild[1])==true,0,_wild[1])+ (TR - IFF(IsNan(_wild[1])==true,0,_wild[1])) / ATRPeriod; loss = ATRFactor * _wild; Up = norm_c - loss; Dn = norm_c + loss; var : TrendUp(0),TrendDown(0),trend(0),trail(0),ex(0); TrendUp = Up; TrendDown = Dn; Trend = 1; TrendUp = iff(norm_c[1] > TrendUp[1] , max(Up, TrendUp[1]) , Up); TrendDown= iff(norm_c[1] < TrendDown[1] , min(Dn, TrendDown[1]) , Dn); Trend = iff(norm_c > TrendDown[1] , 1 , IFf( norm_c < TrendUp[1] , -1 , iff(isnan(Trend[1]) == true, 1,trend[1]))); trail = iff(Trend == 1 , TrendUp , TrendDown); ex = 0.0; ex = iff(crossup(Trend, 0) , norm_h , IFf(CrossDown(Trend, 0) , norm_l ,IFf(Trend == 1 , max(ex[1], norm_h) , IFf(Trend == -1 , min(ex[1], norm_l) , ex[1])))); plot1(trail,"Trailingstop",IFf(Trend == 1 , red ,IFf(Trend == -1 ,green,Black))); plot2(ex,"Extremum", iff(Trend == 1 , Magenta , IFf(Trend == -1 , lime , Black))); var : state(0); var : fib1Level(0),fib2Level(0),fib3Level(0); var : f1(0),f2(0),f3(0),l100(0); state = iff(Trend == 1 , 1 , -1); fib1Level = 61.8; fib2Level = 78.6; fib3Level = 88.6; f1 = ex + (trail - ex) * fib1Level / 100; f2 = ex + (trail - ex) * fib2Level / 100; f3 = ex + (trail - ex) * fib3Level / 100; l100 = trail + 0; plot3(f1, "Fib 1",yellow); plot4(f2, "Fib 2",yellow); plot5(f3, "Fib 3",yellow); plot6(l100, "l100",yellow); var : l1(False),l2(false),l3(False),s1(False),s2(False),s3(False),A(0); var : tx1(0),tx2(0),tx3(0),tx4(0),tx5(0),tx6(0); l1 = state[1] == 1 and CrossDown(norm_c, f1[1]); l2 = state[1] == 1 and CrossDown(norm_c, f2[1]); l3 = state[1] == 1 and CrossDown(norm_c, f3[1]); s1 = state[1] == -1 and CrossUp(norm_c, f1[1]); s2 = state[1] == -1 and CrossUp(norm_c, f2[1]); s3 = state[1] == -1 and CrossUp(norm_c, f3[1]); A = ma(TR, 14); if show_fib_entries and l1 Then { tx1 = text_new(sDate,sTime,low,"▲"); Text_SetStyle(tx1,2,0); Text_SetColor(tx1,Yellow); } if show_fib_entries and l2 Then { tx2 = text_new(sDate,sTime,low,"▲"); Text_SetStyle(tx2,2,0); Text_SetColor(tx2,Yellow); } if show_fib_entries and l3 Then { tx3 = text_new(sDate,sTime,low,"▲"); Text_SetStyle(tx3,2,0); Text_SetColor(tx3,Yellow); } if show_fib_entries and s1 Then { tx4 = text_new(sDate,sTime,high,"▼"); Text_SetStyle(tx4,2,1); Text_SetColor(tx4,Purple); } if show_fib_entries and s2 Then { tx5 = text_new(sDate,sTime,high,"▼"); Text_SetStyle(tx5,2,1); Text_SetColor(tx5,Purple); } if show_fib_entries and s3 Then { tx6 = text_new(sDate,sTime,high,"▼"); Text_SetStyle(tx6,2,1); Text_SetColor(tx6,Purple); } 즐거운 하루되세요 > 고도산 님이 쓴 글입니다. > 제목 : 지표식 부탁드립니다. > TradomgView 식을 변환해보았는데 원래와 모양이 다르군요. 수정을 부탁드립니다. 미리 감사드립니다. //@version=6 indicator('#SwingArm ATR Trend', overlay = true, timeframe = '') //{ // # Author: Jose Azcarate //} // inputs // //{ trailType = input.string('modified', 'Trailtype', options = ['modified', 'unmodified']) ATRPeriod = input(28, 'ATR Period') ATRFactor = input(5, 'ATR Factor') show_fib_entries = input(true, 'Show Fib Entries?') //norm_o = security(tickerid(syminfo.prefix,syminfo.ticker), timeframe.period, open) //norm_h = security(tickerid(syminfo.prefix,syminfo.ticker), timeframe.period, high) //norm_l = security(tickerid(syminfo.prefix,syminfo.ticker), timeframe.period, low) //norm_c = security(tickerid(syminfo.prefix,syminfo.ticker), timeframe.period, close) norm_o = open norm_h = high norm_l = low norm_c = close //} //////// FUNCTIONS ////////////// //{ // Wilders ma // Wild_ma(_src, _malength) => _wild = 0.0 _wild := nz(_wild[1]) + (_src - nz(_wild[1])) / _malength _wild /////////// TRUE RANGE CALCULATIONS ///////////////// HiLo = math.min(norm_h - norm_l, 1.5 * nz(ta.sma(norm_h - norm_l, ATRPeriod))) HRef = norm_l <= norm_h[1] ? norm_h - norm_c[1] : norm_h - norm_c[1] - 0.5 * (norm_l - norm_h[1]) LRef = norm_h >= norm_l[1] ? norm_c[1] - norm_l : norm_c[1] - norm_l - 0.5 * (norm_l[1] - norm_h) trueRange = trailType == 'modified' ? math.max(HiLo, HRef, LRef) : math.max(norm_h - norm_l, math.abs(norm_h - norm_c[1]), math.abs(norm_l - norm_c[1])) //} /////////// TRADE LOGIC //////////////////////// //{ loss = ATRFactor * Wild_ma(trueRange, ATRPeriod) Up = norm_c - loss Dn = norm_c + loss TrendUp = Up TrendDown = Dn Trend = 1 TrendUp := norm_c[1] > TrendUp[1] ? math.max(Up, TrendUp[1]) : Up TrendDown := norm_c[1] < TrendDown[1] ? math.min(Dn, TrendDown[1]) : Dn Trend := norm_c > TrendDown[1] ? 1 : norm_c < TrendUp[1] ? -1 : nz(Trend[1], 1) trail = Trend == 1 ? TrendUp : TrendDown ex = 0.0 ex := ta.crossover(Trend, 0) ? norm_h : ta.crossunder(Trend, 0) ? norm_l : Trend == 1 ? math.max(ex[1], norm_h) : Trend == -1 ? math.min(ex[1], norm_l) : ex[1] //} // //////// PLOT TP and SL ///////////// //{ plot(trail, 'Trailingstop', style = plot.style_line, color = Trend == 1 ? color.red : Trend == -1 ? color.green : na) plot(ex, 'Extremum', style = plot.style_circles, color = Trend == 1 ? color.fuchsia : Trend == -1 ? color.lime : na) //} ////// FIBONACCI LEVELS /////////// //{ state = Trend == 1 ? 'long' : 'short' fib1Level = 61.8 fib2Level = 78.6 fib3Level = 88.6 f1 = ex + (trail - ex) * fib1Level / 100 f2 = ex + (trail - ex) * fib2Level / 100 f3 = ex + (trail - ex) * fib3Level / 100 l100 = trail + 0 Fib1 = plot(f1, 'Fib 1', style = plot.style_line, color = color.new(color.yellow, 0)) Fib2 = plot(f2, 'Fib 2', style = plot.style_line, color = color.new(color.yellow, 0)) Fib3 = plot(f3, 'Fib 3', style = plot.style_line, color = color.new(color.yellow, 0)) L100 = plot(l100, 'l100', style = plot.style_line, color = color.new(color.yellow, 0)) fill(Fib1, Fib2, color = state == 'long' ? color.new(color.red, 70) : state == 'short' ? color.new(color.green, 70) : na) fill(Fib2, Fib3, color = state == 'long' ? color.new(color.red, 50) : state == 'short' ? color.new(color.green, 50) : na) fill(Fib3, L100, color = state == 'long' ? color.new(color.red, 30) : state == 'short' ? color.new(color.green, 30) : na) l1 = state[1] == 'long' and ta.crossunder(norm_c, f1[1]) l2 = state[1] == 'long' and ta.crossunder(norm_c, f2[1]) l3 = state[1] == 'long' and ta.crossunder(norm_c, f3[1]) s1 = state[1] == 'short' and ta.crossover(norm_c, f1[1]) s2 = state[1] == 'short' and ta.crossover(norm_c, f2[1]) s3 = state[1] == 'short' and ta.crossover(norm_c, f3[1]) atr = ta.sma(trueRange, 14) /////////// FIB PLOTS /////////////////. plotshape(show_fib_entries and l1 ? low - atr : na, 'LS1', style = shape.triangleup, location = location.belowbar, color = color.new(color.yellow, 0), size = size.tiny) plotshape(show_fib_entries and l2 ? low - 1.5 * atr : na, 'LS2', style = shape.triangleup, location = location.belowbar, color = color.new(color.yellow, 0), size = size.tiny) plotshape(show_fib_entries and l3 ? low - 2 * atr : na, 'LS3', style = shape.triangleup, location = location.belowbar, color = color.new(color.yellow, 0), size = size.tiny) plotshape(show_fib_entries and s1 ? high + atr : na, 'SS1', style = shape.triangledown, location = location.abovebar, color = color.new(color.purple, 0), size = size.tiny) plotshape(show_fib_entries and s2 ? high + 1.5 * atr : na, 'SS2', style = shape.triangledown, location = location.abovebar, color = color.new(color.purple, 0), size = size.tiny) plotshape(show_fib_entries and s3 ? high + 2 * atr : na, 'SS3', style = shape.triangledown, location = location.abovebar, color = color.new(color.purple, 0), size = size.tiny) //}