Chiến lược Cloud Nine của Ichimoku hướng đến giao dịch

Tác giả:ChaoZhang, Ngày: 2024-02-19 11:35:05
Tags:

img

Tổng quan

Chiến lược Ichimoku Cloud Nine được xây dựng dựa trên chỉ số Ichimoku Cloud kết hợp với việc sử dụng Fractals Williams. Đây là một chiến lược định hướng giao dịch sử dụng nhiều tín hiệu giao dịch từ Ichimoku Cloud.

Chiến lược logic

Chiến lược chủ yếu sử dụng các tín hiệu Ichimoku sau đây để tham gia giao dịch:

  1. Kumo Breakout: tạo tín hiệu khi giá đóng trên hoặc dưới đám mây
  2. TK Cross: tạo tín hiệu khi Tenkan băng qua Kijun
  3. Kumo Twist: tạo tín hiệu khi Senkou Span A băng qua Senkou Span B
  4. Edge to Edge: tạo tín hiệu khi giá nhập vào cả hai bên của Cloud

Chiến lược sẽ thoát khỏi giao dịch trong các tình huống sau:

  1. Giá đóng trong đám mây
  2. TK Chạy ngang theo hướng ngược lại
  3. Vi phạm của Williams Fractal theo hướng ngược lại

Chiến lược này kết hợp nhiều tín hiệu Ichimoku để tăng độ tin cậy trong khi sử dụng fractals như là dừng lỗ để kiểm soát rủi ro.

Ưu điểm

So với các chiến lược tín hiệu đơn, chiến lược này lọc tín hiệu thông qua nhiều tín hiệu Ichimoku, cải thiện độ chính xác.

Sử dụng các fractal như là dừng lỗ chủ động kiểm soát rủi ro và khóa lợi nhuận.

Rủi ro

Các rủi ro chính:

  1. Bản chất chậm của đám mây Ichimoku
  2. Nhiều tín hiệu có thể là quá bảo thủ bỏ lỡ cơ hội
  3. Lỗ phí dừng lại fractal có thể được đưa ra

Giảm thiểu: điều chỉnh các thông số hoặc loại bỏ một số tín hiệu.

Cơ hội gia tăng

Các lĩnh vực tối ưu hóa chính:

  1. Điều chỉnh các tham số Ichimoku cho các sản phẩm khác nhau
  2. Loại bỏ một số tín hiệu, giữ nguyên các quy tắc cốt lõi
  3. Điều chỉnh các tham số fractal để sử dụng khung thời gian cao hơn hoặc chỉ dừng một phần
  4. Thêm các chỉ số khác như khối lượng

Kết luận

Chiến lược Ichimoku Cloud Nine cải thiện giao dịch Ichimoku bằng cách kết hợp các tín hiệu để tăng độ chính xác và tỷ lệ chiến thắng. Sử dụng fractals quản lý rủi ro. Các thông số và tín hiệu có thể được tối ưu hóa cho giao dịch tự động trên các sản phẩm khác nhau.


