답변완료
지표 변환 부탁드립니다.
// This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © BigBeluga
//@version=6
indicator("Two-Pole Oscillator [BigBeluga]", max_labels_count = 500, max_lines_count = 500)
// INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
int length = input.int(20, minval=1, title="Filter Length")
bool disp_lvl = input.bool(true, "Levels")
color up_color = input.color(#55ffda, "", inline = "color")
color dn_color = input.color(#8c5bff, "", inline = "color")
var buy_line = line(na)
var sell_line = line(na)
// }
// CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
float sma1 = ta.sma(close, 25)
float sma_n1 = ((close - sma1) - ta.sma(close - sma1, 25)) / ta.stdev(close - sma1, 25)
float area = ta.sma(high-low, 100)
// Two-pole smooth filter function
f_two_pole_filter(source, length) =>
var float smooth1 = na
var float smooth2 = na
alpha = 2.0 / (length + 1)
if na(smooth1)
smooth1 := source
else
smooth1 := (1 - alpha) * smooth1 + alpha * source
if na(smooth2)
smooth2 := smooth1
else
smooth2 := (1 - alpha) * smooth2 + alpha * smooth1
// Oscillator
two_p = f_two_pole_filter(sma_n1, length)
two_pp = two_p[4]
// Colors
color buy_col1 = color.from_gradient(two_p, -1, 0.5, up_color, na)
color buy_col2 = color.from_gradient(two_p, -1, 0.5, color.new(up_color, 50), na)
color sell_col1 = color.from_gradient(two_p, -0.5, 1, na, dn_color)
color sell_col2 = color.from_gradient(two_p, -0.5, 1, na, color.new(dn_color, 50))
color color = two_p > two_pp
? color.from_gradient(two_p, -1,1, up_color, color.new(up_color, 0))
: color.from_gradient(two_p, -1,1,color.new(dn_color, 0), dn_color)
// Signals
bool buy = ta.crossover(two_p, two_pp) and two_p < 0 and barstate.isconfirmed
bool sell = ta.crossunder(two_p, two_pp) and two_p > 0 and barstate.isconfirmed
// }
// PLOT ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
if buy //and two_p < -0.5
sell_line := line(na)
if disp_lvl
buy_line := line.new(
bar_index-1
, low[1] - area
, bar_index
, low[1] - area
, force_overlay = true
, color = buy_col1
, style = line.style_dashed
)
label.new(bar_index-1, low[1] - area
, color = buy_col1, style = label.style_label_up, force_overlay = true, size = size.tiny)
if ta.crossunder(low, buy_line.get_y1()) and barstate.isconfirmed
label.new(
bar_index-1
, buy_line.get_y1()
, color = color.new(up_color, 100)
, style = label.style_label_center
, force_overlay = true
, size = size.large
, text = "✖"
, textcolor = up_color
)
buy_line := line(na)
if sell //and two_p > 0.5
buy_line := line(na)
if disp_lvl
sell_line := line.new(
bar_index-1
, high[1] + area
, bar_index
, high[1] + area
, force_overlay = true
, color = sell_col1
, style = line.style_dashed
)
label.new(bar_index-1, high[1] + area
, color = sell_col1, style = label.style_label_down, force_overlay = true, size = size.tiny)
if ta.crossover(high, sell_line.get_y1()) and barstate.isconfirmed
label.new(
bar_index-1
, sell_line.get_y1()
, color = color.new(dn_color, 100)
, style = label.style_label_center
, force_overlay = true
, size = size.large
, text = "✖"
, textcolor = dn_color
)
sell_line := line(na)
switch
not na(buy_line) => buy_line. set_x2(bar_index)
not na(sell_line) => sell_line.set_x2(bar_index)
plotshape(buy ? two_p[1] : na, "Buy", shape.circle, location.absolute, buy_col2, -1, size = size.small)
plotshape(buy ? two_p[1] : na, "Buy", shape.circle, location.absolute, buy_col1, -1, size = size.tiny)
plotshape(sell ? two_p[1] : na, "Sell", shape.circle, location.absolute, sell_col2, -1, size = size.small)
plotshape(sell ? two_p[1] : na, "Sell", shape.circle, location.absolute, sell_col1, -1, size = size.tiny)
p11 = plot(1, color = color.new(chart.fg_color, 80))
plot(0.5, color = color.new(chart.fg_color, 50))
p00 = plot(0, color = color.new(bar_index % 2 == 0 ? chart.fg_color : na, 0))
plot(-0.5, color = color.new(chart.fg_color, 50))
p_1 = plot(-1, color = color.new(chart.fg_color, 80))
fill(p11, p00, 2, -1, color.new(chart.fg_color, 80), na)
fill(p_1, p00, 1, -2, na, color.new(chart.fg_color, 80))
p1 = plot(two_p, color = color, linewidth = 1)
p2 = plot(two_pp, display = display.none)
fill(p1, p2, two_p, two_pp, color, na)
// }
2025-03-21
417
글번호 189393
지표
답변완료
수식 요청합니다
아래 그림과 수식은 예스스탁에서 변환해준 식입니다. 점선부분 2부분을 실선으로 plot하도록 부탁드립니다.
아울러
검색에서 두 부분을 돌파하는 조건을 만들려고 합니다.
input : lookback(72);
input : multiplier(1);
input : high_col(red);
input : low_col(lime);
var : hest(0),lest(0);
var : alpha(0),source(0),ATRV(0),A(0);
var : high_i(Nan),high_D(Nan),high_T(Nan),high_V(Nan);
VAR : low_i(Nan),low_D(Nan),low_T(Nan),low_V(Nan);
hest = highest(H,lookback);
lest = lowest(L,lookback);
alpha = 1 / 200 ;
source = TrueRange;
ATrV = IFf(IsNan(ATrV[1]) == true, ma(source,200) , alpha * source + (1 - alpha) * IFf(isnan(ATrV[1])==true,0,ATrV[1]));
A = ATRV*multiplier;
if high[1] == hest[1] and high < hest Then
{
high_i = Index-1;
high_d = sDate[1];
high_t = sTime[1];
high_v = high[1];
}
if low[1] == lest[1] and low > lest Then
{
low_i = Index-1;
low_v = low[1];
}
var : size(0),mid(0),mid_index(0),i(0),idx(0);
var : hTL1(0),hTL2(0),hTX(0);
var : lTL1(0),lTL2(0),lTX(0);
var : mTL(0),mTX(0);
size = index - IFf(high_i > low_i , low_i , high_i);
TL_Delete(hTL1);
TL_Delete(hTL2);
Text_Delete(hTX);
hTL1 = TL_New(sDate[Index-high_i],sTime[Index-high_i],high_v,NextBarSdate,NextBarStime,high_v);
TL_SetColor(hTL1,high_col);
TL_SetSize(hTL1,2);
hTL2 = TL_New(sDate[(Index-high_i)-3],sTime[(Index-high_i)-3],high_v-A,NextBarSdate,NextBarStime,high_v-A);
TL_SetColor(hTL2,high_col);
TL_SetSize(hTL2,0);
TL_SetStyle(hTL2,3);
hTX = Text_New(NextBarSdate,NextBarStime,high_v,ntostr(high_v,2));
Text_SetColor(hTX,high_col);
Text_SetStyle(hTX,0,2);
TL_Delete(lTL1);
TL_Delete(lTL2);
Text_Delete(lTX);
lTL1 = TL_New(sDate[Index-Low_i],sTime[Index-Low_i],Low_v,NextBarSdate,NextBarStime,Low_v);
TL_SetColor(lTL1,Low_col);
TL_SetSize(lTL1,2);
lTL2 = TL_New(sDate[(Index-low_i)-3],sTime[(Index-low_i)-3],low_v+A,NextBarSdate,NextBarStime,low_v+A);
TL_SetColor(lTL2,Low_col);
TL_SetSize(lTL2,0);
TL_SetStyle(lTL2,3);
lTX = Text_New(NextBarSdate,NextBarStime,low_v,ntostr(low_v,2));
Text_SetColor(lTX,low_col);
Text_SetStyle(lTX,0,2);
mid = avg(high_v, low_v);
mid_index = size/2;
TL_Delete(mTL);
Text_Delete(mTX);
mTL = TL_New(sDate[mid_index],sTime[mid_index],mid,NextBarSdate,NextBarStime,mid);
TL_SetColor(mTL,Black);
TL_SetSize(mTL,0);
TL_SetStyle(mTL,3);
mTX = Text_New(NextBarSdate,NextBarStime,mid,ntostr(mid,2));
Text_SetColor(mTX,Black);
Text_SetStyle(mTX,0,2);
2025-03-20
367
글번호 189380
지표