// === Swing High and Low Detection === var float swing_high = na var float swing_low = na
if bar_index > input_length if swingHigh(input_length) swing_high := high if swingLow(input_length) swing_low := low
// === Entry Conditions === long_condition = not na(swing_high) and ta.crossover(close, swing_high) short_condition = not na(swing_low) and ta.crossunder(close, swing_low)
// === Risk Management === var float long_entry = na var float short_entry = na var float stop_loss = na var float take_profit = na
// === Plotting === // Entry Labels var label long_label = na var label short_label = na
if long_condition if na(long_label) long_label := label.new(bar_index, swing_high, "Buy", style=label.style_label_up, color=color.new(color.green, 0), textcolor=color.white) else label.set_xy(long_label, bar_index, swing_high)
if short_condition if na(short_label) short_label := label.new(bar_index, swing_low, "Sell", style=label.style_label_down, color=color.new(color.red, 0), textcolor=color.white) else label.set_xy(short_label, bar_index, swing_low)
// Stop Loss and Take Profit Lines var line stop_loss_line = na var line take_profit_line = na
if not na(stop_loss) if na(stop_loss_line) stop_loss_line := line.new(bar_index, stop_loss, bar_index + 1, stop_loss, color=color.red, width=2, style=line.style_dotted) else line.set_xy1(stop_loss_line, bar_index, stop_loss) line.set_xy2(stop_loss_line, bar_index + 1, stop_loss)
if not na(take_profit) if na(take_profit_line) take_profit_line := line.new(bar_index, take_profit, bar_index + 1, take_profit, color=color.green, width=2, style=line.style_dotted) else line.set_xy1(take_profit_line, bar_index, take_profit) line.set_xy2(take_profit_line, bar_index + 1, take_profit)
// Alerts alertcondition(long_condition, title="Long Alert", message="Buy signal detected at {{close}}") alertcondition(short_condition, title="Short Alert", message="Sell signal detected at {{close}}")
진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.