/*backtest
start: 2024-01-19 00:00:00
end: 2024-02-18 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Ichimoku Cloud Nine", shorttitle="Ichimoku Cloud Nine", overlay=true, calc_on_every_tick = true, calc_on_order_fills = false, initial_capital = 5000, currency = "USD", default_qty_type = "percent_of_equity", default_qty_value = 10, pyramiding = 3, process_orders_on_close = true)

color green = #459915
color red = #991515

// --------
// Fractals
// --------

// Define "n" as the number of periods and keep a minimum value of 2 for error handling.
close_on_fractal = input.bool(false, title="Use William Fractals for SL?", group = "Fractals")
n = input.int(title="Periods", defval=2, minval=2, group = "Fractals")
fractal_close_percentage = input.int(100, minval=1, maxval=100, title="Position % to close on fractal breach", group = "Fractals")
selected_fractals_timeframe = input.timeframe('Current', "Timeframe", options=["Current", "1D", "12H", "8H", "4H", "1H"], group = "Fractals", tooltip = "Timeframe to use to look for fractals. Example: if 12H is selected, it will close positions when the last 12H fractal is breached.")

string fractals_timeframe = switch selected_fractals_timeframe
    "1D" => "1D"
    "12H" => "720"
    "8H" => "480"
    "4H" => "240"
    "1H" => "60"
    // Default used when the three first cases do not match.
    => ""

prev_high = request.security(syminfo.tickerid, fractals_timeframe, high)
prev_low = request.security(syminfo.tickerid, fractals_timeframe, low)

period_high=prev_high
period_low=prev_low

// UpFractal
bool upflagDownFrontier = true
bool upflagUpFrontier0 = true
bool upflagUpFrontier1 = true
bool upflagUpFrontier2 = true
bool upflagUpFrontier3 = true
bool upflagUpFrontier4 = true

for i = 1 to n
    upflagDownFrontier := upflagDownFrontier and (period_high[n-i] < period_high[n])
    upflagUpFrontier0 := upflagUpFrontier0 and (period_high[n+i] < period_high[n])
    upflagUpFrontier1 := upflagUpFrontier1 and (period_high[n+1] <= period_high[n] and period_high[n+i + 1] < period_high[n])
    upflagUpFrontier2 := upflagUpFrontier2 and (period_high[n+1] <= period_high[n] and period_high[n+2] <= period_high[n] and period_high[n+i + 2] < period_high[n])
    upflagUpFrontier3 := upflagUpFrontier3 and (period_high[n+1] <= period_high[n] and period_high[n+2] <= period_high[n] and period_high[n+3] <= period_high[n] and period_high[n+i + 3] < period_high[n])
    upflagUpFrontier4 := upflagUpFrontier4 and (period_high[n+1] <= period_high[n] and period_high[n+2] <= period_high[n] and period_high[n+3] <= period_high[n] and period_high[n+4] <= period_high[n] and period_high[n+i + 4] < period_high[n])
flagUpFrontier = upflagUpFrontier0 or upflagUpFrontier1 or upflagUpFrontier2 or upflagUpFrontier3 or upflagUpFrontier4

upFractal = (upflagDownFrontier and flagUpFrontier)

var float upFractalPrice = 0

if (upFractal)
    upFractalPrice := period_high[n]

// downFractal
bool downflagDownFrontier = true
bool downflagUpFrontier0 = true
bool downflagUpFrontier1 = true
bool downflagUpFrontier2 = true
bool downflagUpFrontier3 = true
bool downflagUpFrontier4 = true

for i = 1 to n
    downflagDownFrontier := downflagDownFrontier and (period_low[n-i] > period_low[n])
    downflagUpFrontier0 := downflagUpFrontier0 and (period_low[n+i] > period_low[n])
    downflagUpFrontier1 := downflagUpFrontier1 and (period_low[n+1] >= period_low[n] and period_low[n+i + 1] > period_low[n])
    downflagUpFrontier2 := downflagUpFrontier2 and (period_low[n+1] >= period_low[n] and period_low[n+2] >= period_low[n] and period_low[n+i + 2] > period_low[n])
    downflagUpFrontier3 := downflagUpFrontier3 and (period_low[n+1] >= period_low[n] and period_low[n+2] >= period_low[n] and period_low[n+3] >= period_low[n] and period_low[n+i + 3] > period_low[n])
    downflagUpFrontier4 := downflagUpFrontier4 and (period_low[n+1] >= period_low[n] and period_low[n+2] >= period_low[n] and period_low[n+3] >= period_low[n] and period_low[n+4] >= period_low[n] and period_low[n+i + 4] > period_low[n])
flagDownFrontier = downflagUpFrontier0 or downflagUpFrontier1 or downflagUpFrontier2 or downflagUpFrontier3 or downflagUpFrontier4

downFractal = (downflagDownFrontier and flagDownFrontier)

var float downFractalPrice = 0

if (downFractal)
    downFractalPrice := period_low[n]

plotshape(downFractal, style=shape.triangledown, location=location.belowbar, offset=-n, color=#F44336, size = size.auto)
plotshape(upFractal, style=shape.triangleup,   location=location.abovebar, offset=-n, color=#009688, size = size.auto)

// --------
// Ichimoku
// --------

previous_close = close[1]

conversionPeriods = input.int(20, minval=1, title="Conversion Line Periods", group = "Cloud Settings"),
basePeriods = input.int(60, minval=1, title="Base Line Periods", group = "Cloud Settings")
laggingSpan2Periods = input.int(120, minval=1, title="Lagging Span 2 Periods", group = "Cloud Settings"),
displacement = input.int(30, minval=1, title="Displacement", group = "Cloud Settings")


long_entry = input.bool(true, title="Longs", group = "Entries", tooltip = "Will look for longs")
short_entry = input.bool(true, title="Shorts", group = "Entries", tooltip = "Will look for shorts")
wait_for_twist = input.bool(true, title="Wait for kumo twist?", group = "Entries", tooltip = "Will wait for the Kumo to turn green (longs) or red (shorts)")
ignore_lagging_span = input.bool(true, title="Ignore Lagging Span Signal?", group = "Entries", tooltip = "Will not wait for lagging span to be above/below price and cloud")
bounce_entry = input.bool(true, title="Kijun Bounce", group = "Entries", tooltip = "Will enter position on a Kijun bounce")

e2e_entry = input.bool(true, title="Enable", group = "Edge 2 Edge", tooltip = "Will look for edge-to-edge trades")
e2e_entry_tk_confluence = input.bool(true, title="Require TK Confluence?", group = "Edge 2 Edge", tooltip = "Require confluent TK cross in order to enter an e2e trade")
min_cloud_thickness = input.float(10, minval=1, title="Minimun Cloud Thickness (%)", group = "Edge 2 Edge", tooltip = "Minimum cloud thickness for entering e2e trades")

donchian(len) => math.avg(ta.lowest(len), ta.highest(len))

tenkan = donchian(conversionPeriods)
kijun = donchian(basePeriods)
spanA = math.avg(tenkan, kijun)
spanB = donchian(laggingSpan2Periods)

plot(tenkan, color=#0496ff, title="Tenkan-Sen", linewidth = 2)
plot(kijun, color=red, title="Kijun-Sen", linewidth = 2)
plot(close, offset = -displacement, color=color.gray, title="Chikou Span")

p1 = plot(spanA, offset = displacement, color=green, title="Senkou Span A")
p2 = plot(spanB, offset = displacement, color=red, title="Senkou Span B")
fill(p1, p2, color = spanA > spanB ? color.new(green, 50) : color.new(red, 50))

cloud_high = math.max(spanA[displacement], spanB[displacement])
cloud_low = math.min(spanA[displacement], spanB[displacement])

lagging_span_above_price_and_cloud = (close > close[displacement] and close > cloud_high[displacement]) or ignore_lagging_span
lagging_span_below_price_and_cloud = (close < close[displacement] and close < cloud_low[displacement]) or ignore_lagging_span

step1=cloud_high-cloud_low
step2=(cloud_high+cloud_low)/2
cloud_thickness = (step1/step2)*100

// --------
// Trades
// --------

// LONGS
// kumo breakout
if (long_entry and ta.crossover(close, cloud_high) and tenkan > kijun and close > kijun and lagging_span_above_price_and_cloud and (not wait_for_twist or spanA > spanB))
    comment = "Long - Kumo Breakout"
    strategy.entry("Long", strategy.long, comment = comment)
    alert(comment, alert.freq_once_per_bar)

// tk cross above cloud
if (long_entry and close > cloud_high and ta.crossover(tenkan, kijun) and lagging_span_above_price_and_cloud and (not wait_for_twist or spanA > spanB))
    comment = "Long - TK Cross"
    strategy.entry("Long", strategy.long, comment = comment)
    alert(comment, alert.freq_once_per_bar)

// kumo twist
if (long_entry and close > cloud_high and tenkan > kijun and ta.crossover(spanA, spanB) and lagging_span_above_price_and_cloud)
    comment = "Long - Kumo Twist"
    strategy.entry("Long", strategy.long, comment = comment)
    alert(comment, alert.freq_once_per_bar)

// close inside cloud
if (ta.crossunder(close, cloud_high))
    comment = "Close Long - Close inside cloud"
    strategy.close("Long", comment = comment)
    alert(comment, alert.freq_once_per_bar)

// bearish tk cross
if (ta.crossunder(tenkan, kijun))
    comment = "Close Long - TK Cross"
    strategy.close("Long", comment = comment)
    alert(comment, alert.freq_once_per_bar)


if (close_on_fractal and ta.crossunder(low, downFractalPrice))
    comment = "Close Long - Fractal"
    strategy.close("Long", comment = comment, qty_percent = fractal_close_percentage)
    alert(comment, alert.freq_once_per_bar)


// SHORTS
// kumo breakout
if (short_entry and ta.crossunder(close, cloud_low) and tenkan < kijun and close < kijun and lagging_span_below_price_and_cloud and (not wait_for_twist or spanA < spanB))
    comment = "Short - Kumo Breakout"
    strategy.entry("Short", strategy.short, comment = comment)
    alert(comment, alert.freq_once_per_bar)

// tk cross below cloud
if (short_entry and close < cloud_low and ta.crossunder(tenkan, kijun) and lagging_span_below_price_and_cloud and (not wait_for_twist or spanA < spanB))
    comment = "Short - TK Cross"
    strategy.entry("Short", strategy.short, comment = comment)
    alert(comment, alert.freq_once_per_bar)

// kumo twist
if (short_entry and close < cloud_low and tenkan < kijun and lagging_span_below_price_and_cloud and ta.crossunder(spanA, spanB))
    comment = "Short - Kumo Twist"
    strategy.entry("Short", strategy.short, comment = comment)
    alert(comment, alert.freq_once_per_bar)

// close inside cloud
if (ta.crossover(close, cloud_low))
    comment = "Close Short - Close inside cloud"
    strategy.close("Short", comment = comment)
    alert(comment, alert.freq_once_per_bar)

// bullish tk cross
if (ta.crossover(tenkan, kijun))
    comment = "Close Short - TK Cross"
    strategy.close("Short", comment = comment)
    alert(comment, alert.freq_once_per_bar)

if (close_on_fractal and ta.crossover(high, upFractalPrice))
    comment = "Close Short - Fractal"
    strategy.close("Short", comment = comment, qty_percent = fractal_close_percentage)
    alert(comment, alert.freq_once_per_bar)


// BULL EDGE TO EDGE
if (e2e_entry and e2e_entry_tk_confluence and ta.crossover(close, cloud_low) and tenkan > kijun and open > kijun and cloud_thickness > min_cloud_thickness)
    comment = "Long e2e"
    strategy.entry("Long e2e", strategy.long, comment = comment)
    alert(comment, alert.freq_once_per_bar)

if (e2e_entry and not e2e_entry_tk_confluence and ta.crossover(close, cloud_low) and open > kijun and cloud_thickness > min_cloud_thickness)
    comment = "Long e2e"
    strategy.entry("Long e2e", strategy.long, comment = comment)
    alert(comment, alert.freq_once_per_bar)

if (ta.cross(high, cloud_high))
    comment = "Close Long e2e - Target Hit"
    strategy.close("Long e2e", comment = comment)
    alert(comment, alert.freq_once_per_bar)

if (ta.crossunder(close, cloud_low))
    comment = "Close Long e2e - Close below cloud"
    strategy.close("Long e2e", comment = comment)
    alert(comment, alert.freq_once_per_bar)
 
if (close_on_fractal and ta.crossunder(low, downFractalPrice))
    comment = "Close Long e2e - Fractal"
    strategy.close("Long e2e", comment = comment, qty_percent = fractal_close_percentage)
    alert(comment, alert.freq_once_per_bar)

// BEAR EDGE TO EDGE
if (e2e_entry and e2e_entry_tk_confluence and ta.crossunder(close, cloud_high) and tenkan < kijun and open < kijun and cloud_thickness > min_cloud_thickness)
    comment = "Short e2e"
    strategy.entry("Short e2e", strategy.long, comment = comment)
    alert(comment, alert.freq_once_per_bar)

if (e2e_entry and not e2e_entry_tk_confluence and ta.crossunder(close, cloud_high) and open < kijun and cloud_thickness > min_cloud_thickness)
    comment = "Short e2e"
    strategy.entry("Short e2e", strategy.long, comment = comment)
    alert(comment, alert.freq_once_per_bar)

if (ta.cross(low, cloud_low))
    comment = "Close Short e2e - Target Hit"
    strategy.close("Short e2e", comment = comment)
    alert(comment, alert.freq_once_per_bar)

if (ta.crossover(close, cloud_high))
    comment = "Close Short e2e - Close below cloud"
    strategy.close("Short e2e", comment = comment)
    alert(comment, alert.freq_once_per_bar)
 
if (close_on_fractal and ta.crossover(high, upFractalPrice))
    comment = "Close Short e2e - Fractal"
    strategy.close("Short e2e", comment = comment, qty_percent = fractal_close_percentage)
    alert(comment, alert.freq_once_per_bar)

// Kijun Bounce
if (bounce_entry and long_entry and open > cloud_high and open > kijun and ta.crossunder(low, kijun) and close > kijun and tenkan > kijun and kijun > cloud_high and lagging_span_above_price_and_cloud)
    comment = "Long - Kijun Bounce"
    strategy.entry("Long", strategy.long, comment = comment)
    alert(comment, alert.freq_once_per_bar)

if (bounce_entry and short_entry and open < cloud_low and open < kijun and ta.crossover(high, kijun) and close < kijun and tenkan < kijun and kijun < cloud_low and lagging_span_below_price_and_cloud)
    comment = "Short - Kijun Bounce"
    strategy.entry("Short", strategy.short, comment = comment)
    alert(comment, alert.freq_once_per_bar)


Thêm nữa