커뮤니티

부탁드립니다

프로필 이미지
트레트레
2024-12-03 15:13:09
601
글번호 185906
답변완료
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // &#169; danilogalisteu //@version=5 indicator("Darvas box", overlay=true) show_labels = input.bool(false, "Show labels for box top and bottom") // Reference: https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/C-D/DarvasBox // Logic changed to transition to state 5 after one higher low only box_state = 1 high_value = high low_value = ta.lowest(4) if box_state[1] == 1 and high < high_value[1] box_state := 2 high_value := high_value[1] if box_state[1] == 2 and high < high_value[1] box_state := 3 high_value := high_value[1] if box_state[1] == 3 and high < high_value[1] if low > low_value[1] box_state := 5 low_value := low_value[1] else box_state := 4 high_value := high_value[1] if box_state[1] == 4 and high < high_value[1] if low > low_value[1] box_state := 5 low_value := low_value[1] else box_state := 4 high_value := high_value[1] if box_state[1] == 5 and high <= high_value[1] and low >= low_value[1] box_state := 5 high_value := high_value[1] low_value := low_value[1] draw_box(left, top, right, bottom, color) => box = box.new(left, top, right, bottom) box.set_border_color(box, color) box.set_bgcolor(box, color.rgb(color.r(color), color.g(color), color.b(color), 95)) box // draw and redraw box state_active = 5 box_active = box_state == state_active box_start = ta.barssince(box_state == 1) b = box(na) l_up = label(na) l_dn = label(na) end_box = false end_box_dir = 0 box_color = color.yellow if box_active if box_active[1] box.delete(b[1]) if show_labels label.delete(l_up[1]) label.delete(l_dn[1]) b := draw_box(bar_index-box_start, high_value, bar_index, low_value, box_color) if show_labels l_up := label.new(bar_index-2, high_value[1], str.tostring(high_value[1]), yloc=yloc.price, color=color.green, style=label.style_label_down) l_dn := label.new(bar_index-2, low_value[1], str.tostring(low_value[1]), yloc=yloc.price, color=color.red, style=label.style_label_up) else if box_active[1] end_box := true end_box_dir := high > box.get_top(b[1]) ? 1 : low < box.get_bottom(b[1]) ? -1 : 0 box_color := end_box_dir == 1 ? color.green : end_box_dir == -1 ? color.red : color.yellow box.set_border_color(b[1], box_color) box.set_bgcolor(b[1], color.rgb(color.r(box_color), color.g(box_color), color.b(box_color), 95)) box_break_up = end_box_dir == 1 box_break_dn = end_box_dir == -1 // show values as soon as box is active plot(box_active ? high_value : na, "Box top", style=plot.style_linebr, color=color.green, display=display.all-display.pane) plot(box_active ? low_value : na, "Box bottom", style=plot.style_linebr, color=color.red, display=display.all-display.pane) // show arrows for breakout / breakdown plotshape(box_break_up ? high_value[1]+0.1*(high_value-low_value)[1] : na, style=shape.arrowup, color=color.green, offset=-1, location=location.absolute, display=display.pane) plotshape(box_break_dn ? low_value[1]-0.1*(high_value-low_value)[1] : na, style=shape.arrowdown, color=color.red, offset=-1, location=location.absolute, display=display.pane) // alerts alertcondition(end_box, title='DB break', message='Darvas box break!') alertcondition(box_break_up, title='DB breakout', message='Darvas box breakout!') alertcondition(box_break_dn, title='DB breakdown', message='Darvas box breakdown!') 트레이딩뷰 지표인데 예스랭귀지로 변환 가능할까요? 화살표는 없어도 될 것 같습니다 매번 감사드립니다!
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2024-12-04 09:05:26

