커뮤니티

예트로 변환 부탁합니다

프로필 이미지
고도산
2025-03-30 18:23:59
468
글번호 189681
답변완료
트레이딩뷰 소스를 예트로 변환 부탁합니다. 제가 시도했는데 box에서 막히네요. //@version=5 indicator("ZLMA Trend Levels [ChartPrime]", overlay = true) //-----------------------------------} // User Inputs //-----------------------------------{ int length = input.int(15, title="Length") // Length for the moving average calculations bool show_levl = input.bool(true, "Trend Levels") // Toggle to show trend levels // Colors for the trend levels color up = input.color(color.red, "+", group = "Colors", inline = "i") color dn = input.color(color.lime, "-", group = "Colors", inline = "i") var box1 = box(na) // Variable to store the box series float atr = ta.atr(200) // Average True Range (ATR) for trend levels //-----------------------------------} // Indicator Calcs //-----------------------------------{ series float emaValue = ta.ema(close, length) // EMA of the closing price series float correction = close + (close - emaValue) // Correction factor for zero-lag calculation series float zlma = ta.ema(correction, length) // Zero-Lag Moving Average (ZLMA) bool signalUp = ta.crossover(zlma, emaValue) // Signal for bullish crossover bool signalDn = ta.crossunder(zlma, emaValue) // Signal for bearish crossunder // Determine the color of ZLMA based on its direction color zlma_color = zlma > zlma[3] ? up : zlma < zlma[3] ? dn : na color ema_col = emaValue < zlma ? up : dn // Determine the EMA color //-----------------------------------} // Visualization //-----------------------------------{ // Plot the Zero-Lag Moving Average p1 = plot(zlma, color = zlma_color, linewidth = 1, title = 'zlma') // Plot ZLMA p2 = plot(emaValue, color = ema_col, linewidth = 1, title = 'emaValue') // Plot EMA fill(p1, p2, zlma, emaValue, color.new(zlma_color, 80), color.new(ema_col, 80)) // Fill between ZLMA and EMA // Method to draw a box on the chart method draw_box(color col, top, bot, price)=> box.new( bar_index, top, bar_index, bot, col, 1, bgcolor = color.new(col, 90), text = str.tostring(math.round(price, 2)), text_size = size.tiny, text_color = chart.fg_color, text_halign = text.align_right ) // Logic to draw trend levels as boxes on the chart if show_levl bool check_signals = signalUp or signalDn // Check if there is an up or down signal switch // Draw a box when a bullish signal is detected signalUp => box1 := up.draw_box(zlma, zlma - atr, close) // Draw a box when a bearish signal is detected signalDn => box1 := dn.draw_box(zlma + atr, zlma, close) switch // Extend the right side of the box if no new signal is detected not signalUp or not signalDn => box1.set_right(bar_index + 4) => box1 := box(na) // Otherwise, reset the box switch // Add a downward label when price crosses below the bottom of the box ta.crossunder(high, box1.get_bottom()) and not check_signals[1] and not check_signals and emaValue > zlma=> label.new(bar_index - 1, high[1], "▼", color = color(na), textcolor = dn, style = label.style_label_down) // Add an upward label when price crosses above the top of the box ta.crossover(low, box1.get_top()) and not check_signals and not check_signals[1] and emaValue < zlma=> label.new(bar_index - 1, low[1], "▲", color = color(na), textcolor = up, style = label.style_label_up) // Plot shapes for up and down signals plotshape(signalUp ? zlma : na, "sig up", shape.diamond, location.absolute, color = up, size = size.tiny) plotshape(signalDn ? zlma : na, "sig dn", shape.diamond, location.absolute, color = dn, size = size.tiny) //-----------------------------------}
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-03-31 09:38:59

