AlexInc's Bar v1.2 Chiến lược tích lũy đột phá dựa trên lọc thanh có ý nghĩa

Tác giả:ChaoZhang, Ngày: 2024-01-03 16:30:16
Tags:

img

Tổng quan

Chiến lược này dự đoán xu hướng bằng cách đánh giá thanh ý nghĩa của các đường K và tạo ra các tín hiệu giao dịch kết hợp với các tín hiệu đột phá. Chiến lược lọc các đường K quá nhỏ và chỉ phân tích thanh ý nghĩa để tránh sự can thiệp từ các biến động nhỏ thường xuyên, làm cho các tín hiệu mượt mà và đáng tin cậy hơn.

Chiến lược logic

  1. Đánh giá chiều dài thực thể của đường K hiện tại. Nếu nó lớn hơn 3 lần giá trị cơ thể trung bình của 6 đường K trước đó, nó được coi là một thanh ý nghĩa.

  2. Nếu có 3 thanh liên tiếp có ý nghĩa với thân thể dài, nó được đánh giá là tín hiệu dài. Nếu 3 thanh liên tiếp với thân thể ngắn, nó được đánh giá là tín hiệu ngắn.

  3. Trong khi đánh giá tín hiệu, nếu giá vượt qua điểm cao hoặc thấp trước đó, các tín hiệu giao dịch bổ sung cũng sẽ được tạo ra.

  4. Sử dụng SMA như một bộ lọc. Chỉ mở các vị trí khi giá vượt qua SMA.

  5. Sau khi thực hiện một vị trí, nếu giá vượt qua điểm vào hoặc SMA một lần nữa, đóng vị trí.

Phân tích lợi thế

  1. Sử dụng "các thanh có ý nghĩa" để đánh giá xu hướng có thể lọc ra sự can thiệp không cần thiết và tạo ra các tín hiệu rõ ràng hơn.

  2. Kết hợp các tín hiệu xu hướng và tín hiệu đột phá cải thiện chất lượng tín hiệu và giảm các tín hiệu sai.

  3. Bộ lọc SMA tránh mua cao và bán thấp. Chỉ mua dưới Close, bán trên Close, do đó cải thiện độ tin cậy.

  4. Đặt các điều kiện lấy lợi nhuận và dừng lỗ tạo điều kiện kiểm soát rủi ro kịp thời.

Phân tích rủi ro

  1. Chiến lược hung hăng này đánh giá tín hiệu từ chỉ 3 thanh và có thể đánh giá sai các biến động ngắn hạn như sự đảo ngược xu hướng.

  2. Không đủ dữ liệu backtesting. Kết quả có thể khác nhau giữa các sản phẩm và khung thời gian.

  3. Không kiểm soát vị trí qua đêm, với rủi ro giữ qua đêm.

Hướng dẫn tối ưu hóa

  1. Tiếp tục tối ưu hóa các tham số cho thanh có ý nghĩa, chẳng hạn như số thanh được đánh giá và định nghĩa của thanh có ý nghĩa.

  2. Kiểm tra tác động của các khung thời gian khác nhau để tìm các thông số tối ưu.

  3. Thêm stop loss dựa trên ATR để kiểm soát rủi ro.

  4. Xem xét thêm điều khiển vị trí qua đêm.

Tóm lại

Chiến lược này sử dụng lọc thanh có ý nghĩa và đánh giá xu hướng để tạo ra các tín hiệu giao dịch kết hợp với các đột phá. Nó lọc hiệu quả các biến động nhỏ không cần thiết cho các tín hiệu rõ ràng và đáng tin cậy hơn. Tuy nhiên, do chu kỳ đánh giá ngắn, có một số rủi ro đánh giá sai. Có thể cải thiện hơn nữa thông qua tối ưu hóa tham số và kiểm soát rủi ro.