안녕하세요 예스스탁입니다. input : show_labels(1); #1출력,0:출력안함 input : 텍스트소수점자리수(2); var : box_state(0),high_value(0),low_value(0),state_active(0),box_active(False); var : box_start(-1); box_state = 1; high_value = high; low_value = lowest(L,4); if box_state[1] == 1 and high < high_value[1] Then { box_state = 2; high_value = high_value[1]; } if box_state[1] == 2 and high < high_value[1] Then { box_state = 3; high_value = high_value[1]; } if box_state[1] == 3 and high < high_value[1] Then { if low > low_value[1] Then { box_state = 5; low_value = low_value[1]; } else box_state = 4; high_value = high_value[1]; } if box_state[1] == 4 and high < high_value[1] Then { if low > low_value[1] Then { box_state = 5; low_value = low_value[1]; } else box_state = 4; high_value = high_value[1]; } if box_state[1] == 5 and high <= high_value[1] and low >= low_value[1] Then { box_state = 5; high_value = high_value[1]; low_value = low_value[1]; } /*draw_box(left, top, right, bottom, color) => box = box.new(left, top, right, bottom) box.set_border_color(box, color) box.set_bgcolor(box, color.rgb(color.r(color), color.g(color), color.b(color), 95)) box */ // draw and redraw box state_active = 5; box_active = box_state == state_active; if box_state == 1 Then box_start = 0; Else { if box_start >= 0 Then box_start = box_start+1; } var : b(0),l_up(0),l_dn(0),end_box(False),end_box_dir(0),box_color(0); b = Nan; l_up = Nan; l_dn = Nan; end_box = false; end_box_dir = 0; box_color = Black; if box_active Then { if box_active[1] == 1 Then { Box_Delete(b[1]); if show_labels Then { text_delete(l_up[1]); text_delete(l_dn[1]); } } b = box_new(sDate[box_start],sTime[box_start],high_value,sDate,sTime,low_value); Box_SetColor(b, box_color); Box_SetFill(b,true); if show_labels == 1 Then { l_up = text_new(sdate[2],sTime[2], high_value[1], NToStr(high_value[1],텍스트소수점자리수)); Text_SetColor(l_up,Green); Text_SetStyle(l_up,2,1); l_dn = text_new(sdate[2],stime[2], low_value[1], NToStr(low_value[1],텍스트소수점자리수)); Text_SetColor(l_dn,Red); Text_SetStyle(l_dn,2,0); } } else if box_active[1] Then { end_box = true; end_box_dir = iff(high > high_value[1] , 1 ,IFf( low < low_value[1],-1 , 0)); box_color = iff(end_box_dir == 1 , green , IFf(end_box_dir == -1 , red , yellow)); Box_SetColor(b[1],box_color); } 즐거운 하루되세요 > 트레트레 님이 쓴 글입니다. > 제목 : 부탁드립니다 > // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // &#169; danilogalisteu //@version=5 indicator("Darvas box", overlay=true) show_labels = input.bool(false, "Show labels for box top and bottom") // Reference: https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/C-D/DarvasBox // Logic changed to transition to state 5 after one higher low only box_state = 1 high_value = high low_value = ta.lowest(4) if box_state[1] == 1 and high < high_value[1] box_state := 2 high_value := high_value[1] if box_state[1] == 2 and high < high_value[1] box_state := 3 high_value := high_value[1] if box_state[1] == 3 and high < high_value[1] if low > low_value[1] box_state := 5 low_value := low_value[1] else box_state := 4 high_value := high_value[1] if box_state[1] == 4 and high < high_value[1] if low > low_value[1] box_state := 5 low_value := low_value[1] else box_state := 4 high_value := high_value[1] if box_state[1] == 5 and high <= high_value[1] and low >= low_value[1] box_state := 5 high_value := high_value[1] low_value := low_value[1] draw_box(left, top, right, bottom, color) => box = box.new(left, top, right, bottom) box.set_border_color(box, color) box.set_bgcolor(box, color.rgb(color.r(color), color.g(color), color.b(color), 95)) box // draw and redraw box state_active = 5 box_active = box_state == state_active box_start = ta.barssince(box_state == 1) b = box(na) l_up = label(na) l_dn = label(na) end_box = false end_box_dir = 0 box_color = color.yellow if box_active if box_active[1] box.delete(b[1]) if show_labels label.delete(l_up[1]) label.delete(l_dn[1]) b := draw_box(bar_index-box_start, high_value, bar_index, low_value, box_color) if show_labels l_up := label.new(bar_index-2, high_value[1], str.tostring(high_value[1]), yloc=yloc.price, color=color.green, style=label.style_label_down) l_dn := label.new(bar_index-2, low_value[1], str.tostring(low_value[1]), yloc=yloc.price, color=color.red, style=label.style_label_up) else if box_active[1] end_box := true end_box_dir := high > box.get_top(b[1]) ? 1 : low < box.get_bottom(b[1]) ? -1 : 0 box_color := end_box_dir == 1 ? color.green : end_box_dir == -1 ? color.red : color.yellow box.set_border_color(b[1], box_color) box.set_bgcolor(b[1], color.rgb(color.r(box_color), color.g(box_color), color.b(box_color), 95)) box_break_up = end_box_dir == 1 box_break_dn = end_box_dir == -1 // show values as soon as box is active plot(box_active ? high_value : na, "Box top", style=plot.style_linebr, color=color.green, display=display.all-display.pane) plot(box_active ? low_value : na, "Box bottom", style=plot.style_linebr, color=color.red, display=display.all-display.pane) // show arrows for breakout / breakdown plotshape(box_break_up ? high_value[1]+0.1*(high_value-low_value)[1] : na, style=shape.arrowup, color=color.green, offset=-1, location=location.absolute, display=display.pane) plotshape(box_break_dn ? low_value[1]-0.1*(high_value-low_value)[1] : na, style=shape.arrowdown, color=color.red, offset=-1, location=location.absolute, display=display.pane) // alerts alertcondition(end_box, title='DB break', message='Darvas box break!') alertcondition(box_break_up, title='DB breakout', message='Darvas box breakout!') alertcondition(box_break_dn, title='DB breakdown', message='Darvas box breakdown!') 트레이딩뷰 지표인데 예스랭귀지로 변환 가능할까요? 화살표는 없어도 될 것 같습니다 매번 감사드립니다!