Chiến lược theo dõi giá đột phá cao và thấp


Ngày tạo: 2023-12-22 12:59:43 sửa đổi lần cuối: 2023-12-22 12:59:43
sao chép: 1 Số nhấp chuột: 606
1
tập trung vào
1623
Người theo dõi

Chiến lược theo dõi giá đột phá cao và thấp

Tổng quan

Chiến lược phá vỡ cao thấp là một chiến lược theo dõi xu hướng theo dõi mức cao hoặc thấp của giá vượt qua một đường K trước đó. Nó kết hợp với đường trung bình di chuyển để xác định hướng của xu hướng, tham gia vào điểm phá vỡ, sau đó thiết lập dừng lỗ hoặc theo dõi dừng lỗ để khóa lợi nhuận.

Nguyên tắc chiến lược

Chiến lược này dựa trên các điều kiện sau:

  1. Xác định đường K là màu đỏ hoặc màu xanh lá cây để xác định đường K tăng hoặc đường K giảm
  2. Xác định xem dòng K hiện tại có vượt qua điểm cao hay điểm thấp của một dòng K trước đó hay không
  3. Sử dụng đường trung bình di chuyển nhanh và đường trung bình di chuyển chậm để đánh giá xu hướng
  4. Khi đường K lên vượt qua điểm cao của đường K xuống trước đó, làm nhiều; khi đường K xuống vượt qua điểm thấp của đường K lên trước đó, làm trống
  5. Điều kiện dừng lỗ hoặc theo dõi kích hoạt dừng lỗ; cũng có thể thiết lập dừng lỗ ngay lập tức nếu có đường K ngược

Chiến lược này kết hợp với phán đoán tuyến K đảo ngược thứ hai để lọc các đột phá giả, đảm bảo độ tin cậy của tín hiệu đột phá.

Phân tích lợi thế

  • Chiến lược được định vị rõ ràng, các hoạt động đột phá dễ nắm bắt
  • Kết hợp với đường trung bình di chuyển đôi để đảm bảo định giá xu hướng chính xác
  • Theo dõi các cơ chế dừng lỗ giúp khóa lợi nhuận nhiều hơn
  • Cơ chế K-line đảo ngược giúp tránh việc theo đuổi cao và thấp

Phân tích rủi ro

  • Thâm nhập thất bại có thể gây tổn thất hoạt động siêu ngắn
  • Tấn công giả tạo có nguy cơ cao trong tình trạng động đất
  • Đường trung bình di chuyển đôi có thể bị trễ, dẫn đến sai lầm trong phán đoán

Biện pháp kiểm soát rủi ro:

  1. Lựa chọn chỉ số hoặc chỉ số lớn để tránh rủi ro cao cho mỗi cổ phiếu
  2. Tối ưu hóa các tham số trung bình di chuyển để tăng độ chính xác phán đoán
  3. Tăng cường mức dừng lỗ phù hợp để đảm bảo kiểm soát tổn thất đơn

Hướng tối ưu hóa

Chiến lược này có thể được tối ưu hóa theo các khía cạnh sau:

  1. Kiểm tra các tổ hợp tham số trung bình di chuyển khác nhau
  2. Thử nghiệm kết hợp các chỉ số khác để đánh giá kết hợp
  3. Các tham số để tối ưu hóa vị trí mở và điểm dừng lỗ
  4. Tăng quy tắc lọc định lượng, chọn tiêu chuẩn chất lượng
  5. Tối ưu hóa tự thích ứng tham số kết hợp với thuật toán học máy

Tóm tắt

Chiến lược phá vỡ cao thấp là một chiến lược theo dõi xu hướng trưởng thành hơn, có thể nắm bắt một mức độ xu hướng, với phán đoán hỗ trợ moving average, và các cơ chế dừng lỗ và theo dõi dừng lỗ cũng giúp khóa lợi nhuận. Bằng cách liên tục thử nghiệm và tối ưu hóa, bạn có thể làm cho các tham số của chiến lược và hiệu quả của chiến lược trở nên tuyệt vời hơn.

