
Chiến lược cân bằng động đa luồng trong ngày kết hợp với xu hướng trung bình và siêu xu hướng là một chiến lược giao dịch định lượng được viết dựa trên Pine Script TM 5. Chiến lược này sử dụng chỉ số MACD và chỉ số siêu xu hướng để nắm bắt cơ hội theo xu hướng của thị trường, đồng thời kiểm soát rủi ro thông qua chuyển đổi đa luồng động và dừng lỗ.
Cốt lõi của chiến lược này là kết hợp các chỉ số MACD và chỉ số siêu xu hướng để đánh giá xu hướng của thị trường.
Bằng cách chuyển đổi đa luồng động, chiến lược này có thể thích ứng với sự thay đổi của thị trường và nắm bắt cơ hội theo xu hướng. Đồng thời, thiết kế vị trí trơn thời gian cố định cũng giúp kiểm soát rủi ro.
Phương pháp cân bằng động trong ngày nhiều không gian kết hợp với xu hướng trung bình và siêu xu hướng là một chiến lược giao dịch dựa trên theo dõi xu hướng và phán đoán động lực. Bằng cách kết hợp các chỉ số siêu xu hướng và chỉ số MACD, chiến lược này có thể điều chỉnh hướng vị trí của vị trí bằng cách thích ứng với sự thay đổi của thị trường và nắm bắt cơ hội xu hướng.
Tuy nhiên, chiến lược này cũng có một số rủi ro và thiếu sót, chẳng hạn như rủi ro thất bại chỉ số, rủi ro tối ưu hóa tham số, rủi ro dừng lỗ, v.v. Để hoàn thiện chiến lược hơn nữa, bạn có thể xem xét thêm logic dừng lỗ, tham số tối ưu hóa, thêm các điều kiện lọc tín hiệu và thử nghiệm trên nhiều thị trường.
Nhìn chung, chiến lược cân bằng động lực đa luồng trong ngày kết hợp với xu hướng siêu cung cấp một suy nghĩ theo dõi xu hướng và kiểm soát rủi ro. Trong ứng dụng thực tế, các thương nhân nên kết hợp với sở thích rủi ro của mình và đặc điểm thị trường, để điều chỉnh và tối ưu hóa chiến lược một cách thích hợp, sử dụng thận trọng. Chiến lược giao dịch định lượng mặc dù có thể cung cấp suy nghĩ giao dịch, nhưng thị trường thay đổi rất nhanh, không có chiến lược nào đảm bảo lợi nhuận.
/*backtest
start: 2023-03-05 00:00:00
end: 2024-03-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © smj31071995
//@version=5
strategy("EQ - INTRA - Samsuga supertrend prod", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_every_tick = false)
atrPeriod = input.int(7, "ATR Length", minval = 1)
factor = input.float(1.0, "Factor", minval = 0.01, step = 0.01)
st_tf = "3"
macd_tf="30"
[supertrend, direction] =request.security(symbol = syminfo.tickerid, timeframe = st_tf,expression = ta.supertrend(factor, atrPeriod),lookahead=barmerge.lookahead_on)
supertrend := barstate.isfirst ? na : supertrend
upTrend = plot(direction <= 0 ? supertrend : na, "Up Trend", color = color.green, style = plot.style_linebr)
downTrend = plot(direction <= 0 ? na : supertrend, "Down Trend", color = color.red, style = plot.style_linebr)
bodyMiddle = plot(barstate.isfirst ? na : (open + close) / 2, "Body Middle",display = display.none)
longcondition = direction[1] > direction
shortCondition = direction[1] < direction
macdp1 = 2
macdp2=8
macdp3=4
[macdLine, signalLine, histLine] =request.security(symbol = syminfo.tickerid, timeframe = macd_tf,expression = ta.macd(close,macdp1,macdp2,macdp3),lookahead=barmerge.lookahead_on)
// log.info(str.tostring(syminfo.tickerid)+str.tostring(histLine[0]))
timezone_input = input("Asia/Kolkata", title="Timezone")
// log.info(timezone_input)
if(hour==15 and minute==15)
strategy.close_all(comment = "DAY EXIT",alert_message = "X-D")
else if(hour==9 and minute==30)
if(longcondition or histLine[1]>0)
strategy.entry(id= "Long", direction=strategy.long, comment = "DL",alert_message = "L")
else if(shortCondition or histLine[1]<0)
strategy.entry(id= "Short", direction=strategy.short, comment = "DS",alert_message = "S")
else
if(longcondition)
strategy.close("Short",comment = "X-S", alert_message = "X-S")
if(histLine[1]>0)
strategy.entry(id= "Long", direction=strategy.long, comment = "L",alert_message = "L")
else if(shortCondition)
strategy.close("Long",comment = "X-L",alert_message = "X-L")
if(histLine[1]<0)
strategy.entry(id= "Short", direction=strategy.short, comment = "S",alert_message = "S")
// plot(macdLine, title = "MACD", color = #2962FF)
// plot(signalLine, title = "Signal", color = #FF6D00)
// 8, 21, 5
// 8,13,9
// 12,26,9
// 1--> 3, 17, 5
// 3, 10, 16
// log.info(str.tostring(syminfo.tickerid)+str.tostring(histLine[0]))
// /////////----------------METHOD 1-----------------////////////////
// if(longcondition)
// if(strategy.opentrades>0)
// strategy.close("Long","Prev Exit", immediately = true)
// if( histLine[0] > 0.1)
// strategy.entry(id= "Long", direction=strategy.long, comment = "update long")
// else if(shortCondition and strategy.openprofit<=0.1)
// strategy.close("Long",comment = "Close",immediately = true)
// /////////----------------METHOD 2-----------------////////////////
// if(longcondition)
// if(histLine[0] > 0)
// strategy.entry(id= "Long", direction=strategy.long, comment = "update long" )
// strategy.exit("Long", loss = close*0.2)
// else if(shortCondition )
// strategy.close("Long",comment = "Close",immediately = true)
// /////////----------------METHOD 3-----------------////////////////