예스스탁
예스스탁 답변
2024-10-25 10:50:33
안녕하세요
예스스탁입니다.
선사이의 색채우기는 수식에서 설정이 가능하지 않습니다.
지표속성창의 차트표시탭에서 채우기 기능이용하셔서 직접 설정하셔야 합니다.
input : len(10);
input : offset(30);
input : width(1);
var : dsl_up(0),dsl_dn(0),sma(0),threshold_up(0),threshold_dn(0);
var : A(0),dsl_up1(0),dsl_dn1(0),lr(0),trend_col(0);
sma = ma(close, len);
threshold_up = highest(H,len)[offset];
threshold_dn = lowest(L,len)[offset];
dsl_up = iff(close > threshold_up , sma , dsl_up[1]);
dsl_dn = iff(close < threshold_dn , sma , dsl_dn[1]);
A = atr(200) * width;
dsl_up1 = dsl_up - A;
dsl_dn1 = dsl_dn + A;
lr = LRL(close, 5);
if high > dsl_up1 and high < dsl_up and high > dsl_dn1 Then
trend_col = Magenta;
if low > dsl_dn and low < dsl_dn1 Then
trend_col = Cyan;
if high > dsl_up Then
trend_col = Red;
if low < dsl_dn Then
trend_col = Blue;
plot1(lr,"Trend Line",trend_col);
plot2(dsl_up, "DSL Up",Gray);
plot3(dsl_dn, "DSL Down",Gray);
plot4(dsl_up1, "DSL Upper Band",Gray);
plot5(dsl_dn1, "DSL Lower Band",Gray);
즐거운 하루되세요
> 비듬싸순 님이 쓴 글입니다.
> 제목 : 수고하십니다
> 항상노고에 감사드리며 트레이딩뷰챠트인데 변환 부탁드립니다
주말 잘보내세요
/@version=5
indicator("DSL Trend Analysis [ChartPrime]", overlay = true)
// --------------------------------------------------------------------------------------------------------------------}
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
// --------------------------------------------------------------------------------------------------------------------{
int len = input.int(10, "Length") // Length for calculating DSL
int offset = input(30, "Offset") // Offset for threshold levels
float width = input.float(1, "Bands Width", step = 0.1, maxval = 2, minval = 0.5) // Width for ATR-based bands
// Colors for upper and lower trends
color upper_col = input.color(color.lime, "+", inline = "col")
color lower_col = input.color(color.orange, "-", inline = "col")
// --------------------------------------------------------------------------------------------------------------------}
// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
// --------------------------------------------------------------------------------------------------------------------{
// Function to calculate DSL lines based on price
dsl_price(float price, int len) =>
// Initialize DSL lines as NaN (not plotted by default)
float dsl_up = na
float dsl_dn = na
float sma = ta.sma(price, len)
// Dynamic upper and lower thresholds calculated with offset
float threshold_up = ta.highest(len)[offset]
float threshold_dn = ta.lowest(len)[offset]
// Calculate the DSL upper and lower lines based on price compared to the thresholds
dsl_up := price > threshold_up ? sma : dsl_up[1]
dsl_dn := price < threshold_dn ? sma : dsl_dn[1]
// Return both DSL lines
[dsl_up, dsl_dn]
// Function to calculate DSL bands based on ATR and width multiplier
dsl_bands(float dsl_up, float dsl_dn) =>
float atr = ta.atr(200) * width // ATR-based calculation for bands
float upper = dsl_up - atr // Upper DSL band
float lower = dsl_dn + atr // Lower DSL band
[upper, lower]
// Get DSL values based on the closing price
[dsl_up, dsl_dn] = dsl_price(close, len)
// Calculate the bands around the DSL lines
[dsl_up1, dsl_dn1] = dsl_bands(dsl_up, dsl_dn)
// Linear regression on the close price over a short period
float linreg = ta.linreg(close, 5, 0)
// Determine the trend color based on the relationship between price, DSL lines, and bands
color trend_col =
high > dsl_up1 and high < dsl_up and high > dsl_dn1
? color.new(upper_col, 60)
: low > dsl_dn and low < dsl_dn1
? color.new(lower_col, 60)
: high > dsl_up
? upper_col
: low < dsl_dn
? lower_col
: na
// --------------------------------------------------------------------------------------------------------------------}
// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
// --------------------------------------------------------------------------------------------------------------------{
// Plot the linear regression with color based on trend analysis
plot(linreg, "Trend Line", color = trend_col, linewidth=4, style = plot.style_linebr, force_overlay = false)
// If it's the last bar, display labels for the DSL upper and lower bands
if barstate.islast
label.delete(label.new(bar_index + 5, dsl_up, "Upper Band₩n" + str.tostring(dsl_up, "#.##"), style = label.style_label_left, color = color(na), textcolor = chart.fg_color)[1])
label.delete(label.new(bar_index + 5, dsl_dn, "Lower Band₩n" + str.tostring(dsl_dn, "#.##"), style = label.style_label_left, color = color(na), textcolor = chart.fg_color)[1])
// Plot the DSL lines on the chart
pu = plot(dsl_up, color=color.gray, linewidth=1, title="DSL Up")
pd = plot(dsl_dn, color=color.gray, linewidth=1, title="DSL Down")
// Plot the DSL bands
pu1 = plot(dsl_up1, color=color.gray, linewidth=1, title="DSL Upper Band")
pd1 = plot(dsl_dn1, color=color.gray, linewidth=1, title="DSL Lower Band")
// Fill the space between the DSL lines and bands with color
fill(pu, pu1, dsl_up, dsl_up1, color.new(upper_col, 80), color.new(upper_col, 90))
fill(pd, pd1, dsl_dn, dsl_dn1, color.new(lower_col, 80), color.new(lower_col, 90))
// Uncomment the following line to plot candles with trend color
// plotcandle(open, high, low, close, title='Title', color = trend_col, wickcolor=trend_col, bordercolor = trend_col)
// --------------------------------------------------------------------------------------------------------------------}