该策略基于蜡烛线大小来识别和交易重要的价格走势。它通过设定具体的点数阈值、交易时间窗口和每日交易次数限制来实现精确控制。策略专门针对期货市场进行了优化,可以在高流动性时段捕捉显著的价格变动。
策略的核心逻辑是通过计算每根蜡烛线的高低点差值(以点数为单位),并与预设的阈值进行比较。当蜡烛线大小超过阈值且在指定的交易时间窗口内(默认为美中时间7:00-9:15),系统会根据蜡烛线的方向触发多空交易信号。为了控制风险,策略限制每天只执行一次交易,并设置了止盈止损点位。
该策略通过精确的点数控制和严格的时间过滤,为期货交易提供了一个可靠的交易系统。它的优势在于执行的精确性和风险控制,但也需要交易者根据具体品种和市场情况进行参数优化。通过建议的优化方向,策略可以进一步提升其适应性和稳定性。
/*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")