
Chiến lược này được sử dụng để đánh giá liệu có kích hoạt tín hiệu mua hay bán bằng cách so sánh giá đóng cửa của dòng K hiện tại với giá đóng cửa của dòng K trước đó.
Cụ thể, một tín hiệu mua sẽ được kích hoạt nếu giá đóng cửa K hiện tại cao hơn giá cao nhất của K trước; và một tín hiệu bán sẽ được kích hoạt nếu giá đóng cửa K hiện tại thấp hơn giá thấp nhất của K trước.
Đây là logic giao dịch cơ bản của chiến lược này.
Chiến lược tổng thể của chiến lược này rất đơn giản và rõ ràng, sử dụng thông tin giá đóng cửa K để đánh giá xu hướng, đồng thời thiết lập rủi ro kiểm soát dừng lỗ, có thể là chiến lược cơ bản cho giao dịch cổ phiếu, tiền kỹ thuật số. Tuy nhiên, chỉ dựa trên hình dạng K-line của một chu kỳ thời gian duy nhất, dễ tạo ra tín hiệu giả, có rất nhiều không gian tối ưu hóa, cần xem xét thêm kết hợp nhiều yếu tố và điều chỉnh tham số để cải thiện hiệu quả của chiến lược.
/*backtest
start: 2023-12-08 00:00:00
end: 2024-01-07 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Buy/Sell on Candle Close", overlay=true)
var float prevLowest = na
var float prevHighest = na
var float slDistance = na
var float tpDistance = na
// Specify the desired timeframe here (e.g., "D" for daily, "H" for hourly, etc.)
timeframe = "D"
// Fetching historical data for the specified timeframe
pastLow = request.security(syminfo.tickerid, timeframe, low, lookahead=barmerge.lookahead_on)
pastHigh = request.security(syminfo.tickerid, timeframe, high, lookahead=barmerge.lookahead_on)
if bar_index > 0
prevLowest := pastLow[1]
prevHighest := pastHigh[1]
currentClose = close
if not na(prevLowest) and not na(prevHighest)
slDistance := prevHighest - prevLowest
tpDistance := 3 * slDistance // Adjusted for 1:3 risk-reward ratio
// Buy trigger when current close is higher than previous highest
if not na(prevLowest) and not na(prevHighest) and currentClose > prevHighest
strategy.entry("Buy", strategy.long)
strategy.exit("Buy TP/SL", "Buy", stop=prevLowest - slDistance, limit=prevHighest + tpDistance)
// Sell trigger when current close is lower than previous lowest
if not na(prevLowest) and not na(prevHighest) and currentClose < prevLowest
strategy.entry("Sell", strategy.short)
strategy.exit("Sell TP/SL", "Sell", stop=prevHighest + slDistance, limit=prevLowest - tpDistance)
plot(prevLowest, color=color.blue, title="Previous Lowest")
plot(prevHighest, color=color.red, title="Previous Highest")