안녕하세요 예스스탁입니다. input : length(15); input : show_levl(true); input : up(red); input : dn(lime); var : box(Nan),box1(Nan),alpha(0),ATRV(0); var : emaValue(0),correction(0),zlma(0); var : signalUp(False),signalDn(False); var : zlma_color(0),Ema_col(0),ii(0),check_signals(False); var : tx(0),tx1(0),text(0),text1(0); alpha = 1 / 200 ; ATrV = IFf(IsNan(ATrV[1]) == true, ma(TrueRange,200) , alpha * TrueRange + (1 - alpha) * IFf(isnan(ATrV[1])==true,0,ATrV[1])); emaValue = ema(close, length); correction = close + (close - emaValue); zlma = ema(correction, length); signalUp = CrossUp(zlma, emaValue); signalDn = CrossDown(zlma, emaValue); zlma_color = iff(zlma > zlma[3] , up , iff(zlma < zlma[3] , dn , Nan)); ema_col = iff(emaValue < zlma , up , dn); plot1(zlma,"zlma",zlma_color); plot2(emaValue,"EmaValue", ema_col); if signalUp == true Then { tx = Text_New(sDate,sTime,zlma,"◆"); Text_SetColor(tx,up); Text_SetStyle(tx,2,2); var1 = zlma - ATRV; var2 = close; box = Box_New(sDate,sTime,zlma,NextBarSdate,NextBarStime,var1); Box_SetColor(box,up); Box_SetFill(box,true); text = Text_New(sDate,sTime,(zlma+var1)/2,NumToStr(var2,2)); Text_SetStyle(text,1,2); box1 = box[1]; text1 = text[1]; ii = Index; } Else if signalDn == true Then { tx = Text_New(sDate,sTime,zlma,"◆"); Text_SetColor(tx,dn); Text_SetStyle(tx,2,2); var1 = zlma + ATRV; var2 = close; box = Box_New(sDate,sTime,zlma,NextBarSdate,NextBarStime,var1); Box_SetColor(box,dn); Box_SetFill(box,true); text = Text_New(sDate,sTime,(zlma+var1)/2,NumToStr(var2,2)); Text_SetStyle(text,1,2); box1 = box[1]; text1 = text[1]; ii = Index; } Else { Box_SetEnd(box,sDate,sTime,var1); Text_SetLocation(text,sDate,sTime,avg(Box_GetBeginVal(box),Box_GetEndVal(box))); } if var11 > 0 and Index < ii+4 Then { Box_SetEnd(box1,sDate,sTime,Box_GetEndVal(box1)); Text_SetLocation(text1,sDate,sTime,avg(Box_GetBeginVal(box1),Box_GetEndVal(box1))); Text_SetStyle(text1,0,2); } check_signals = signalUp or signalDn; if CrossDown(high, min(Box_GetBeginVal(box),Box_GetEndVal(box))) and check_signals[1] == False and check_signals == False and emaValue > zlma Then { tx1 = Text_New(sDate[1],sTime[1],high[1],"▼"); Text_SetColor(tx1,dn); Text_SetStyle(tx1,2,1); } if CrossUp(low, max(Box_GetBeginVal(box),Box_GetEndVal(box))) and check_signals[1] == False and check_signals == False and emaValue < zlma Then { tx1 = Text_New(sDate[1],sTime[1],low[1],"▲"); Text_SetColor(tx1,up); Text_SetStyle(tx1,2,0); } 즐거운 하루되세요 > 고도산 님이 쓴 글입니다. > 제목 : 예트로 변환 부탁합니다 > 트레이딩뷰 소스를 예트로 변환 부탁합니다. 제가 시도했는데 box에서 막히네요. //@version=5 indicator("ZLMA Trend Levels [ChartPrime]", overlay = true) //-----------------------------------} // User Inputs //-----------------------------------{ int length = input.int(15, title="Length") // Length for the moving average calculations bool show_levl = input.bool(true, "Trend Levels") // Toggle to show trend levels // Colors for the trend levels color up = input.color(color.red, "+", group = "Colors", inline = "i") color dn = input.color(color.lime, "-", group = "Colors", inline = "i") var box1 = box(na) // Variable to store the box series float atr = ta.atr(200) // Average True Range (ATR) for trend levels //-----------------------------------} // Indicator Calcs //-----------------------------------{ series float emaValue = ta.ema(close, length) // EMA of the closing price series float correction = close + (close - emaValue) // Correction factor for zero-lag calculation series float zlma = ta.ema(correction, length) // Zero-Lag Moving Average (ZLMA) bool signalUp = ta.crossover(zlma, emaValue) // Signal for bullish crossover bool signalDn = ta.crossunder(zlma, emaValue) // Signal for bearish crossunder // Determine the color of ZLMA based on its direction color zlma_color = zlma > zlma[3] ? up : zlma < zlma[3] ? dn : na color ema_col = emaValue < zlma ? up : dn // Determine the EMA color //-----------------------------------} // Visualization //-----------------------------------{ // Plot the Zero-Lag Moving Average p1 = plot(zlma, color = zlma_color, linewidth = 1, title = 'zlma') // Plot ZLMA p2 = plot(emaValue, color = ema_col, linewidth = 1, title = 'emaValue') // Plot EMA fill(p1, p2, zlma, emaValue, color.new(zlma_color, 80), color.new(ema_col, 80)) // Fill between ZLMA and EMA // Method to draw a box on the chart method draw_box(color col, top, bot, price)=> box.new( bar_index, top, bar_index, bot, col, 1, bgcolor = color.new(col, 90), text = str.tostring(math.round(price, 2)), text_size = size.tiny, text_color = chart.fg_color, text_halign = text.align_right ) // Logic to draw trend levels as boxes on the chart if show_levl bool check_signals = signalUp or signalDn // Check if there is an up or down signal switch // Draw a box when a bullish signal is detected signalUp => box1 := up.draw_box(zlma, zlma - atr, close) // Draw a box when a bearish signal is detected signalDn => box1 := dn.draw_box(zlma + atr, zlma, close) switch // Extend the right side of the box if no new signal is detected not signalUp or not signalDn => box1.set_right(bar_index + 4) => box1 := box(na) // Otherwise, reset the box switch // Add a downward label when price crosses below the bottom of the box ta.crossunder(high, box1.get_bottom()) and not check_signals[1] and not check_signals and emaValue > zlma=> label.new(bar_index - 1, high[1], "▼", color = color(na), textcolor = dn, style = label.style_label_down) // Add an upward label when price crosses above the top of the box ta.crossover(low, box1.get_top()) and not check_signals and not check_signals[1] and emaValue < zlma=> label.new(bar_index - 1, low[1], "▲", color = color(na), textcolor = up, style = label.style_label_up) // Plot shapes for up and down signals plotshape(signalUp ? zlma : na, "sig up", shape.diamond, location.absolute, color = up, size = size.tiny) plotshape(signalDn ? zlma : na, "sig dn", shape.diamond, location.absolute, color = dn, size = size.tiny) //-----------------------------------}