
이 전략은 평평한 Heikin Ashi 도표를 기반으로 한 트렌드 추적 시스템이다. 높은 시간 주기에서 Heikin Ashi 도표를 계산하고 낮은 시간 주기 거래 결정에 적용함으로써 시장 소음의 영향을 효과적으로 줄인다. 이 전략은 유연한 거래 방향 선택, 단 하나, 단 하나 또는 양방향 거래를 제공하며, 손해 중지 기능을 통합하여 완전히 자동화 된 거래 프로세스를 구현한다.
이 전략의 핵심 논리는 하이킨 아시 그래프의 고 시간 주기에서의 부드러운 특성을 활용하여 트렌드를 식별하는 것입니다. 하이킨 아시 그래프는 개시 가격과 폐시 가격에 대한 이동 평균을 계산하여 시장 소음을 효과적으로 필터링하여 주요 트렌드를 강조합니다. 녹색 이 나타나면 상승 추세를 나타냅니다.
이 전략은 다주기 하이킨 아시 지표의 부드러운 특성을 통해 시장 추세를 효과적으로 포착하고, 완벽한 위험 관리 메커니즘을 통해 회전을 제어한다. 전략의 유연성과 확장성은 좋은 실용적 가치를 가지고 있으며, 지속적인 최적화와 개선을 통해 다양한 시장 환경에 적응할 수 있다. 특정 위험이 있지만, 합리적인 매개 변수 설정과 위험 관리를 통해 안정적인 거래 성능을 달성할 수 있다.
/*backtest
start: 2024-11-10 00:00:00
end: 2024-12-09 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Optimized Heikin Ashi Strategy with Buy/Sell Options", overlay=true)
// User inputs for customizing backtest settings
startDate = input(timestamp("2023-01-01 00:00"), title="Backtest Start Date", tooltip="Start date for the backtest")
endDate = input(timestamp("2024-01-01 00:00"), title="Backtest End Date", tooltip="End date for the backtest")
// Input for Heikin Ashi timeframe optimization
ha_timeframe = input.timeframe("D", title="Heikin Ashi Timeframe", tooltip="Choose the timeframe for Heikin Ashi candles")
// Inputs for optimizing stop loss and take profit
use_stop_loss = input.bool(true, title="Use Stop Loss")
stop_loss_percent = input.float(2.0, title="Stop Loss (%)", minval=0.0, tooltip="Set stop loss percentage")
use_take_profit = input.bool(true, title="Use Take Profit")
take_profit_percent = input.float(4.0, title="Take Profit (%)", minval=0.0, tooltip="Set take profit percentage")
// Input to choose Buy or Sell
trade_type = input.string("Buy Only", options=["Buy Only", "Sell Only"], title="Trade Type", tooltip="Choose whether to only Buy or only Sell")
// Heikin Ashi calculation on a user-defined timeframe
ha_open = request.security(syminfo.tickerid, ha_timeframe, ta.sma(open, 2), barmerge.gaps_off, barmerge.lookahead_on)
ha_close = request.security(syminfo.tickerid, ha_timeframe, ta.sma(close, 2), barmerge.gaps_off, barmerge.lookahead_on)
ha_high = request.security(syminfo.tickerid, ha_timeframe, math.max(high, close), barmerge.gaps_off, barmerge.lookahead_on)
ha_low = request.security(syminfo.tickerid, ha_timeframe, math.min(low, open), barmerge.gaps_off, barmerge.lookahead_on)
// Heikin Ashi candle colors
ha_bullish = ha_close > ha_open // Green candle
ha_bearish = ha_close < ha_open // Red candle
// Backtest period filter
inDateRange = true
// Trading logic depending on user input
if (inDateRange) // Ensures trades happen only in the selected period
if (trade_type == "Buy Only") // Buy when green, Sell when red
if (ha_bullish and strategy.position_size <= 0) // Buy on green candle only if no position is open
strategy.entry("Buy", strategy.long)
if (ha_bearish and strategy.position_size > 0) // Sell on red candle (close the long position)
strategy.close("Buy")
if (trade_type == "Sell Only") // Sell when red, Exit sell when green
if (ha_bearish and strategy.position_size >= 0) // Sell on red candle only if no position is open
strategy.entry("Sell", strategy.short)
if (ha_bullish and strategy.position_size < 0) // Exit the sell position on green candle
strategy.close("Sell")
// Add Stop Loss and Take Profit conditions if enabled
if (use_stop_loss)
strategy.exit("Stop Loss", from_entry="Buy", stop=strategy.position_avg_price * (1 - stop_loss_percent / 100))
if (use_take_profit)
strategy.exit("Take Profit", from_entry="Buy", limit=strategy.position_avg_price * (1 + take_profit_percent / 100))
// Plot Heikin Ashi candles on the chart
plotcandle(ha_open, ha_high, ha_low, ha_close, color=ha_bullish ? color.green : color.red)