예스스탁
예스스탁 답변
2024-10-28 09:14:42
안녕하세요
예스스탁입니다.
input : length(15);
input : show_levl(true);
var : up(0),dn(0),A(0),emaValue(0),correction(0),zlma(0);
var : signalUp(False),signalDn(False),zlma_color(0),ema_col(0);
var : TOP(0),BTM(0),box(0),tx(0),tx1(0),check_signals(False);
up = Green;
dn = Blue;
#var box1 = box(na) // Variable to store the box
a = atr(200);
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); // Plot ZLMA
plot2(emaValue,"EMA",ema_col);
if signalUp Then
{
Top = zlma;
BTM = zlma-A;
box = box_new(sDate,sTime,Top,NextBarSdate,NextBarStime,BTM);
Box_SetColor(box,up);
Box_SetFill(box,true);
var3 = (Top+BTM)/2;
tx = Text_New(NextBarSdate,NextBarStime,var3,NumToStr(C,2));
Text_SetStyle(tx,1,2);
}
else if signalDn Then
{
Top = zlma+A;
BTM = zlma;
box = box_new(sDate,sTime,Top,NextBarSdate,NextBarStime,BTM);
Box_SetColor(box,dn);
Box_SetFill(box,true);
var3 = (Top+BTM)/2;
tx = Text_New(NextBarSdate,NextBarStime,var3,NumToStr(C,2));
Text_SetStyle(tx,1,2);
}
Else
{
Box_SetEnd(box,sDate,sTime,BTM);
Text_SetLocation(tx,sDate,sTime,var3);
}
check_signals = signalUp or signalDn;
if CrossDown(high, BTM) and emaValue > zlma Then
{
tx1 = Text_New(sDate[1],sTime[1],H[1],"▼");
Text_SetStyle(tx1,2,1);
Text_SetColor(tx1,dn);
}
if CrossUp(low, Top) and emaValue < zlma Then
{
tx1 = Text_New(sDate[1],sTime[1],L[1],"▲");
Text_SetStyle(tx1,2,0);
Text_SetColor(tx1,up);
}
즐거운 하루되세요
> 유경완 님이 쓴 글입니다.
> 제목 : 트레이딩뷰 사용중인 Zero-Lag MA Trend Levels 수정요망
> 항상 감사드립니다..
트레이딩뷰 사이트에서 제공하여 사용중인 아래의 수식을 예스스탁에서 사용할수 있도록 수식을 부탁 드립니다.
indicator("Zero-Lag MA Trend Levels [ChartPrime]", overlay = true)
// --------------------------------------------------------------------------------------------------------------------}
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
// --------------------------------------------------------------------------------------------------------------------{
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(#30d453, "+", group = "Colors", inline = "i")
color dn = input.color(#4043f1, "-", 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
// --------------------------------------------------------------------------------------------------------------------}
// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
// --------------------------------------------------------------------------------------------------------------------{
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
// --------------------------------------------------------------------------------------------------------------------}
// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
// --------------------------------------------------------------------------------------------------------------------{
// Plot the Zero-Lag Moving Average
p1 = plot(zlma, color = zlma_color, linewidth = 1) // Plot ZLMA
p2 = plot(emaValue, color = ema_col, linewidth = 1) // 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, "", shape.diamond, location.absolute, color = up, size = size.tiny)
plotshape(signalDn ? zlma : na, "", shape.diamond, location.absolute, color = dn, size = size.tiny)
// --------------------------------------------------------------------------------------------------------------------}