Mã nguồn chiến lược
/*backtest
start: 2022-12-15 00:00:00
end: 2023-12-21 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Broken High/Low Strategy", overlay=true, initial_capital = 5000, default_qty_value = 25, pyramiding = 10, default_qty_type= strategy.percent_of_equity)

useEMAForStop = input.bool(false, 'Use trail stop EMA', group = 'Exit strategy')
trailStopMALength = input(8, 'Trail stop EMA length', group = 'Exit strategy')

fastMALength = input(5 , 'Fast MA length', group = 'Trend strength')
fastEMAEnabled = input.bool(false, 'Fast EMA enabled (default is SMA)', group = 'Trend strength')

slowMALength = input(10, 'Slow MA length', group = 'Trend strength')
slowEMAEnabled = input.bool(false, 'Slow EMA enabled (default is SMA)', group = 'Trend strength')

ignoreSlowMA = input.bool(false, 'Use fast MA for trend ignoring slow MA', group = 'Trend strength')

useOpposingBarAsExit = input.bool(false, 'Using opposing bar as exit', group = 'Exit strategy')
secondEntryEnabled = input.bool(false, 'Second bar that eliminates opposing bar for entry', group = 'Trend strength')

longsEnabled = input.bool(true, 'Enable longs', group = 'Trade settings')
shortsEnabled = input.bool(true, 'Enable shorts', group = 'Trade settings')

fastMA = fastEMAEnabled ? ta.ema(close, fastMALength) : ta.sma(close, fastMALength)
slowMA = slowEMAEnabled ? ta.ema(close, slowMALength) : ta.sma(close, slowMALength)

FromMonth=input.int(defval=1,title="FromMonth",minval=1,maxval=12, group = 'Time filters')
FromDay=input.int(defval=1,title="FromDay",minval=1,maxval=31, group = 'Time filters')
FromYear=input.int(defval=1990,title="FromYear",minval=1900, group = 'Time filters')
ToMonth=input.int(defval=1,title="ToMonth",minval=1,maxval=12, group = 'Time filters')
ToDay=input.int(defval=1,title="ToDay",minval=1,maxval=31, group = 'Time filters')
ToYear=input.int(defval=9999,title="ToYear",minval=2017, group = 'Time filters')
start=timestamp(FromYear,FromMonth,FromDay,00,00)
finish=timestamp(ToYear,ToMonth,ToDay,23,59)
window()=>time>=start and time<=finish?true:false
afterStartDate = time >= start and time<=finish?true:false
closeTradesEOD = input.bool(false, 'Close trades end of day', group = 'Time filters')

trailStopMA = ta.ema(close, trailStopMALength)

isGreenCandle = close > open
isRedCandle = close < open
isBrokenHigh = close > open[1]
isPriorCandleRed = close[1] < open[1]
isPriorPriorCandleRed = close[2] < open[2]
isPriorPriorCandleGreen = close[2] > open[2]
isPriorCandleGreen = close[1] > open[1]
isBrokenLow = close < open[1]

isPriorRedCandleBroken = isGreenCandle and isPriorCandleRed and isBrokenHigh
isPriorGreenCandleBroken = isRedCandle and isPriorCandleGreen and isBrokenLow

isPriorPriorRedCandleBroken = secondEntryEnabled and not isPriorRedCandleBroken and isGreenCandle and isPriorPriorCandleRed ? close > open[2] : false
isPriorPriorGreenCandleBroken = secondEntryEnabled and not isPriorGreenCandleBroken and isRedCandle and isPriorPriorCandleGreen ? close < open[2] : false

longOpenCondition = (isPriorRedCandleBroken or isPriorPriorRedCandleBroken) and afterStartDate and (ignoreSlowMA ? close > fastMA : fastMA > slowMA) and longsEnabled
longCloseCondition = useOpposingBarAsExit ? isRedCandle : ta.crossunder(close, fastMA)
longCloseCondition := useEMAForStop ? ta.crossunder(close, trailStopMA) : longCloseCondition

shortOpenCondition = (isPriorGreenCandleBroken or isPriorPriorGreenCandleBroken) and afterStartDate and (ignoreSlowMA ? close < fastMA : fastMA < slowMA) and shortsEnabled
shortCloseCondition = useOpposingBarAsExit ? isGreenCandle : ta.crossover(close, fastMA)
shortCloseCondition := useEMAForStop ? ta.crossover(close, trailStopMA) : shortCloseCondition

if (longOpenCondition)
    strategy.entry("Long Entry", strategy.long)

if (longCloseCondition)
    strategy.close('Long Entry', 'Long Exit')

if (shortOpenCondition)
    strategy.entry("Short Entry", strategy.long)

if (shortCloseCondition)
    strategy.close('Short Entry', 'Short Exit')

if (closeTradesEOD and hour >= 14 and minute >= 30)
    strategy.close_all("EOD")

plot(useEMAForStop ? trailStopMA : na, linewidth = 2, color = color.red)
plot(fastMA)
plot(ignoreSlowMA ? na : slowMA, linewidth = 4)