この戦略は,週末の価格変動に特化して取引し,事前に設定された上昇幅の範囲で多空方向を判断する.
戦略の原則:
先週の金曜日の閉店価格を参考にして,上下幅の区間を設定します.例えば,区間の上限は閉店価格の4.5%の上昇です.
価格が区画の上限を超えると空白操作を行う.価格が下限を下回ると多操作を行う.
既にあるポジションの場合は,新しい層を超えた区間に応じて,空きや増額などでポジションを継続する.
累積利益が一定比率に達すると,平仓止まり,例えば10%。
一度に最大2方向のポジション. 月曜の開盤前には全ポジションをクリアする.
この戦略の利点は
固定の上昇・下降区間を設定し,機械的な操作を行う.
段階的な加仓により,よりよいコスト価格が得られます.
周期的法則は安定し,基本面に影響されない.
この戦略のリスクは
単一の損失の大きさを制限することはできません.単一の損失の大きなリスクがあります.
固定パラメータは,異なる時間帯の市場の変動率に対応することはできません.
周期的法則が変化し,モデルが失敗するリスクが生じます.
要するに,この戦略は周期的法則を利用して頻繁な取引を行うが,一定の利益ロックが難しい問題がある.パラメータの失敗と単一損失の過大リスクに注意し,慎重に操作する必要がある.
/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-12 00:00:00
period: 2d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
//Copyright Boris Kozak
// strategy("XBT Weekend Trade Strategy", overlay=true, default_qty_type=strategy.percent_of_equity,)
strategy.initial_capital=50000
leverage = input(10,"Leverage")
profitTakingPercentThreshold = input(0.10,"Profit Taking Percent Threshold")
//****Code used for setting up backtesting.****///
testStartYear = input(2017, "Backtest Start Year")
testStartMonth = input(12, "Backtest Start Month")
testStartDay = input(10, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear = input(2025, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(30, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FFFF : na
bgcolor(testPeriodBackgroundColor, transp=50)
testPeriod() => true
//****END Code used for setting up backtesting.****///
//*** Main entry point is here***//
// Figure out how many days since the Friday close
days_since_friday = if dayofweek == 6
0
else
if dayofweek == 7
1
else
if dayofweek == 1
2
else
if dayofweek == 2
3
else
if dayofweek == 3
4
else
if dayofweek == 4
5
else
6
// Grab the Friday close price
fridaycloseprice = security(syminfo.ticker,'D',close[days_since_friday])
plot(fridaycloseprice)
// Only perform backtesting during the window specified
if testPeriod()
// If we've reached out profit threshold, exit all positions
if ((strategy.openprofit/strategy.initial_capital) > profitTakingPercentThreshold)
strategy.close_all()
// Only execute this trade on saturday and sunday (UTC)
if (dayofweek == 7.0 or dayofweek == 1.0)
// Begin - Empty position (no active trades)
if (strategy.position_size == 0)
// If current close price > threshold, go short
if ((close>fridaycloseprice*1.045))
strategy.entry("Short Entry", strategy.short, leverage)
else
// If current close price < threshold, go long
if (close<(fridaycloseprice*0.955))
strategy.entry("Long Entry",strategy.long, leverage)
// Begin - we already have a position
if (abs(strategy.position_size) > 0)
// We are short
if (strategy.position_size < 0)
if ((close>strategy.position_avg_price*1.045))
// Add to the position
strategy.entry("Adding to Short Entry", strategy.short, leverage)
else
if ((close<strategy.position_avg_price*0.955))
strategy.entry("Adding to Long Entry",strategy.long,leverage)
// On Monday, if we have any open positions, close them
if (dayofweek==2.0)
strategy.close_all()