
最後のK線策略は,最後のK線の終値と開値の関係を分析して市場のトレンド方向を判断し,取引シグナルを生成するトレンド追跡策略である.
この戦略の核心的な論理は:
具体的には,戦略では,最後のK線の開場価格と閉場価格のデータを要求し,価格比較の結果に基づいてトレンド方向を判断する. 上昇傾向の場合,K線の閉場時に市価単価で多項を開きます. 下降傾向の場合,K線の閉場時に市価単価で空券を開きます.
その後,ストップとストップの価格を設定します. 多項のストップは,K線の開閉価格に係数で掛けられ,ストップは,現在の閉閉価格になります. 空券は,逆になります. 価格がストップまたはストップを触発すると,対応するポジションは平仓で退出されます.
トレンド指標の確認,ストップ・ストップの論理の最適化,反測周期の拡張,市場環境との組み合わせによりリスクを低減することができる.
最後のK線戦略は,簡単なトレンド追跡戦略である。それは,最後のK線によって,トレンドの方向を素早く判断し,取引する。戦略の論理はシンプルで,実行しやすい.トレンド追跡の理念に合致する。同時に,ストップとストップを設定してリスクを制御する。しかし,最後のK線だけに頼りやすいので,トレンド指標と組み合わせるべきである。さらに,この戦略を使用すると,拡張する余地があり,より多くの技術指標や機械学習モデルを導入してパフォーマンスを向上させることができる。
/*backtest
start: 2022-12-14 00:00:00
end: 2023-12-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Last Candle Strategy with Date Range", overlay=true)
// Define the start and end dates for the backtest
startDate = timestamp(2015, 01, 01, 00, 00)
endDate = timestamp(2023, 11, 24, 23, 59)
// Check if the current bar is within the specified date range
withinDateRange = time >= startDate and time <= endDate
// If outside the date range, skip the strategy logic
if (not withinDateRange)
strategy.close_all()
// Calculate the opening and closing values for the last candle
lastCandleOpen = request.security(syminfo.tickerid, "D", open[1], lookahead=barmerge.lookahead_on)
lastCandleClose = request.security(syminfo.tickerid, "D", close[1], lookahead=barmerge.lookahead_on)
// Determine the trade direction based on the last candle
tradeDirection = lastCandleOpen < lastCandleClose ? 1 : -1 // 1 for buy, -1 for sell
// Plot the last candle's opening and closing values on the chart
plot(lastCandleOpen, color=color.blue, title="Last Candle Open")
plot(lastCandleClose, color=color.red, title="Last Candle Close")
// Execute strategy orders
if (withinDateRange)
if (tradeDirection == 1)
strategy.entry("Buy", strategy.long)
if (tradeDirection == -1)
strategy.entry("Sell", strategy.short)
// Set stop loss and take profit
stopLoss = 0.01 * lastCandleOpen
takeProfit = close
// Exit strategy
strategy.exit("StopLoss/Profit", from_entry="Buy", loss=stopLoss, profit=takeProfit)
strategy.exit("StopLoss/Profit", from_entry="Sell", loss=stopLoss, profit=takeProfit)