Chiến lược dựa trên thẻ


Ngày tạo: 2024-02-19 15:07:33 sửa đổi lần cuối: 2024-02-19 15:07:33
sao chép: 1 Số nhấp chuột: 593
1
tập trung vào
1617
Người theo dõi

Chiến lược dựa trên thẻ

Tổng quan

Đây là một chiến lược giao dịch tự động dựa trên hình dạng thẻ. Chiến lược này kiểm soát rủi ro bằng cách nhận ra nhiều tín hiệu hình dạng thẻ, tham gia khi phù hợp với điều kiện hình dạng, và thiết lập dừng lỗ, dừng và theo dõi dừng lỗ.

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

Chiến lược này chủ yếu nhận diện các hình dạng thẻ sau như là tín hiệu nhập cảnh: hình thức gói, hình thức bao bọc, hình thức đối thấm, hình thức khởi động, hình thức đám mây đen, hình thức thành phố, hình thức dòng thai, hình thức quân ba, hình thức đáy bậc thang, v.v. Khi phát hiện tín hiệu mua trên, hãy nhập cảnh nhiều hơn; Khi phát hiện tín hiệu bán, hãy nhập cảnh trống.

Ngoài ra, các chiến lược cũng thiết lập dừng lỗ, dừng và theo dõi dừng để kiểm soát rủi ro. Cụ thể, điểm dừng lỗ được thiết lập là một phần trăm nhất định dưới giá nhập, điểm dừng là một giá trị nhất định trên giá nhập, theo dõi dừng là một điểm chuyển động nào đó trên giá nhập. Điều này có thể ngăn ngừa hiệu quả tổn thất vượt quá mức chấp nhận được.

Cần nhấn mạnh rằng chiến lược này cũng đặt thời gian giao dịch, tất cả các vị trí sẽ tháo lỗ trong thời gian giao dịch được xác định trong chiến lược, để tránh rủi ro qua đêm.

Phân tích lợi thế

Lợi thế lớn nhất của chiến lược này là sử dụng hình dạng thẻ, một chỉ số kỹ thuật hiệu quả, làm cơ sở cho sự tham gia. Nhiều dữ liệu lịch sử cho thấy rằng khi một số hình dạng K-line cụ thể xuất hiện, nó có thể là dấu hiệu của sự chuyển đổi trong mối quan hệ cung cấp và nhu cầu và tâm lý thị trường, điều này cung cấp thời điểm tốt cho sự tham gia của chúng tôi.

Một lợi thế khác là cơ chế kiểm soát rủi ro được thiết lập hoàn hảo. Cho dù là dừng lỗ, dừng lỗ hoặc theo dõi dừng lỗ, bạn có thể ngăn chặn tối đa thiệt hại vượt quá phạm vi chấp nhận được và kiểm soát rủi ro.

Cuối cùng, chiến lược hoạt động linh hoạt, có thể thích ứng với các giống và sở thích giao dịch khác nhau bằng cách điều chỉnh các tham số hình dạng và tham số kiểm soát rủi ro.

Phân tích rủi ro

Rủi ro lớn nhất của chiến lược này là sự không ổn định của hình dạng thẻ là chỉ số kỹ thuật. Mặc dù hình dạng thẻ có thể phản ánh rõ ràng xu hướng thay đổi của thị trường, nhưng cũng dễ bị ảnh hưởng bởi sự biến động ngẫu nhiên của thị trường, khả năng có tín hiệu sai là không thấp.

Ngoài ra, không có mối quan hệ nhân quả nhất thiết giữa hình dạng thẻ và sự thay đổi giá được xác nhận sau đó. Ngay cả khi phát hiện được hình dạng điển hình, xác suất của giá đi theo hướng ngược lại với mong đợi hình dạng cũng tồn tại.

