
이 전략의 주요 아이디어는 두 개의 다른 주기의 이동 평균을 사용하여 시장 회귀 후의 반발 기회를 잡는 것입니다. 가격이 장기 평균선 위에 있고 단기 평균선으로 회귀하는 경우, 전략은 더 많은 포지션을 열고, 가격이 단기 평균선에 다시 오르게하거나 중단 가격에 닿을 때 평소 포지션을합니다. 이 전략은 추세에서 회귀 구매 기회를 찾아 추세에서 이익을 얻으려고 노력합니다.
이동 평균 회전을 추적하는 전략은 두 개의 다른 주기적 평균선의 상대적 위치 관계를 통해 상승 추세에서 가격 회전을 할 수 있는 여러 기회를 포착한다. 이 전략은 트렌드형 시장에 적용되며, 적절한 매개 변수와 스톱로스를 설정하여 트렌드 상황에서 안정적인 수익을 얻을 수 있다. 그러나 불안한 시장과 트렌드 전환시에는 이 전략은 일정 위험에 직면한다. 더 많은 지표, 최적화된 포지션 관리 및 동적 스톱로스 방법 등을 도입함으로써 이 전략의 성과와 안정성을 더욱 향상시킬 수 있다.
/*backtest
start: 2023-03-22 00:00:00
end: 2024-03-27 00:00:00
period: 1d
basePeriod: 1h
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/
// © contapessoal_ivan
// @version=5
strategy("Pullback Strategy",
overlay=true,
initial_capital=1000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100, // 100% of balance invested on each trade
commission_type=strategy.commission.cash_per_contract,
commission_value=0.005) // Interactive Brokers rate
// Get user input
i_ma1 = input.int(title="MA 1 Length", defval=200, step=10, group="Strategy Parameters", tooltip="Long-term MA")
i_ma2 = input.int(title="MA 2 Length", defval=10, step=10, group="Strategy Parameters", tooltip="Short-term MA")
i_stopPercent = input.float(title="Stop Loss Percent", defval=0.10, step=0.1, group="Strategy Parameters", tooltip="Failsafe Stop Loss Percent Decline")
i_lowerClose = input.bool(title="Exit On Lower Close", defval=false, group="Strategy Parameters", tooltip="Wait for a lower-close before exiting above MA2")
i_startTime = input(title="Start Filter", defval=timestamp("26 Jan 2023 00:00 +0000"), group="Time Filter", tooltip="Start date & time to begin searching for setups")
i_endTime = input(title="End Filter", defval=timestamp("26 Mar 2024 23:59 +0000"), group="Time Filter", tooltip="End date & time to stop searching for setups")
// Get indicator values
ma1 = ta.sma(close, i_ma1)
ma2 = ta.sma(close, i_ma2)
// Check filter(s)
f_dateFilter = true
// Check buy/sell conditions
var float buyPrice = 0
buyCondition = close > ma1 and close < ma2 and strategy.position_size == 0 and f_dateFilter
sellCondition = close > ma2 and strategy.position_size > 0 and (not i_lowerClose or close < low[1])
stopDistance = strategy.position_size > 0 ? ((buyPrice - close) / close) : na
stopPrice = strategy.position_size > 0 ? buyPrice - (buyPrice * i_stopPercent) : na
stopCondition = strategy.position_size > 0 and stopDistance > i_stopPercent
// Enter positions
if buyCondition
strategy.entry(id="Long", direction=strategy.long)
if buyCondition[1]
buyPrice := open
// Exit positions
if sellCondition or stopCondition
strategy.close(id="Long", comment="Exit" + (stopCondition ? "SL=true" : ""))
buyPrice := na
// Draw pretty colors
plot(buyPrice, color=color.lime, style=plot.style_linebr)
plot(stopPrice, color=color.red, style=plot.style_linebr, offset=-1)
plot(ma1, color=color.blue)
plot(ma2, color=color.orange)