
Chiến lược này dựa trên kích thước của đường dây để xác định và giao dịch các biến động giá quan trọng. Nó có thể kiểm soát chính xác bằng cách thiết lập ngưỡng điểm cụ thể, cửa sổ thời gian giao dịch và giới hạn số lần giao dịch mỗi ngày. Chiến lược được tối ưu hóa đặc biệt cho thị trường tương lai, có thể bắt được sự thay đổi giá đáng kể trong thời gian có tính thanh khoản cao.
Lý luận cốt lõi của chiến lược là tính toán chênh lệch điểm cao và thấp của mỗi đường dây và so sánh với ngưỡng dự kiến. Khi đường dây lớn hơn ngưỡng và trong cửa sổ thời gian giao dịch được chỉ định, hệ thống sẽ kích hoạt tín hiệu giao dịch đa không gian theo hướng của đường dây. Để kiểm soát rủi ro, chiến lược giới hạn chỉ thực hiện một giao dịch mỗi ngày và đặt điểm dừng lỗ.
Chiến lược này cung cấp một hệ thống giao dịch đáng tin cậy cho giao dịch tương lai thông qua kiểm soát điểm chính xác và lọc thời gian nghiêm ngặt. Ưu điểm của nó nằm ở độ chính xác và kiểm soát rủi ro khi thực hiện, nhưng cũng đòi hỏi các nhà giao dịch tối ưu hóa các tham số theo các giống cụ thể và tình hình thị trường. Bằng hướng tối ưu hóa được đề xuất, chiến lược có thể nâng cao hơn nữa khả năng thích ứng và ổn định của nó.
/*backtest
start: 2025-02-15 01:00:00
end: 2025-02-20 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"DOGE_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © omnipadme
//@version=5
strategy("Futures Candle Size Strategy (Start Trading on Jan 1, 2025)", overlay=true)
// Input for candle size threshold in ticks
candleSizeThresholdTicks = input.float(25, title="Candle Size Threshold (Ticks)", minval=1)
// Input for take profit and stop loss in ticks
takeProfitTicks = input.float(50, title="Take Profit (Ticks)", minval=1)
stopLossTicks = input.float(40, title="Stop Loss (Ticks)", minval=1)
// Time filter for trading (e.g., 7:00 AM to 9:15 AM CST)
startHour = input.int(7, title="Start Hour (CST)", minval=0, maxval=23)
startMinute = input.int(0, title="Start Minute (CST)", minval=0, maxval=59)
endHour = input.int(9, title="End Hour (CST)", minval=0, maxval=23)
endMinute = input.int(15, title="End Minute (CST)", minval=0, maxval=59)
// Tick size of the instrument (e.g., ES = 0.25)
tickSize = syminfo.mintick
// Convert tick inputs to price levels
candleSizeThreshold = candleSizeThresholdTicks * tickSize
takeProfit = takeProfitTicks * tickSize
stopLoss = stopLossTicks * tickSize
// Time range calculation
startTime = timestamp("GMT-6", year(timenow), month(timenow), dayofmonth(timenow), startHour, startMinute)
endTime = timestamp("GMT-6", year(timenow), month(timenow), dayofmonth(timenow), endHour, endMinute)
inTimeRange = (time >= startTime and time <= endTime)
// Filter to start trading only from January 1, 2025
startTradingDate = timestamp("GMT-6", 2025, 1, 1, 0, 0)
isValidStartDate = time >= startTradingDate
// Calculate the candle size for the current candle
candleSize = math.abs(high - low)
// Track whether a trade has been executed for the day
var hasTradedToday = false
isNewDay = dayofweek != dayofweek[1] // Detect new day
// Reset `hasTradedToday` at the start of a new day
if isNewDay
hasTradedToday := false
// Trigger condition for futures trading (only if no trade has been executed today)
triggerCondition = isValidStartDate and inTimeRange and candleSize >= candleSizeThreshold and not hasTradedToday
// Entry logic: If condition is met, enter a trade
if triggerCondition
hasTradedToday := true // Mark as traded for the day
if close > open // Bullish candle
strategy.entry("Buy", strategy.long)
if close < open // Bearish candle
strategy.entry("Sell", strategy.short)
// Set take profit and stop loss
strategy.exit("Exit Long", from_entry="Buy", limit=close + takeProfit, stop=close - stopLoss)
strategy.exit("Exit Short", from_entry="Sell", limit=close - takeProfit, stop=close + stopLoss)
// Alerts for triggered condition
if triggerCondition
alert("Candle size is " + str.tostring(candleSizeThresholdTicks) + " ticks or greater. Trade initiated.", alert.freq_once_per_bar)
// Color the alert candle white
barcolor(triggerCondition ? color.white : na)
// Visual aids for backtesting
bgcolor(isValidStartDate and inTimeRange ? color.new(color.green, 90) : na, title="Time and Date Range Highlight")