
この戦略は,ストップ・ローズを動的に調整することでトレンドを追跡する目的を達成するために,ストップ・ローズを動的に調整する.価格が有利な方向に移動すると,ストップ・ローズもそれに合わせて調整され,得られる利益をロックします.価格が不利な方向に移動すると,ストップ・ローズは変わらない.価格がストップ・ローズに触れたら,ストップ・ローズは平らになります.この戦略の鍵は,ストップ・ポジションの動的調整にあります.
ATRトラッキングストップ戦略は,価格変動幅度に応じてストップポジションを動的に調整できるので,トレンドの状況で良い効果が得られます.しかし,この戦略は,震動市場,ストップが頻繁すぎ,空飛ぶギャップを避けるのが難しいなどのリスクにも対応できません.上記の欠陥に対して,トレンド判断,ストップ戦略,最大ストップ制限などの面で戦略を最適化および改善することができます.これらの調整により,戦略の適応性と収益性を高める見込みがあります.
/*backtest
start: 2024-04-01 00:00:00
end: 2024-04-30 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Long TAP", overlay=true)
// Constants
keyValueDefault = 3.0
keyValueStep = 0.5
atrPeriodDefault = 10
// Inputs
keyValue = input.float(keyValueDefault, title="Key Value")
atrPeriod = input.int(atrPeriodDefault, title="ATR Period")
// Calculations
xATR = ta.atr(atrPeriod)
nLoss = keyValue * xATR
// Trailing Stop Calculation
var float xATRTrailingStop = 0.0
xATRTrailingStop := ta.highest(math.max(nz(xATRTrailingStop[1], 0), close - nLoss), 1)
xATRTrailingStop := ta.lowest(math.min(nz(xATRTrailingStop, 0), close + nLoss), 1)
// Position Calculation
var int pos = 0
pos := nz(pos[1], 0)
if (close[1] < nz(xATRTrailingStop, 0) and close > nz(xATRTrailingStop, 0))
pos := 1
else if (close[1] > nz(xATRTrailingStop, 0) and close < nz(xATRTrailingStop, 0))
pos := -1
// Plotting Trailing Stop
var color xcolor = na
if (pos == -1)
xcolor := color.red
else if (pos == 1)
xcolor := color.green
plot(xATRTrailingStop, color=xcolor, title="Trailing Stop")
// Buy/Sell Signals
buySignal = ta.crossover(close, xATRTrailingStop)
sellSignal = ta.crossunder(close, xATRTrailingStop)
// Strategy
if (buySignal)
strategy.entry("Long", strategy.long)
label.new(bar_index, xATRTrailingStop, text="Buy Signal", color=color.green, style=label.style_label_up, yloc=yloc.belowbar)
if (sellSignal)
strategy.entry("Short", strategy.short)
label.new(bar_index, xATRTrailingStop, text="Sell Signal", color=color.red, style=label.style_label_down, yloc=yloc.abovebar)
// Alerts
alertcondition(buySignal, title='UT BOT Buy', message='UT BOT Buy')
alertcondition(sellSignal, title='UT BOT Sell', message='UT BOT Sell')