
Đây là một hệ thống giao dịch thông minh dựa trên tín hiệu chéo hai đường cong, kết hợp với chức năng quản lý rủi ro. Hệ thống sử dụng tín hiệu giao dịch ngắn hạn và trung bình di chuyển đơn giản dài hạn ((SMA) để tạo ra tín hiệu giao dịch, đồng thời tích hợp các chức năng dừng lỗ và dừng để kiểm soát rủi ro. Chiến lược này sử dụng phương pháp quản lý rủi ro phần trăm, điều chỉnh quy mô vị trí theo động lực của tài khoản tài chính, tự động hóa và thông minh hóa quá trình giao dịch.
Chiến lược này dựa trên những nguyên tắc cốt lõi sau:
Đây là một hệ thống giao dịch thông minh kết hợp các phương pháp phân tích kỹ thuật cổ điển với các khái niệm quản lý rủi ro hiện đại. Bằng cách nắm bắt xu hướng bằng hai đường thẳng chéo, sử dụng quản lý rủi ro động để kiểm soát rủi ro, thực hiện tự động hóa giao dịch. Mặc dù hệ thống vẫn còn một số nơi cần được tối ưu hóa, nhưng khái niệm thiết kế tổng thể tiên tiến và có giá trị thực tế tốt.
/*backtest
start: 2024-06-09 00:00:00
end: 2025-02-19 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy("AI Trade Bot with Risk Management", overlay=true)
// Input parameters
shortSMA = input.int(9, title="Short SMA")
longSMA = input.int(21, title="Long SMA")
riskPercent = input.float(1.0, title="Risk Percentage", step=0.1)
// Calculate SMAs
shortSMAValue = ta.sma(close, shortSMA)
longSMAValue = ta.sma(close, longSMA)
// Bullish and Bearish Signals
bullishSignal = ta.crossover(shortSMAValue, longSMAValue)
bearishSignal = ta.crossunder(shortSMAValue, longSMAValue)
// Risk Management
stopLossPercent = riskPercent / 100
takeProfitPercent = stopLossPercent * 2
// Calculate position size based on risk management
riskAmount = strategy.equity * riskPercent / 100
var float buyStopLossPrice = na
var float buyTakeProfitPrice = na
var float sellStopLossPrice = na
var float sellTakeProfitPrice = na
if (bullishSignal)
buyStopLossPrice := close * (1 - stopLossPercent)
buyTakeProfitPrice := close * (1 + takeProfitPercent)
strategy.entry("Buy", strategy.long)
strategy.exit("Take Profit/Stop Loss", from_entry="Buy", limit=buyTakeProfitPrice, stop=buyStopLossPrice)
if (bearishSignal)
sellStopLossPrice := close * (1 + stopLossPercent)
sellTakeProfitPrice := close * (1 - takeProfitPercent)
strategy.entry("Sell", strategy.short)
strategy.exit("Take Profit/Stop Loss", from_entry="Sell", limit=sellTakeProfitPrice, stop=sellStopLossPrice)
// Plot SMAs on the chart
plot(shortSMAValue, color=color.blue, title="Short SMA")
plot(longSMAValue, color=color.red, title="Long SMA")
// Plot Buy/Sell signals on the chart
plotshape(series=bullishSignal, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY")
plotshape(series=bearishSignal, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL")
// Plot Buy Stop Loss and Take Profit levels
plot(buyStopLossPrice, color=color.red, style=plot.style_linebr, linewidth=2, title="Buy Stop Loss")
plot(buyTakeProfitPrice, color=color.green, style=plot.style_linebr, linewidth=2, title="Buy Take Profit")
// Plot Sell Stop Loss and Take Profit levels
plot(sellStopLossPrice, color=color.red, style=plot.style_linebr, linewidth=2, title="Sell Stop Loss")
plot(sellTakeProfitPrice, color=color.green, style=plot.style_linebr, linewidth=2, title="Sell Take Profit")