Để giảm nguy cơ trên, ngoài việc tuân thủ nghiêm ngặt các quy tắc dừng lỗ, dừng và theo dõi, bạn cũng có thể xem xét kết hợp với các chỉ số khác ổn định hơn, tránh rủi ro tiềm ẩn do chỉ số kỹ thuật đơn lẻ gây ra.

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

Với những hạn chế về tính ổn định hình dạng của thẻ, bạn có thể thử kết hợp với các chỉ số ổn định hơn. Ví dụ như các chỉ số xu hướng như Bollinger Bands, Moving Averages, hoặc các chỉ số dao động như RSI, MACD. Điều này có thể được sử dụng để lọc thời gian vào sân và giảm khả năng giao dịch ồn ào.

Một hướng tối ưu hóa khác có thể là sử dụng phương pháp học máy. Bằng cách đào tạo một lượng lớn dữ liệu lịch sử như mạng thần kinh, xây dựng mô hình mối quan hệ thống kê giữa hình dạng và biến động thực tế của giá. Điều này có thể làm tăng độ chính xác của tín hiệu hình dạng.

Cuối cùng, chiến lược này có thể được sử dụng như một khuôn khổ cơ bản, được tối ưu hóa bằng các thuật toán phức tạp hơn để phù hợp với giao dịch tần số cao. Ví dụ như cách dừng lỗ tinh tế hơn hoặc mô hình phức tạp kết hợp nhiều giao diện dữ liệu hơn bằng ngôn ngữ cao cấp.

Tóm tắt

Nhìn chung, chiến lược này sử dụng hình dạng thẻ, một chỉ số kỹ thuật hiệu quả như tín hiệu đầu vào, thiết lập các rủi ro kiểm soát logic dừng, dừng và theo dõi dừng hoàn hảo, là một bộ chiến lược đáng để kiểm tra thực tế. Coding Angle khuyến khích sử dụng chiến lược này như một khuôn khổ cơ bản để tối ưu hóa để có hiệu quả thực tế tốt hơn.

Mã nguồn chiến lược
/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

//DanyChe
//The script allows you to test popular candlestick patterns on various instruments and timeframes. In addition, you can configure risk management (if the value is zero, it means the function is disabled), and you can also specify the time of the trading session (for example, so that the positions are not transferred to the next day). 
//The author is grateful to JayRogers and Phi35, their code examples helped a lot in writing the strategy.
strategy("Candle Patterns Strategy", shorttitle="CPS", overlay=true)

//--- Patterns Input ---

OnEngulfing = input(defval=true, title="Engulfing")
OnHarami = input(defval=true, title="Harami")
OnPiercingLine = input(defval=true, title="Piercing Line / Dark Cloud Cover")
OnMorningStar = input(defval=true, title="Morning Star / Evening Star ")
OnBeltHold = input(defval=true, title="Belt Hold")
OnThreeWhiteSoldiers = input(defval=true, title="Three White Soldiers / Three Black Crows")
OnThreeStarsInTheSouth = input(defval=true, title="Three Stars in the South")
OnStickSandwich = input(defval=true, title="Stick Sandwich")
OnMeetingLine = input(defval=true, title="Meeting Line")
OnKicking = input(defval=true, title="Kicking")
OnLadderBottom = input(defval=true, title="Ladder Bottom")

//--- Risk Management Input ---

inpsl = input(defval = 100, title="Stop Loss", minval = 0)
inptp = input(defval = 1000, title="Take Profit", minval = 0)
inptrail = input(defval = 40, title="Trailing Stop", minval = 0)
// If the zero value is set for stop loss, take profit or trailing stop, then the function is disabled
sl = inpsl >= 1 ? inpsl : na
tp = inptp >= 1 ? inptp : na
trail = inptrail >= 1 ? inptrail : na

//--- Session Input ---

sess = input(defval = "0000-0000", title="Trading session")
t = time('240', sess)
session_open = na(t) ? false : true

// --- Candlestick Patterns ---

