TP, SL, 클라우드 확인과 함께 Ichimoku 백테스터

저자:차오장, 날짜: 2023-11-24 17:32:47
태그:

img

전반적인 설명

이치는 이치모쿠 백테스팅 전략으로 이윤을 취하고, 손해를 멈추고, 클라우드 확인을 합니다. 이치는 이치모쿠 지표를 사용하여 트렌드를 정확하게 캡처함으로써 수익성을 향상시키는 것을 목표로 합니다.

전략 논리

이 전략의 핵심은 사용자 입력 매개 변수 - 텐칸-센, 키준-센, 센쿠 스판 A & B 및 치코 스판에 기반한 이치모쿠 구성 요소를 구성합니다. 가격이 이러한 균형선을 넘을 때 상승 (장) 및 하락 (단) 신호를 식별합니다.

또한, 리스크 & 리워드를 관리하기 위해 엔트리 가격에 기반한 스톱 로스 및 영리를 구현합니다. 클라우드 확인을 기다리는 옵션도 있습니다. 즉, 장래에 대한 Senkou Span A > B 및 쇼트에 대한 Senkou Span A < B입니다. 이것은 잘못된 브레이크를 피하는 데 도움이됩니다.

장점

이 전략의 주요 장점은 세 가지입니다.

  1. 이치모쿠는 트렌드와 추진력을 잘 파악할 수 있습니다. 평형선은 견고한 지지와 저항 영역을 제공합니다.

  2. 스톱 로스 및 영업 수익 기능은 위험을 최소화하면서 보상을 극대화합니다. 이것은 위험 수익 프로파일을 최적화합니다.

  3. 클라우드 확인은 잘못된 신호를 필터링하여 높은 확률의 항목을 보장합니다. 이것은 수익성을 향상시킵니다.

위험성

그러나 고려해야 할 몇 가지 주요 위험 요소도 있습니다.

  1. 이치모쿠는 시장의 흐름이 명확하지 않은 범위 내에서 휘프사이에 취약합니다.

  2. 구름은 뒤떨어진 지표입니다. 구름 확인이 있을 때, 이동의 대부분은 이미 이루어졌을 수 있습니다.

  3. 스톱 로스 및 취리 레벨을 최적화하는 것은 도전적이고 민감합니다. 최적 이하의 매개 변수는 더 많은 손실로 이어질 수 있습니다.

개선

이 전략을 개선할 수 있는 몇 가지 방법:

  1. 이치모쿠를 RSI와 같은 대표적인 지표와 결합해 추가 확인과 초기 진입을 위해

  2. 고정된 비율을 사용하는 대신 변동성을 기반으로 스톱 로스를 적응적으로 조정하고 수익을 취합니다.

  3. 최적의 매개 변수를 다양한 자산과 기간에 걸쳐 테스트하여 전략에 대한 최적의 설정을 식별합니다.

  4. 기계 학습을 통합하여 업데이트 된 데이터를 기반으로 매개 변수와 전략 규칙을 지속적으로 최적화합니다.

결론

이치는 좋은 트렌드 캡처 및 리스크 관리 기능을 가진 탄탄한 이치모쿠 시스템이다. 일부 개선으로 전체 거래 접근 방식에 훌륭한 추가가 될 수 있습니다. 이치는 외환, 상품 및 암호화폐 시장에서 잘 작동합니다.


/*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))


더 많은