
この戦略は,QuantNomadが開発したUT Botの指標に基づいて,モバイルストップの思考を組み合わせている. @Yo_adriiiiaanが原始コードを書き,@HPotterが修正した. この戦略は,LuxAlgoのSmart Money Conceptsと連携して使用される. この戦略は現在,テスト段階にある.
この戦略の基本原則は以下の通りです.
この戦略は,UT Bot指標に基づいて,移動ストップの論理を加え,トレンド状況で利益を保護する役割を果たすことができる.同時に,戦略は多頭と空頭ポジションに別々にストップを設定し,適応性が強い.移動ストップの基準としてATRを使用すると,ストップの位置を動的に調整し,柔軟性を向上させることができる.しかし,この戦略は,振動状況で頻繁に損失がもたらされる高取引コストのリスクに直面し,移動ストップの設定が欠如し,誤った利益の可能性がある.さらに,パラメータの選択は,戦略のパフォーマンスに大きな影響を与える.
将来は,入場条件の最適化,より複雑な移動止損方法の探索,移動止損機構の加入,異なる品種と周期に対するパラメータの最適化など,戦略を完善して,より安定した利益を得ることができる.全体として,この戦略の考え方は単純でわかりやすく,理解しやすく,実行できますが,さらなる最適化の余地があり,引き続き探索し,改善する価値があります.
/*backtest
start: 2023-03-05 00:00:00
end: 2024-03-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Trailingstop", overlay=true)
if close > sma(close, 50)
strategy.entry("long", strategy.long)
// Trailing stop loss for long positions
Trailperc = 0.20
price_stop_long = 0.0
if (strategy.position_size > 0)
stopValue = close * (1 - Trailperc)
price_stop_long := max(stopValue, price_stop_long[1])
else
price_stop_long := 0
if (strategy.position_size > 0)
strategy.exit(id="stoploss_long", stop=price_stop_long)
// Trailing stop loss for short positions
Trailperc_short = 0.20
price_stop_short = 0.0
if (strategy.position_size < 0)
stopValue_short = close * (1 + Trailperc_short)
price_stop_short := min(stopValue_short, price_stop_short[1])
else
price_stop_short := 0
if (strategy.position_size < 0)
strategy.exit(id="stoploss_short", stop=price_stop_short)
// ATR Trailing Stop for visualization
keyvalue = input(3, title="Key Value. 'This changes the sensitivity'", step=0.5)
atrperiod = input(10, title="ATR Period")
xATR = atr(atrperiod)
nLoss = keyvalue * xATR
xATRTrailingStop = 0.0
xATRTrailingStop := iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss),
iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss),
iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))
pos = 0
pos := iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1,
iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0)))
xcolor = pos == -1 ? color.red: pos == 1 ? color.green : color.blue
plot(xATRTrailingStop, color = xcolor, title = "Trailing Stop")