本策略名称为“基于随机运气的简单交易策略”。该策略使用随机方法在每周首日产生做多或做空信号,通过大量重复测试评估随机交易的效果。
具体来说,策略的交易逻辑非常简单直白:
每周一投掷一枚硬币,随机生成头或尾的结果。
如果是头,则在当日做多;如果是尾,则在当日做空。
做多时,设置止损为1倍ATR,止盈为1倍ATR;做空同理,实现1:1的风险回报比。
持仓至本周末平仓。
该策略的优势在于回测大量年份的数据,可评估随机交易的平均胜率。交易规则极简单,可作为策略比较的基准线。
但随机交易无法利用市场规律,难以持续获得正收益。止盈止损固定也易造成亏损扩大。交易者仅可将其作为实验性策略,不能用于实盘。
总体来说,数据回测可以提示随机交易的效果,但不代表可实际运用的策略。交易者最终还是需要判断力与系统的交易技巧。
/*backtest
start: 2022-09-12 00:00:00
end: 2023-01-12 00:00:00
period: 2d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("CoinFlip", overlay = true)
int result = int(math.random()+0.5)
atr_period = input(defval = 20, title = "ATR Period")
year_to_test = input(defval = 2022, title = "Year to Test")
day_of_week = input(defval = 1, title = "Day of Week")
atr = ta.atr(atr_period)
shouldSell = result == 0 and dayofweek == day_of_week
shouldBuy = result == 1 and dayofweek == day_of_week
plotshape(result == 0 and dayofmonth == day_of_week, title="sell", location=location.abovebar, color=color.red, transp=0, style=shape.arrowdown)
plotshape(result == 1 and dayofmonth == day_of_week, title="buy", location=location.belowbar, color=color.lime, transp=0, style=shape.arrowup)
strategy.entry("short entry", strategy.short, 1000 / (1*atr), when=shouldSell and year == year_to_test)
strategy.entry("long entry", strategy.long, 1000 / (1*atr), when=shouldBuy and year == year_to_test)
strategy.exit("exit", "long entry", limit = close + 1*atr, stop = close - 1*atr, when = shouldBuy)
strategy.exit("exit", "short entry", limit = close - 1*atr, stop = close + 1*atr, when = shouldSell)