
이것은 1차 균형 이동 평균에 기반한 트렌드 추적 전략이다. 그것은 평행선, 가와 퓨전 1차 균형 이동 평균과 정밀 입출장 메커니즘을 결합하여 수익률을 높이는 것을 목표로 한다.
이 전략은 주로 거래의 마지막 날의 종결 가격과 사용자 정의의 입력 변수를 계산하여 일회성 평형 이동 평균을 구성한다. 가격이 상승하면 평균선을 돌파하면 더 많이 하고, 가격이 하락하면 평균선을 돌파하면 공백을 한다. 그리고 스톱 로스 스톱 가격을 설정하여 조건이 충족되면 스톱 로스 또는 스톱 로스를 설정한다.
동시에, 이 전략은 일회성 이동 평균 색상을 결정하는 구름 확인 메커니즘을 추가했다. 일회성 이동 평균 색상이 녹색일 때만 더 많이 하고, 색상이 빨간색일 때만 공백을 두는 것으로, 이것은 일부 부정확한 신호를 필터링하여 전략의 수익률을 높일 수 있다.
이 전략의 가장 큰 장점은 평균선과 일차 균형 이동 평균의 두 지표의 장점을 결합하여 가격 평균의 전반적인 움직임을 고려하고 마지막 거래일 종결 가격의 분량 변화에 관심을 두는 것입니다. 또한, 클라우드 확인 메커니즘은 거래 가짜 신호를 방지하여 전략의 안정성을 향상시킵니다.
변수 최적화 측면에서, 스톱 스톱 설정은 또한 이 전략의 위험을 제어할 수 있게 한다. 마지막으로, 일차 균형 이동 평균은 보다 새로운 기술 지표로서, 많은 사람들에게 아직 익숙하지 않다. 이것은 이 전략의 적용에 선행 우위를 가져온다.
이 전략의 가장 큰 위험은 평형 이동 평균 자체의 불안정성이다. 새로운 지표로서, 그것의 장기적인 유효성 및 파라미터 최적화 공간은 의문의 여지가 있다. 모델이 실패를 가정하면, 많은 잘못된 신호가 생성된다.
또한, 트렌드를 추적하는 모든 전략은 트렌드 반전의 위험에 직면합니다. 가격이 평균선을 돌파하지만 빠르게 회전되면 전략은 큰 손실을 입습니다. 따라서, 스톱포드의 설정은 매우 중요합니다.
이 전략은 다음과 같은 방법으로 더 개선될 수 있습니다.
첫 번째 평형 이동 평균의 length 변수를 최적화하여 최적의 평형 지점을 찾습니다.
다양한 스톱 매개 변수 설정을 테스트하여 최적의 매개 변수 조합을 결정한다. 너무 큰 스톱 매개 변수는 수익 상한을 제한하고, 너무 작은 스톱 매개 변수는 너무 큰 위험을 초래한다.
다른 기술 지표 판단을 추가하여, 예를 들어 MACD, KD 등으로, 여러 지표 합의가 형성되어, 잘못된 신호를 더욱 방지한다.
다양한 품종, 주기에 대한 재검토를 통해 최적의 전략 적용 시나리오를 결정한다.
기계학습 모형의 추가를 고려하여 역학적인 최적화와 전략의 적응적 조정을 구현하십시오.
이 전략은 평균선과 1차 균형 이동 평균의 장점을 통합하고, 합리적인 스톱 스톱을 설정하고, 클라우드 확인 메커니즘을 추가하여, 트렌드를 효과적으로 추적하고, 위험을 제어할 수 있다. 이 전략은 주식 지수, 외환, 상품 및 암호화폐와 같은 품종에 널리 적용될 수 있으며, 권장되는 양적 전략이다.
/*backtest
start: 2022-11-17 00:00:00
end: 2023-11-23 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
strategy("Ichimoku Backtester with TP and SL", overlay=true,
currency = currency.USD, default_qty_type = strategy.percent_of_equity,
default_qty_value = 95)
//@version=4
//Inputs
ts_bars = input(9, minval=1, title="Tenkan-Sen Bars")
ks_bars = input(26, minval=1, title="Kijun-Sen Bars")
ssb_bars = input(52, minval=1, title="Senkou-Span B Bars")
cs_offset = input(26, minval=1, title="Chikou-Span Offset")
ss_offset = input(26, minval=1, title="Senkou-Span Offset")
long_entry = input(true, title="Long Entry")
short_entry = input(true, title="Short Entry")
wait_for_cloud = input(true, title="Wait for Cloud Confirmation")
use_short_stop_loss = input(true, title="Use Short Stop Loss")
short_stop_loss = input(title="Short Stop Loss (%)", type=input.float, minval=0.0, step=0.1,
defval=5) * 0.01
use_long_stop_loss = input(true, title="Use Long Stop Loss")
long_stop_loss = input(title="Long Stop Loss (%)", type=input.float, minval=0.0, step=0.1,
defval=5) * 0.01
use_short_take_profit = input(true, title="Use Short Take Profit")
short_take_profit = input(title="Short Take Profit (%)", type=input.float, minval=0.0, step=0.1,
defval = 20) * .01
use_long_take_profit = input(true, title="Use Long Take Profit")
long_take_profit = input(title="Long Take Profit (%)", type=input.float, minval=0.0, step=0.1,
defval = 20) * .01
// === INPUT SHOW PLOT ===
showDate = input(defval = false, title = "Show Date Range", type = input.bool)
// === INPUT BACKTEST RANGE ===
fromMonth = input(defval = 1, title = "From Month", type = input.integer, minval = 1, maxval = 12)
fromDay = input(defval = 1, title = "From Day", type = input.integer, minval = 1, maxval = 31)
fromYear = input(defval = 2020, title = "From Year", type = input.integer, minval = 1970)
thruMonth = input(defval = 1, title = "Thru Month", type = input.integer, minval = 1, maxval = 12)
thruDay = input(defval = 1, title = "Thru Day", type = input.integer, minval = 1, maxval = 31)
thruYear = input(defval = 2112, title = "Thru Year", type = input.integer, minval = 1970)
// === FUNCTION EXAMPLE ===
start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start window
finish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function "within window of time"
middle(len) => avg(lowest(len), highest(len))
// Ichimoku Components
tenkan = middle(ts_bars)
kijun = middle(ks_bars)
senkouA = avg(tenkan, kijun)
senkouB = middle(ssb_bars)
bgcolor(color = showDate and window() ? color.gray : na, transp = 90) // plot within time window
// Plot Ichimoku Kinko Hyo
plot(tenkan, color=#0496ff, title="Tenkan-Sen")
plot(kijun, color=#991515, title="Kijun-Sen")
plot(close, offset=-cs_offset+1, color=#459915, title="Chikou-Span")
sa=plot(senkouA, offset=ss_offset-1, color=color.green, title="Senkou-Span A")
sb=plot(senkouB, offset=ss_offset-1, color=color.red, title="Senkou-Span B")
fill(sa, sb, color = senkouA > senkouB ? color.green : color.red, title="Cloud color")
ss_high = max(senkouA[ss_offset-1], senkouB[ss_offset-1])
ss_low = min(senkouA[ss_offset-1], senkouB[ss_offset-1])
// Entry/Exit Signals
tk_cross_bull = tenkan > kijun
tk_cross_bear = tenkan < kijun
cs_cross_bull = mom(close, cs_offset-1) > 0
cs_cross_bear = mom(close, cs_offset-1) < 0
price_above_kumo = close > ss_high
price_below_kumo = close < ss_low
senkou_green = senkouA > senkouB ? true : false
bullish = tk_cross_bull and cs_cross_bull and price_above_kumo
bearish = tk_cross_bear and cs_cross_bear and price_below_kumo
if (wait_for_cloud)
bullish := bullish and senkou_green
bearish := bearish and not senkou_green
longStopPrice = strategy.position_avg_price * (1 - long_stop_loss)
shortStopPrice = strategy.position_avg_price * (1 + short_stop_loss)
longLimitPrice = strategy.position_avg_price * (1 + long_take_profit)
shortLimitPrice = strategy.position_avg_price * (1 - short_take_profit)
in_long = false
in_long := in_long[1]
open_long = bullish and not in_long
open_short = bearish and in_long
if (open_long)
in_long := true
if (open_short)
in_long := false
strategy.entry("Long", strategy.long, when=open_long and long_entry and (showDate ? window() : true))
strategy.entry("Short", strategy.short ,when=open_short and short_entry and (showDate ? window() : true))
if (strategy.position_size > 0.0)
if (use_long_stop_loss and not use_long_take_profit)
strategy.exit("Long", stop = longStopPrice)
if (use_long_take_profit and not use_long_stop_loss)
strategy.exit("Long", limit = longLimitPrice)
if (use_long_take_profit and use_long_stop_loss)
strategy.exit("Long", stop = longStopPrice, limit=longLimitPrice)
if (strategy.position_size < 0.0)
if (use_short_stop_loss and not use_short_take_profit)
strategy.exit("Short", stop = shortStopPrice)
if (use_short_take_profit and not use_short_stop_loss)
strategy.exit("Short", limit = shortLimitPrice)
if (use_short_take_profit and use_short_stop_loss)
strategy.exit("Short", stop = shortStopPrice, limit = shortLimitPrice)
strategy.close("Long", when=bearish and not short_entry and (showDate ? window() : true))
strategy.close("Short", when=bullish and not long_entry and (showDate ? window() : true))