
이 전략은 매수만 거래하는 시스템으로, 매수 신호를 생성하는 이동 평균의 교차와 주기적 상품 통로 지수 ((CCI) 또는 주기적 평균 방향 지수 ((ADX) 를 기반으로 한다. 매수 신호는 빠른 이동 평균의 빠른 이동 평균을 통과하고 주기적 CCI 및/또는 주기적 ADX가 특정 조건을 충족하면 생성된다.
이 전략은 또한 동적 재입입을 허용하는데, 이는 가격이 다시 세 개의 이동 평균을 통과하면 새로운 다단위 포지션을 열 수 있다는 것을 의미한다. 그러나, 가격이 3번째 이동 평균을 통과하면 이 전략은 다단위 포지션을 평행시킨다.
스크립트는 구매 신호를 생성하는 조건을 정의한다. 유효한 구매 신호를 판단하기 위해 두 가지 조건을 검사한다:
“이봐, 이봐, 이봐.3개의 이동 평균보다 높은 가격으로 매장되지 않은 다단위 포지션이 없다면, 새로운 다단위 포지션을 열으십시오.
탈퇴 조건:이 전략은 3번째 이동 평균 아래로 종결될 경우, 상위 포지션을 평행합니다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
이 전략에는 다음과 같은 위험도 있습니다.
대응방법:
이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.
이 동적 재입장 구매 전략은 구매 시기를 판단하는 여러 가지 기술 지표를 통합하고 동적 재입장 디자인을 적용하여 트렌드를 실시간으로 추적할 수 있습니다. 동시에 더 많은 것을 할 때 공백으로 인한 추가 위험을 피할 수 있습니다. 매개 변수 최적화, 스톱 손실 설정 및 포지션 관리를 통해 이 전략을 실물 거래에 적용하여 위험을 제어하면서 초과 수익을 얻을 수 있습니다.
/*backtest
start: 2022-12-12 00:00:00
end: 2023-12-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Buy Only Strategy with Dynamic Re-Entry and Exit", overlay=true)
// Input Parameters
fast_length = input(20, title="Fast Moving Average Length")
slow_length = input(30, title="Slow Moving Average Length")
third_ma_length = input(100, title="Third Moving Average Length")
cci_period = input(14, title="CCI Period for Weekly CCI")
use_cci = input(true, title="Use CCI for Entry")
use_adx = input(true, title="Use ADX for Entry")
adx_length = input(14, title="ADX Length")
adx_threshold = input(25, title="ADX Threshold")
// Calculate Moving Averages
fast_ma = ta.sma(close, fast_length)
slow_ma = ta.sma(close, slow_length)
third_ma = ta.sma(close, third_ma_length)
// Weekly Commodity Channel Index (CCI) with user-defined period
weekly_cci = request.security(syminfo.tickerid, "W", ta.cci(close, cci_period))
// Weekly Average Directional Index (ADX)
dirmov = hlc3
plus = ta.change(dirmov) > 0 ? ta.change(dirmov) : 0
minus = ta.change(dirmov) < 0 ? -ta.change(dirmov) : 0
trur = ta.rma(ta.tr, adx_length)
plusDI = ta.rma(plus, adx_length) / trur * 100
minusDI = ta.rma(minus, adx_length) / trur * 100
sum = plusDI + minusDI
DX = sum == 0 ? 0 : math.abs(plusDI - minusDI) / sum * 100
ADX = ta.rma(DX, adx_length)
// Entry Conditions (Buy Only and Weekly CCI > 100 and/or Weekly ADX > 25)
cci_condition = use_cci ? (weekly_cci > 100) : false
adx_condition = use_adx ? (ADX > adx_threshold) : false
long_condition = ta.crossover(fast_ma, slow_ma) and (cci_condition or adx_condition)
// Exit Condition and Dynamic Re-Entry
exit_condition = close < third_ma
re_entry_condition = close > fast_ma and close > slow_ma and close > third_ma and weekly_cci > 100
// Entry and Exit Signals
strategy.entry("Long", strategy.long, when=long_condition)
strategy.close("Long", when=exit_condition)
// Dynamic Re-Entry and Exit
if strategy.position_size == 0 and re_entry_condition
strategy.entry("Long", strategy.long)
if strategy.position_size > 0 and close < third_ma
strategy.close("Long")
// Plot Weekly CCI and ADX for reference
plot(weekly_cci, title="Weekly CCI", color=color.orange)
plot(ADX, title="Weekly ADX", color=color.blue)