
Chiến lược này là một hệ thống giao dịch động lực dựa trên chỉ số CCI, để nắm bắt cơ hội giao dịch tại các khu vực bán tháo của thị trường bằng cách theo dõi mức độ giá lệch khỏi giá trị trung bình. Chiến lược sử dụng 12 chu kỳ như là giai đoạn quay trở lại, mua nhiều khi chỉ số CCI giảm xuống 90 điểm, bán tháo khi giá bán tháo phá vỡ mức cao trước đó, và được trang bị các cơ chế dừng lỗ và thu lợi nhuận có thể chọn.
Chiến lược này sử dụng chỉ số CCI để đo độ lệch giữa giá và giá trung bình của nó. Quy trình tính toán CCI bao gồm: đầu tiên tính giá điển hình (((giá cao nhất, giá thấp nhất và giá đóng cửa), sau đó tính trung bình di chuyển đơn giản của giá điển hình (((SMA), và cuối cùng lấy giá điển hình bằng cách trừ SMA và nhân 0,015 với độ lệch trung bình để có được giá trị CCI cuối cùng.
Chiến lược này nắm bắt cơ hội bán tháo thị trường thông qua chỉ số CCI, kết hợp với cơ chế dừng lỗ và đóng lợi nhuận, để thực hiện một hệ thống giao dịch hoàn chỉnh. Lập luận của chiến lược rõ ràng, dễ thực hiện và có khả năng kiểm soát rủi ro tốt.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("CCI Threshold Strategy", overlay=false, initial_capital=50000, pyramiding=0, commission_type=strategy.commission.cash_per_contract, commission_value=0.05, slippage=1)
// --- Input Parameters ---
// Lookback period for CCI calculation
lookbackPeriod = input.int(12, minval=1, title="CCI Lookback Period")
// Buy threshold for CCI; typically represents an oversold condition
buyThreshold = input.int(-90, title="CCI Buy Threshold")
// Stop loss and take profit settings
stopLoss = input.float(100.0, minval=0.0, title="Stop Loss in Points")
takeProfit = input.float(150.0, minval=0.0, title="Take Profit in Points")
// Checkboxes to enable/disable SL and TP
useStopLoss = input.bool(false, title="Enable Stop Loss")
useTakeProfit = input.bool(false, title="Enable Take Profit")
// --- Calculate CCI ---
// CCI (Commodity Channel Index) is used as a momentum indicator to identify oversold and overbought conditions
cci = ta.cci(close, length=lookbackPeriod)
// --- Define Buy and Sell Conditions ---
// Buy condition: CCI drops below -90, indicating potential oversold levels
longCondition = cci < buyThreshold
// Sell condition: Close price crosses above the previous day's high, signaling potential exit
sellCondition = close > ta.highest(close[1], 1)
// --- Strategy Execution ---
// Buy entry based on the long condition
if (longCondition)
strategy.entry("Buy", strategy.long)
// Close the long position based on the sell condition
if (sellCondition)
strategy.close("Buy")
// Optional: Add stop loss and take profit for risk management
if (longCondition)
strategy.exit("Sell", from_entry="Buy", loss=useStopLoss ? stopLoss : na, profit=useTakeProfit ? takeProfit : na)
// --- Plotting for Visualization ---
// Plot CCI with threshold levels for better visualization
plot(cci, title="CCI", color=color.blue)
hline(buyThreshold, "Buy Threshold", color=color.red, linestyle=hline.style_dotted)
hline(0, "Zero Line", color=color.gray, linestyle=hline.style_dotted)