//Engulfing 
bullish_engulfing = high[0]>high[1] and low[0]<low[1] and open[0]<open[1] and close[0]>close[1] and close[0]>open[0] and close[1]<close[2] and close[0]>open[1] ? OnEngulfing : na
bearish_engulfing = high[0]>high[1] and low[0]<low[1] and open[0]>open[1] and close[0]<close[1] and close[0]<open[0] and close[1]>close[2] and close[0]<open[1] ? OnEngulfing : na

//Harami
bullish_harami =  open[1]>close[1] and close[1]<close[2] and open[0]>close[1] and open[0]<open[1] and close[0]>close[1] and close[0]<open[1] and high[0]<high[1] and low[0]>low[1] and close[0]>=open[0] ? OnHarami : na
bearish_harami =   open[1]<close[1] and close[1]>close[2] and open[0]<close[1] and open[0]>open[1] and close[0]<close[1] and close[0]>open[1] and high[0]<high[1] and low[0]>low[1] and close[0]<=open[0] ? OnHarami : na

//Piercing Line/Dark Cloud Cover 
piercing_line = close[2]>close[1] and open[0]<low[1] and close[0]>avg(open[1],close[1]) and close[0]<open[1] ? OnPiercingLine : na
dark_cloud_cover = close[2]<close[1] and open[0]>high[1] and close[0]<avg(open[1],close[1]) and close[0]>open[1] ? OnPiercingLine : na

//Morning Star/Evening Star
morning_star = close[3]>close[2] and close[2]<open[2] and open[1]<close[2] and close[1]<close[2] and open[0]>open[1] and open[0]>close[1] and close[0]>close[2] and open[2]-close[2]>close[0]-open[0] ? OnMorningStar : na
evening_star = close[3]<close[2] and close[2]>open[2] and open[1]>close[2] and close[1]>close[2] and open[0]<open[1] and open[0]<close[1] and close[0]<close[2] and close[2]-open[2]>open[0]-close[0] ? OnMorningStar : na

//Belt Hold
bullish_belt_hold = close[1]<open[1] and low[1]>open[0] and close[1]>open[0] and open[0]==low[0] and close[0]>avg(close[0],open[0]) ? OnBeltHold :na
bearish_belt_hold =  close[1]>open[1] and high[1]<open[0] and close[1]<open[0] and open[0]==high[0] and close[0]<avg(close[0],open[0]) ? OnBeltHold :na

//Three White Soldiers/Three Black Crows 
three_white_soldiers = close[3]<open[3] and open[2]<close[3] and close[2]>avg(close[2],open[2]) and open[1]>open[2] and open[1]<close[2] and close[1]>avg(close[1],open[1]) and open[0]>open[1] and open[0]<close[1] and close[0]>avg(close[0],open[0]) and high[1]>high[2] and high[0]>high[1] ? OnThreeWhiteSoldiers : na
three_black_crows =  close[3]>open[3] and open[2]>close[3] and close[2]<avg(close[2],open[2]) and open[1]<open[2] and open[1]>close[2] and close[1]<avg(close[1],open[1]) and open[0]<open[1] and open[0]>close[1] and close[0]<avg(close[0],open[0]) and low[1]<low[2] and low[0]<low[1] ? OnThreeWhiteSoldiers : na

//Three Stars in the South
three_stars_in_the_south = open[3]>close[3] and open[2]>close[2] and open[2]==high[2] and open[1]>close[1] and open[1]<open[2] and open[1]>close[2] and low[1]>low[2] and open[1]==high[1] and open[0]>close[0] and open[0]<open[1] and open[0]>close[1] and open[0]==high[0] and close[0]==low[0] and close[0]>=low[1] ? OnThreeStarsInTheSouth : na

//Stick Sandwich
stick_sandwich = open[2]>close[2] and open[1]>close[2] and open[1]<close[1] and open[0]>close[1] and open[0]>close[0] and close[0]==close[2] ? OnStickSandwich : na

