
Chiến lược này là một hệ thống giao dịch tham số tự điều chỉnh dựa trên tín hiệu giao chéo hai đường cong. Các tín hiệu giao dịch được tạo ra bằng cách giao chéo giữa các đường trung bình di chuyển nhanh và đường trung bình di chuyển chậm, kết hợp với các tham số quản lý rủi ro có thể điều chỉnh như dừng, dừng và theo dõi dừng để thực hiện quản lý chiến lược giao dịch linh hoạt.
Chiến lược sử dụng hai đường trung bình di chuyển nhanh và chậm làm chỉ số cốt lõi. Hệ thống tạo ra nhiều tín hiệu khi đường trung bình di chuyển nhanh đi lên vượt qua đường trung bình di chuyển chậm; hệ thống tạo ra tín hiệu đồng bằng khi đường trung bình di chuyển nhanh đi xuống vượt qua đường trung bình di chuyển chậm.
Chiến lược này kết hợp các tham số quản lý rủi ro linh hoạt bằng cách kết nối hai đường cong bằng nhau, xây dựng một hệ thống giao dịch thích ứng. Ưu điểm của chiến lược là các tham số có thể điều chỉnh được, kiểm soát rủi ro hoàn hảo, nhưng cũng cần chú ý đến rủi ro của thị trường xung đột và tối ưu hóa tham số.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 08:00:00
period: 2d
basePeriod: 2d
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/
// © traderhub
//@version=5
strategy("Two Moving Averages Strategy with Adjustable Parameters", overlay=true)
// Adjustable parameters for fast and slow moving averages
fastLength = input.int(10, title="Fast Moving Average Length", minval=1, maxval=100)
slowLength = input.int(30, title="Slow Moving Average Length", minval=1, maxval=100)
// Risk management parameters
stopLossPerc = input.float(1, title="Stop Loss (%)", step=0.1) // Stop-loss percentage
takeProfitPerc = input.float(2, title="Take Profit (%)", step=0.1) // Take-profit percentage
trailStopPerc = input.float(1.5, title="Trailing Stop (%)", step=0.1) // Trailing stop percentage
// Calculate fast and slow moving averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)
// Plot moving averages on the chart
plot(fastMA, color=color.blue, title="Fast Moving Average")
plot(slowMA, color=color.red, title="Slow Moving Average")
// Conditions for opening and closing positions
longCondition = ta.crossover(fastMA, slowMA) // Buy when fast moving average crosses above the slow moving average
shortCondition = ta.crossunder(fastMA, slowMA) // Sell when fast moving average crosses below the slow moving average
// Variables for stop-loss and take-profit levels
var float longStopLevel = na
var float longTakeProfitLevel = na
// Enter a long position
if (longCondition)
longStopLevel := strategy.position_avg_price * (1 - stopLossPerc / 100)
longTakeProfitLevel := strategy.position_avg_price * (1 + takeProfitPerc / 100)
strategy.entry("Long", strategy.long)
// Manage stop-loss, take-profit, and trailing stop for long positions
if (strategy.position_size > 0)
strategy.exit("Take Profit/Stop Loss", "Long", stop=longStopLevel, limit=longTakeProfitLevel, trail_offset=trailStopPerc)
// Close the long position and enter short when the condition is met
if (shortCondition)
strategy.close("Long")
strategy.entry("Short", strategy.short)