
これは,ATR (平均真範囲) 指標に基づくトレンド追跡戦略で,ダイナミックストップと均線交差信号を組み合わせている.この戦略はATRを計算して市場の変動を決定し,この情報を使用してダイナミックストップを設定する.価格とEMA (移動平均) がATRトラッキングストップラインを破るとき,取引信号を生成する.この戦略は,通常のK線または平安K線を使用して計算するオプションも提供しており,戦略の柔軟性を高めています.
戦略の核心的な論理は,以下のいくつかの重要な計算に基づいています.
これは,ダイナミックなストップ・ローズと均線システムを組み合わせた完全な取引戦略である.ATR指標によって市場の波動特性を捉え,均線交差を利用して取引シグナルを提供し,論理的に厳格な取引システムを形成する.戦略の優位性は,そのダイナミックな適応性とリスク管理能力にあるが,横軸市場のパフォーマンスにも注意する必要がある.推奨された最適化方向によって,戦略にはさらに向上する余地がある.
/*backtest
start: 2024-05-15 00:00:00
end: 2024-08-08 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy(title="UT Bot Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// Inputs
a = input.float(1, title="Key Value. 'This changes the sensitivity'")
c = input.int(10, title="ATR Period")
h = input.bool(false, title="Signals from Heikin Ashi Candles")
// Calculate ATR
xATR = ta.atr(c)
nLoss = a * xATR
// Source for calculations
src = h ? request.security(syminfo.tickerid, timeframe.period, hlc3) : close
// ATR Trailing Stop logic
var float xATRTrailingStop = na
if (not na(xATRTrailingStop[1]) and src > xATRTrailingStop[1] and src[1] > xATRTrailingStop[1])
xATRTrailingStop := math.max(xATRTrailingStop[1], src - nLoss)
else if (not na(xATRTrailingStop[1]) and src < xATRTrailingStop[1] and src[1] < xATRTrailingStop[1])
xATRTrailingStop := math.min(xATRTrailingStop[1], src + nLoss)
else
xATRTrailingStop := src > xATRTrailingStop[1] ? src - nLoss : src + nLoss
// Position logic
var int pos = 0
if (not na(xATRTrailingStop[1]) and src[1] < xATRTrailingStop[1] and src > xATRTrailingStop[1])
pos := 1
else if (not na(xATRTrailingStop[1]) and src[1] > xATRTrailingStop[1] and src < xATRTrailingStop[1])
pos := -1
else
pos := pos[1]
xcolor = pos == -1 ? color.red : pos == 1 ? color.green : color.blue
// Entry and Exit Signals
ema = ta.ema(src, 1)
above = ta.crossover(ema, xATRTrailingStop)
below = ta.crossover(xATRTrailingStop, ema)
buy = src > xATRTrailingStop and above
sell = src < xATRTrailingStop and below
// Strategy Execution
if (buy)
strategy.entry("UT Long", strategy.long)
if (sell)
strategy.entry("UT Short", strategy.short)
// Plotting and Alerts
plotshape(buy, title="Buy", text='Buy', style=shape.labelup, location=location.belowbar, color=color.green, textcolor=color.white, size=size.tiny)
plotshape(sell, title="Sell", text='Sell', style=shape.labeldown, location=location.abovebar, color=color.red, textcolor=color.white, size=size.tiny)
barcolor(src > xATRTrailingStop ? color.green : src < xATRTrailingStop ? color.red : na)
alertcondition(buy, title="UT Long", message="UT Long")
alertcondition(sell, title="UT Short", message="UT Short")