//Meeting Line 
bullish_ml = open[2]>close[2] and open[1]>close[1] and close[1]==close[0] and open[0]<close[0] and open[1]>=high[0] ? OnMeetingLine : na
bearish_ml = open[2]<close[2] and open[1]<close[1] and close[1]==close[0] and open[0]>close[0] and open[1]<=low[0] ? OnMeetingLine : na

//Kicking 
bullish_kicking =  open[1]>close[1] and open[1]==high[1] and close[1]==low[1] and open[0]>open[1] and open[0]==low[0] and close[0]==high[0] and close[0]-open[0]>open[1]-close[1] ? OnKicking : na
bearish_kicking = open[1]<close[1] and open[1]==low[1] and close[1]==high[1] and open[0]<open[1] and open[0]==high[0] and close[0]==low[0] and open[0]-close[0]>close[1]-open[1] ? OnKicking : na

//Ladder Bottom
ladder_bottom = open[4]>close[4] and open[3]>close[3] and open[3]<open[4] and open[2]>close[2] and open[2]<open[3] and open[1]>close[1] and open[1]<open[2] and open[0]<close[0] and open[0]>open[1] and low[4]>low[3] and low[3]>low[2] and low[2]>low[1] ? OnLadderBottom : na

// ---Plotting ---

plotshape(bullish_engulfing, text='Engulfing', style=shape.triangleup, color=#1FADA2, editable=true, title="Bullish Engulfing Text")
plotshape(bearish_engulfing,text='Engulfing', style=shape.triangledown, color=#F35A54, editable=true, title="Bearish Engulfing Text")
plotshape(bullish_harami,text='Harami', style=shape.triangleup, color=#1FADA2, editable=true, title="Bullish Harami Text")
plotshape(bearish_harami,text='Harami', style=shape.triangledown, color=#F35A54, editable=true, title="BEarish Harami Text")
plotshape(piercing_line,text='Piercing Line', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(dark_cloud_cover,text='Dark Cloud Cover', style=shape.triangledown, color=#F35A54, editable=false)
plotshape(morning_star,text='Morning Star', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(evening_star,text='Evening Star', style=shape.triangledown, color=#F35A54, editable=false)
plotshape(bullish_belt_hold,text='Belt Hold', style=shape.triangleup, color=#1FADA2, editable=false)    
plotshape(bearish_belt_hold,text='Belt Hold', style=shape.triangledown, color=#F35A54, editable=false)
plotshape(three_white_soldiers,text='Three White Soldiers', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(three_black_crows,text='Three Black Crows', style=shape.triangledown, color=#F35A54, editable=false)
plotshape(three_stars_in_the_south,text='3 Stars South', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(stick_sandwich,text='Stick Sandwich', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(bullish_ml,text='Meeting Line', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(bearish_ml,text='Meeting Line', style=shape.triangledown, color=#F35A54, editable=false)
plotshape(bullish_kicking,text='Kicking', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(bearish_kicking,text='Kicking', style=shape.triangledown, color=#F35A54, editable=false)
plotshape(ladder_bottom,text='Ladder Bottom', style=shape.triangleup, color=#1FADA2, editable=false)

// --- STRATEGY ---

SignalUp = bullish_engulfing or bullish_harami or piercing_line or morning_star or bullish_belt_hold or three_white_soldiers or three_stars_in_the_south or stick_sandwich or bullish_ml or bullish_kicking or ladder_bottom
SignalDown = bearish_engulfing or bearish_harami or dark_cloud_cover or evening_star or bearish_belt_hold or three_black_crows or bearish_ml or bearish_kicking

strategy.entry("long", true, when = SignalUp and session_open)
strategy.entry("short", false, when = SignalDown and session_open)
strategy.close("long", when = not session_open)
strategy.close("short", when = not session_open)
strategy.exit("Risk Exit long", from_entry = "long", profit = tp, trail_points = trail, loss = sl)
strategy.exit("Risk Exit short", from_entry = "short", profit = tp, trail_points = trail, loss = sl )