
이 전략은 가격 피벗 포인트를 기반으로 지지선과 저항선을 동적으로 식별하는 적응형 거래 시스템입니다. 실시간으로 현지 최고가와 최저가를 계산하여 주요 가격 수준을 결정하고 그에 따라 거래를 실행합니다. 이 전략의 핵심은 시장 상황의 변화에 따라 거래 매개변수를 적시에 조정할 수 있는 역동적인 특성에 있으며, 추세적이고 변동성이 큰 시장에 적합합니다.
전략의 핵심 논리는 다음과 같은 핵심 요소에 기초합니다.
이 전략은 주요 가격 수준을 동적으로 식별하고 엄격한 위험 관리를 결합하여 추세 추종 및 역전 거래를 위한 견고한 프레임워크를 제공합니다. 어느 정도 매개변수 민감도와 시장 환경 의존성은 있지만, 지속적인 최적화와 개선을 통해 다양한 시장 환경에서 안정적인 성과를 유지할 수 있습니다. 전략을 성공적으로 운영하려면 거래자가 전략의 원칙을 깊이 이해하고 특정 시장 상황에 따라 적절한 매개변수 조정을 해야 합니다.
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-08 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © felipemiransan
//@version=6
strategy("Dynamic Support and Resistance Pivot Strategy ", overlay=true)
// Strategy parameters
pivot_length = input.int(2, title="Pivot Length", tooltip="Pivot size to identify peaks and troughs")
support_resistance_distance = input.float(0.4, title="Support/Resistance Distance %", tooltip="Distance to consider a support or resistance level in %")
// Stop Loss and Take Profit parameters
stop_loss_pct = input.float(10.0, title="Stop Loss %", tooltip="Stop loss percentage", minval=0.1) / 100
take_profit_pct = input.float(26.0, title="Take Profit %", tooltip="Take profit percentage", minval=0.1) / 100
// Functions to identify high and low pivots
pivot_high = ta.pivothigh(high, pivot_length, pivot_length)
pivot_low = ta.pivotlow(low, pivot_length, pivot_length)
// Storing support and resistance levels
var float resistance_level = na
var float support_level = na
var float last_pivot_high = na
var float last_pivot_low = na
// Updating support and resistance based on pivots
if (not na(pivot_high))
resistance_level := high[pivot_length]
last_pivot_high := high[pivot_length]
if (not na(pivot_low))
support_level := low[pivot_length]
last_pivot_low := low[pivot_length]
// Function to check if the current price is near a support or resistance level
is_near_resistance = (not na(resistance_level)) and (close >= resistance_level * (1 - support_resistance_distance / 100)) and (close <= resistance_level * (1 + support_resistance_distance / 100))
is_near_support = (not na(support_level)) and (close >= support_level * (1 - support_resistance_distance / 100)) and (close <= support_level * (1 + support_resistance_distance / 100))
// Cross conditions variables
long_cross = ta.crossover(close, support_level) and not na(support_level)
short_cross = ta.crossunder(close, resistance_level) and not na(resistance_level)
// Entry conditions
long_condition = is_near_support and long_cross // Buy when crossing support from below
short_condition = is_near_resistance and short_cross // Sell when crossing resistance from above
// Order execution
if (long_condition)
strategy.entry("Long", strategy.long)
if (short_condition)
strategy.entry("Short", strategy.short)
// Stop Loss and Take Profit
if (strategy.opentrades > 0)
if (strategy.position_size > 0) // For long position
avg_price_long = strategy.position_avg_price
long_stop_level = avg_price_long * (1 - stop_loss_pct)
long_take_profit_level = avg_price_long * (1 + take_profit_pct)
strategy.exit("Exit Long", from_entry="Long", stop=long_stop_level, limit=long_take_profit_level)
if (strategy.position_size < 0) // For short position
avg_price_short = strategy.position_avg_price
short_stop_level = avg_price_short * (1 + stop_loss_pct)
short_take_profit_level = avg_price_short * (1 - take_profit_pct)
strategy.exit("Exit Short", from_entry="Short", stop=short_stop_level, limit=short_take_profit_level)
// Plotting support and resistance levels on the chart
plot(support_level, title="Support", color=color.green, linewidth=2, style=plot.style_line)
plot(resistance_level, title="Resistance", color=color.red, linewidth=2, style=plot.style_line)
// Adding labels to show pivot values
if (long_condition and not na(support_level))
label.new(bar_index, low[pivot_length], str.tostring(low[pivot_length]), style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small)
if (short_condition and not na(resistance_level))
label.new(bar_index, high[pivot_length], str.tostring(high[pivot_length]), style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small)