답변완료
질문 부탁드립니다
추세선과 for 문 관련해서 부탁드립니다
첨부된 식 else 문에서
h>var25 인 경우가 하나도 없을 때 (ii==0)
tr[0] 추세선의 시작점, 끝점, 가격값을
기존 값에서 (기존값: sd[6],st[6],aa[6],sd[3],st[3],aa[3])
각각 +1 씩 변경한 식을 작성했는데요, (설명을 위한 예시로 작성한것 입니다)
ii==0 인 상태에서 추세선 위치를 변경했을때 ii >1 이 될때까지
시작점,시작값은 기존값 +2로,
끝점,끝값은 기존값 +1로 변경하는 수식을 작성하고자 합니다.
if문의 기존 추세선 값을 바꾸면 연동돼서 바뀌게 할 수 있을까요?
범위는 뒤로 3 회 까지(즉 3번째 변경 했을때의 시작점은 +6, 끝점은 +3) 로 부탁드립니다
(3회까지 했으나 ii>1 이 아니라면 원래값을 유지)
항상 감사드립니다
var : cnt(0), sum1(0), sumi1(0),summ(0),tt(0),hh(0),ll(0),tll(0),n(0),ae(0);
var: sum2(0),sumi2(0),count(0),sumaa(0),sumai(0),avgaa(0);
var : t(0),StartBarIndex(0),dd(0),d1(0),d2(0),e1(0),e2(0),ii(0);
Array : aa[50](0),cc[50](0),ee[50](0),txt[40](0),txt1[20](0),
tr[40](0),sd[45](0),st[45](0),ad[50](0),at[50](0);
if Bdate != Bdate[1] Then
{
DD = DD+1;
}
if (h>l*1.08) and (d1 == 0 or (d1 > 0 and dd >= d1+5)) Then
{
d1 = dd;
hh = h;
var1 = Index;
Var2 = var1[1];
Var3 = Var2[1];
sum1=0; sumi1=0; sum2=0; sumi2=0;
tll=TL_NEW(sDate,sTime,100,sDate,sTime,999999);
TL_SetSize(tll,0);
TL_SetColor(tll,Gray);
For cnt = 1 to (var1-Var2)
{
sum1=sum1+l[cnt];
sumi1=sumi1+1;
}
value1=sum1/sumi1;
For cnt = 49 DownTo 1
{
aa[cnt] = aa[cnt-1];sd[cnt] =sd[cnt-1];st[cnt] =st[cnt-1];
txt[cnt] = txt[cnt-1];
tr[cnt]=tr[cnt-1];
}
aa[0] = value1;
sd[0] = sDate;
st[0] = sTime;
TL_SetExtRight(tr[3],False);
tr[0] = TL_New(sd[6],st[6],aa[6],sd[3],st[3],aa[3]);TL_SetDrawMode(tr[0],0);
TL_Delete( tr[3]);
TL_SetExtRight( tr[0],true);
TL_SetColor(tr[0],DarkGreen); TL_SetColor(tr[4],Green);
TL_SetColor(tr[5],LightGreen);TL_SetSize( tr[0],1);
ii=0;
}
Else
{
Var25=TL_GetValue(tr[0],sDate,sTime);
if h>=Var25 then
{
ii=ii+1;
#plot24(ii,"test1",Orange,Def,1);
}
if ii==0 Then
{
TL_SetBegin(tr[0],sd[7],st[7],aa[7]);
TL_SetEnd(tr[0],sd[4],st[4],aa[4]);
}
}
2025-05-29
250
글번호 191262
지표
답변완료
수식질문
아래 수식1, 수식2, 수식3을
논리합(or)조건으로 결합하여 하나의 조건식으로 만들어 주시기 바랍니다
수식1.
var : A(0),value(0),Sum(0),ii(0),avgif(0),cnt(0), SumSqrt(0),Stdevif(0),B(0);
Array : diff[500](0);
A= ma(C,5);
value=C-A;
if IsNan(value) == False Then
{ if value < 0 Then {ii = ii + 1; diff[ii] = value; Sum = Sum + value; avgif = Sum/ii; }
if ii >= 1 Then {SumSqrt = 0;
For cnt = 1 To ii
{SumSqrt=SumSqrt+(diff[cnt]-avgif)^2;}
Stdevif=SquareRoot(SumSqrt/ii);
B=A+avgif-2*Stdevif;
if CrossDown(C,B) && C < O Then Find(1); }}
수식2.
var : A(0),value(0),Sum(0),ii(0),avgif(0),cnt(0), SumSqrt(0),Stdevif(0),B(0);
Array : diff[500](0);
A= ma(C,10);
value=C-A;
if IsNan(value) == False Then
{ if value < 0 Then {ii = ii + 1; diff[ii] = value; Sum = Sum + value; avgif = Sum/ii; }
if ii >= 1 Then {SumSqrt = 0;
For cnt = 1 To ii
{SumSqrt=SumSqrt+(diff[cnt]-avgif)^2;}
Stdevif=SquareRoot(SumSqrt/ii);
B=A+avgif-2*Stdevif;
if CrossDown(C,B) && C < O Then Find(1); }}
수식3.
var : A(0),value(0),Sum(0),ii(0),avgif(0),cnt(0), SumSqrt(0),Stdevif(0),B(0);
Array : diff[500](0);
A= ma(C,20);
value=C-A;
if IsNan(value) == False Then
{ if value < 0 Then {ii = ii + 1; diff[ii] = value; Sum = Sum + value; avgif = Sum/ii; }
if ii >= 1 Then {SumSqrt = 0;
For cnt = 1 To ii
{SumSqrt=SumSqrt+(diff[cnt]-avgif)^2;}
Stdevif=SquareRoot(SumSqrt/ii);
B=A+avgif-2*Stdevif;
if CrossDown(C,B) Then Find(1); }}
2025-05-29
253
글번호 191261
종목검색
답변완료
감사합니다 지표 변환 부탁드립니다
// Settings
//---------------------------------------------------------------------------------------------------------------------{
sp='         '
res = input.timeframe ( '' , 'Period        ' )
i1 = input.bool ( true , '' , inline='1', group='Swing Length')
i2 = input.bool ( true , '' , inline='2', group='Swing Length')
i3 = input.bool ( true , '' , inline='3', group='Swing Length')
l1 = input.int (60, 'Long     ', minval=1, inline='1', group='Swing Length')
l2 = input.int (30, 'Medium' , minval=1, inline='2', group='Swing Length')
l3 = input.int (10, 'Short    ', minval=1, inline='3', group='Swing Length')
cBull = input.color (#089981, 'Trendline'+sp, inline='d', group='Style' )
cBear = input.color (#f23645, '' , inline='d', group='Style'
, tooltip = 'Bullish/Bearish Trendline' )
cWickBull = input.color (#085def, 'Wick Dot' +sp, inline='w', group='Style' )
cWickBear = input.color (#ff5d00, '' , inline='w', group='Style'
, tooltip = 'Bullish/Bearish Wick' )
term = input.string('Long' , 'Term'
, options =['Long' , 'Medium', 'Short' ] )
HHLL = input.string('None' , 'HH/LL'
, options =['None','Only HH/LL','HH/LL & previous H/L'])
bg = input.bool ( false , 'Background Color' )
cc = input.bool ( false , 'Bar Color' )
//---------------------------------------------------------------------------------------------------------------------}
//LuxAlgo Defined Type
//---------------------------------------------------------------------------------------------------------------------{
type bin
line lin
float slope
bool active
chart.point cp
//---------------------------------------------------------------------------------------------------------------------}
//Variables
//---------------------------------------------------------------------------------------------------------------------{
lbi = last_bar_index
n = bar_index
INV = color(na)
//---------------------------------------------------------------------------------------------------------------------}
//Function
//---------------------------------------------------------------------------------------------------------------------{
draw(toggle, res, left, right, pos) =>
ps = term == 'Long' ? 1 : term == 'Medium' ? 2 : 3
var int trend = 0
var chart.point prevPh = chart.point.from_index(na, na)
var chart.point prevPl = chart.point.from_index(na, na)
var bn = bin.new(line(na), 0, false)
ph_ = ta.pivothigh(left, right), [tH, ph] = request.security(syminfo.tickerid, res, [time[2], ph_])
pl_ = ta.pivotlow (left, right), [tL, pl] = request.security(syminfo.tickerid, res, [time[2], pl_])
cH = ta.change(fixnan(ph))
cL = ta.change(fixnan(pl))
chH = cH != 0 and cL == 0
chL = cL != 0 and cH == 0
if toggle
if bn.active
if bn.lin.get_x2() - bn.lin.get_x1() > 5000
bn.active := false
bn.lin.delete()
else
bn.lin.set_xy2(n, bn.lin.get_y2() + bn.slope)
if chH
v = 0.
idx = 0
for i = 0 to 5000
Ti = time[i]
if high[i] > v
v := high[i]
idx := i
if Ti < tH
break
x = n - idx
c = close[idx]
if trend < 1
//HH
if v > prevPh.price and x - prevPh.index > 5 and n - prevPl.index < 5000
if pos == ps and HHLL != 'None'
label.new(x, v, color=color(na), text='HH₩n', size=size.tiny, textcolor=chart.fg_color)
if HHLL == 'HH/LL & previous H/L'
label.new(prevPh.index, prevPh.price, color=color(na), size=size.tiny, text='●', textcolor=chart.fg_color)
trend := 1
bn := bin.new(line.new(prevPl.index, prevPl.price, n, prevPl.price, color=cBull
, style= pos == 1 ? line.style_solid : pos == 2 ? line.style_dashed : line.style_dotted, width=pos == 1 ? 2 : 1)
, 0, true, chart.point.from_index(prevPl.index, prevPl.price))
else
//if bearish TL
if bn.active
slope = (v - bn.cp.price) / (x - bn.cp.index)
//if line direction is down and wick breaks line or first LH
if v < bn.lin.get_y1() + slope and (v > bn.lin.get_y2() + slope or bn.slope == 0)
priceLin = bn.lin.get_price(n-idx)
if c < priceLin
//where wick breaks last line price
if bn.slope != 0
label.new(n-idx, priceLin, style=label.style_label_center, text='●', color=color(na), textcolor=cWickBear)
//First 업데이트 line
bn.lin.set_xy2(n, v + slope*idx)
//if first Swing after line conception
if bn.slope == 0
//repeat until all close prices are below the line
stop = false
while not stop
arr = array.new<float>()
//check for inner-line breaks with close
for i = 0 to n - bn.lin.get_x1()
arr.push(close[i] - bn.lin.get_price(n-i))
highest_point = arr.max()
//if yes, 업데이트 first point to highest point
if highest_point > 0
ix = arr.indexof(highest_point)
x1 = n-ix, y1 = high[ix]
//label.new(x1, y1)
bn.cp.index := x1
bn.cp.price := y1
slope := (v - y1) / (x - x1)
bn.lin.set_xy2(n, v + slope*idx)
bn.lin.set_xy1(x1, y1)
bn.slope := slope
else
bn.lin.set_xy2(n, v + slope*idx)
bn.slope := slope
stop := true
else
bn.slope := slope
else
//if close price at Swing point breaks line
bn.active := false
prevPh.index := x
prevPh.price := v
else
if trend < 1
if close > bn.lin.get_y2()
bn.active := false
if chL
v = 10e6
idx = 0
for i = 0 to 5000
Ti = time[i]
if low[i] < v
v := low[i]
idx := i
if Ti < tL
break
x = n - idx
c = close[idx]
if trend >-1
//LL
if v < prevPl.price and x - prevPl.index > 5 and n - prevPh.index < 5000
if pos == ps and HHLL != 'None'
label.new(x, v, color=color(na), text='₩nLL', size=size.tiny, textcolor=chart.fg_color, style=label.style_label_up)
if HHLL == 'HH/LL & previous H/L'
label.new(prevPl.index, prevPl.price, color=color(na), size=size.tiny, text='●', textcolor=chart.fg_color, style=label.style_label_up)
trend :=-1
bn := bin.new(line.new(prevPh.index, prevPh.price, n, prevPh.price, color=cBear
, style= pos == 1 ? line.style_solid : pos == 2 ? line.style_dashed : line.style_dotted, width=pos == 1 ? 2 : 1)
, 0, true, chart.point.from_index(prevPh.index, prevPh.price))
else
//if bullish TL
if bn.active
slope = (v - bn.cp.price) / (x - bn.cp.index)
//if line direction is up and wick breaks line or first HL
if v > bn.lin.get_y1() + slope and (v < bn.lin.get_y2() + slope or bn.slope == 0)
priceLin = bn.lin.get_price(n-idx)
if c > priceLin
//where wick breaks last line price
if bn.slope != 0
label.new(n-idx, priceLin, style=label.style_label_center, text='●', color=color(na), textcolor=cWickBull)
//First 업데이트 line
bn.lin.set_xy2(n, v + slope*idx)
//if first Swing after line conception
if bn.slope == 0
//repeat until all close prices are above the line
stop = false
while not stop
arr = array.new<float>()
//check for inner-line breaks with close
for i = 0 to n - bn.lin.get_x1()
arr.push(bn.lin.get_price(n-i)-close[i])
deepest_point = arr.max()
//if yes, 업데이트 first point to deepest point
if deepest_point > 0
ix = arr.indexof(deepest_point)
x1 = n-ix, y1 = low[ix]
bn.cp.index := x1
bn.cp.price := y1
slope := (v - y1) / (x - x1)
bn.lin.set_xy2(n, v + slope*idx)
bn.lin.set_xy1(x1, y1)
bn.slope := slope
else
bn.lin.set_xy2(n, v + slope*idx)
bn.slope := slope
stop := true
else
bn.slope := slope
else
//if close price at Swing point breaks line
bn.active := false
prevPl.index := x
prevPl.price := v
else
if trend >-1
if close < bn.lin.get_y2()
bn.active := false
[trend, bn.lin.get_y2()]
//---------------------------------------------------------------------------------------------------------------------}
//실행
//---------------------------------------------------------------------------------------------------------------------{
[trend1, value1] = draw(i1, res, l1, 1, 1)
[trend2, value2] = draw(i2, res, l2, 1, 2)
[trend3, value3] = draw(i3, res, l3, 1, 3)
col = color(na)
if cc
col := switch close > value1
true =>
switch close > value2
true =>
if close > value3
color.new(cBull, 20)
else
color.new(cBull, 43)
=>
if close > value3
color.new(cBull, 66)
else
color.new(cBull, 89)
=>
switch close < value2
true =>
if close < value3
color.new(cBear, 20)
else
color.new(cBear, 43)
=>
if close < value3
color.new(cBear, 66)
else
color.new(cBear, 89)
//---------------------------------------------------------------------------------------------------------------------}
//Plot - Bar/Background Color
//---------------------------------------------------------------------------------------------------------------------{
plot(value1, display=display.none)
plot(value2, display=display.none)
plot(value3, display=display.none)
plot(trend1, display=display.none)
barcolor(cc ? col : na)
//Background color - close above/below value1-2-3
isValid = bg and (term == 'Long' ? i1 : term == 'Medium' ? i2 : i3)
bgcolor(isValid ? color.new(close > (term == 'Long' ? value1 : term == 'Medium' ? value2 : value3) ? cBull : cBear, 97) : na)
2025-05-28
310
글번호 191259
지표