/*backtest
start: 2023-12-26 00:00:00
end: 2024-01-02 00:00:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//AlexInc
//2018

// закрытие - вычислить и в течение скольки-то баров его добиваться
// если нет, то по первому противоположному
// по стоп-лоссу в любом случае - стоп вычислить

//@version=2
strategy(title = "AlexInc's Bar v1.2", shorttitle = "AlexInc Bar 1.2", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)

//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
usemar = input(false, defval = false, title = "Use Martingale")
tryprofitbars = input(6, defval = 6, minval = 1, maxval = 100, title = "Number of candles to take profit anyway")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Capital, %")

useSMAfilter = input(false, defval = true, title = "Use SMA filter")
SMAlimit = input(10, defval = 10, minval = 1, maxval = 30, title = "SMA filter limit")
bodysizeMlt = input(3, defval = 3, minval = 1, maxval = 10, title = "Body Size Multiplier")
meanfulbardiv = input(3, title = "Meanful Bar size Divider")

showarr = input(false, defval = false, title = "Show Arrows")
fromyear = input(2018, defval = 2018, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//SMA #
index = 0
index := barstate.isfirst ==true ? 0 : nz(index[1])+1

buyindex = 0
buyindex := barstate.isfirst ==true ? 0 : buyindex[1]

sellindex = 0
sellindex := barstate.isfirst ==true ? 0 : sellindex[1]

//predictprofit = barstate.isfirst ==true ? 0 : predictprofit[1]

smafilter = sma(close, SMAlimit)

//Body
body = abs(close - open)
range = abs(high - low)
abody = sma(body, 6)

max3 = 0
if body >= body[1] and body >= body[2]
    max3 := body
else
    if body[1] >= body and body[1] >= body[2]
        max3 := body[1]
    else 
        if body[2] >= body and body[2] >= body[1]
            max3 := body[2]

prevmax3 = 0
prevmax3 := nz(max3[1])


bar = close > open ? 1 : close < open ? -1 : 0
firstbullishopen = 0
firstbullishopen := bar == 1 and bar[1] != 1 ? open : nz(firstbullishopen[1])
firstbearishopen = 0
firstbearishopen := bar == -1 and bar[1] != -1 ? open : nz(firstbearishopen[1])

meanfulbar = body > abody / meanfulbardiv

meanfulbearish = 0
meanfulbearish := nz(meanfulbearish[1])

meanfulbullish = 0
meanfulbullish := nz(meanfulbullish[1])

if meanfulbar
    if bar == 1
        meanfulbullish := 1 + meanfulbullish
        meanfulbearish := 0
    else
        if bar == -1
            meanfulbearish := 1 + meanfulbearish
            meanfulbullish := 0


plot(min(low, high)-10, style=circles, color = meanfulbar ? yellow:black, linewidth=3)

//Signals
up1 = (meanfulbearish >= 3) and (close < firstbullishopen or 1) and (strategy.position_size == 0 or close < strategy.position_avg_price) and body > abody / 5 and (useSMAfilter == false or close < smafilter)
if up1 == true
	predictprofit = sma(body, 3)
up2 = sma(bar, 1) == -1 and body > prevmax3 * bodysizeMlt and (strategy.position_size == 0 or close < strategy.position_avg_price) and body > abody / 5 and (useSMAfilter == false or close < smafilter)
if up2 == true
	predictprofit = body * 0.5
plot(min(low, high), style=circles, color = up1?blue:up2?green:gray, linewidth=3)

dn1 = (meanfulbullish >= 3) and (close > firstbearishopen or 1)  and (strategy.position_size == 0 or close > strategy.position_avg_price) and body > abody / 5 and (useSMAfilter==false or close > smafilter)
if dn1 ==true 
	predictprofit = sma(body, 3)
dn2 = sma(bar, 1) == 1 and body > prevmax3 * bodysizeMlt and (strategy.position_size == 0 or close > strategy.position_avg_price) and body > abody / 5 and (useSMAfilter==false or close > smafilter)
if dn2 ==true	
	predictprofit = body * 0.5
plot(max(low, high), style=circles, color = dn1?blue:dn2?green:gray, linewidth=3)


exit = (((strategy.position_size > 0 and bar == 1 ) or (strategy.position_size < 0 and bar == -1)) and body > abody / 2 )
// or index >= buyindex (or sellindex) + tryprofitbars


//Arrows
col = exit ? black : up1 or dn1 ? blue : up2 or dn2 ? red : na
needup = up1 or up2
needdn = dn1 or dn2
needexitup = exit and strategy.position_size < 0
needexitdn = exit and strategy.position_size > 0
plotarrow(showarr and needup ? 1 : na, colorup = blue, colordown = blue, transp = 0)
plotarrow(showarr and needdn ? -1 : na, colorup = blue, colordown = blue, transp = 0)
plotarrow(showarr and needexitup ? 1 : na, colorup = black, colordown = black, transp = 0)
plotarrow(showarr and needexitdn ? -1 : na, colorup = black, colordown = black, transp = 0)


//Trading
profit = exit ? ((strategy.position_size > 0 and close > strategy.position_avg_price) or (strategy.position_size < 0 and close < strategy.position_avg_price)) ? 1 : -1 : profit[1]
mult = usemar ? exit ? profit == -1 ? mult[1] * 2 : 1 : mult[1] : 1
lot = strategy.position_size == 0 ? strategy.equity / close * capital / 100 * mult : lot[1]

if up1 or up2
    if strategy.position_size < 0
        strategy.close_all()
		buyindex = index
		sellindex = index
	if strategy.position_size == 0
		buyindex = index
		
        
    strategy.entry("Long", strategy.long, needlong == false ? 0 : lot )

if dn1 or dn2
    if strategy.position_size > 0
        strategy.close_all()
		buyindex = index
		sellindex = index
	if strategy.position_size == 0
		sellindex = index
        
    strategy.entry("Short", strategy.short, needshort == false ? 0 : lot )
    
if  exit
    strategy.close_all()

Thêm nữa