この戦略は,ATR指数を使用して動的ストロップポイントを設定し,価格の変動幅に応じてストロップポジションを調整し,リスク制御を実現する.この戦略は,主に5日EMAと20日EMAを形成し,金叉を複数入場し,その後ATR指数を使用してストロップポジションとストップブックポジションを設定する.ストロップポジションは,価格の変動状況に応じて調整され,より多くの利益をロックする.
この戦略は,まず,第5日EMA上を第20日EMAが金叉を形成する時に多入場を行うことを判断する.入場後,ATR指数を使用して入場価格から現在の価格のATR倍数を計算し,入場価格の下1.5ATRのストップロスを設定する.そして,価格が上昇するにつれて,徐々にストップロスを上げ,入場価格3ATRを超えた場合,部分停止する.
具体的には,以下のような変数を定義します.
入場後,atr_refを現在のATR数,atr_divを入場価格から現在の価格のATR倍数として計算する.そしてatr_divに基づいてatr_down,atr_current,atr_upの位置を設定する.ストップ_プライスは入場価格より1.5ATR下である.
価格が上昇するにつれて,現在の価格avgとatr_upを比較し,avgにatr_upが加えられた場合,atr_divとatrの対応位置を再計算し,ストップラインを段階的に上げ,保有利潤を増やす.
価格が入場価格3ATRを超えた場合,利益をロックするために部分的に平仓する.このとき,tookProfit標識がtrueに設定されます.その後,価格が上昇し続けると,止損位置を上昇させ続ける.止損を触発すると,tookProfitを判断し,以前は部分的に止まった場合,残りのポジションを平仓する,または全ポジションを平仓する.
ATR指標の動的調整により,市場の波動程度に応じて合理的なストップ距離を設定できます.
損失が限られている場合,トレンドの動きに従って利潤をカットする. 止損線は徐々に上昇し,利潤が蓄積される.
部分ストップメカニズムは,利益の一部をロックし,リスクを軽減します. その後,ストップ・ロッドの位置は上昇し続け,利益は継続します.
ATR指標は異常突破に対して無感で,ギャップによるリスクに対応できない.
EMAはトレンドの逆転を判断できず,トレンドが逆転したときに新たなポジションに入れる可能性があります.
部分停止後,損失を逆転させる可能性が高くなります.
パラメータの最適化は不十分で,1.5ATR止損と3ATR止は異なる品種に応じて調整する必要がある.
ATR指標の遅れを防ぐために,ドンキアン通路などの他のストップダメージ指標の追加を検討することができます.
異なる平均線指標をテストしたり,MACDなどのトレンド反転を判断したりできます.
部分停止の割合と回数を最適化できます.異なる品種には異なる設定があります.
パラメータの最適化を追加し,異なるATR倍数の止損停止効果をテストする. ステップ止損停止機能を追加する.
トレンドが弱くるときのパフォーマンスをテストし,トレンドが強くなるときにのみこの戦略を有効にすることを検討してください.
この戦略の全体的な構想は明確で分かりやすく,ATR指標を動的に調整して取引リスクを制御するのが最大の優位性である。しかしATR指標自体は遅滞性があり,パラメータ設定は最適化が必要である。他の止まりとトレンド判断指標を加えれば改善方向となる。さらに,部分止まり機構も,異なる品種に応じて最適化テストが必要である。全体的に,この戦略はATRを利用して損失管理を行う一つの構想を提供しているが,さらなる最適化と完善が必要である。
/*backtest
start: 2022-10-03 00:00:00
end: 2023-10-09 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ekinbasarkomur
//@version=5
strategy("[EKIN] ATR Exit Strategy", overlay=true, initial_capital = 1000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, calc_on_every_tick = true)
// Simple EMA tracking
fastEMA = ta.ema(close, 5)
slowEMA = ta.ema (close, 20)
atr = ta.atr(14)
// We define entry price for future reference
var float entry_price = na
// We define stop and take profit for future calculations
var float stop_price = na
var float take_profit_price = na
// We define atr limtim its here
var float atr_down = na
var float atr_up = na
var float atr_current = na
var float atr_ref = na
avg = (low + high) / 2
// Conditions
enterCondition = ta.crossover(fastEMA, slowEMA)
var bool tookProfit = false
timePeriod = time >= timestamp(syminfo.timezone, 2021, 12, 15, 0, 0)
InTrade = strategy.position_size > 0
// Go long if conditions are met
if (enterCondition and timePeriod and not InTrade)
// Calculate and update variables
entry_price := avg
atr_ref := atr
atr_div = int((avg - entry_price) / atr_ref)
atr_down := entry_price + (atr_ref * (atr_div - 1.5))
atr_up := entry_price + (atr_ref * (atr_div + 1))
atr_current := entry_price + (atr_ref * atr_div)
stop_price := (entry_price - (atr_ref * 1.5))
take_profit_price := (entry_price + (atr_ref * 3))
strategy.order("buy", strategy.long, qty = 2)
// Enter here if in position
if InTrade or tookProfit
stopCondition = avg < stop_price
takeProfitCondition = avg > take_profit_price
if avg < atr_down
stopCondition := true
// Move stop price and exit price if price for each atr price increase
if avg > atr_up
if tookProfit
atr_ref := atr
atr_div = int((avg - entry_price) / atr_ref)
atr_down := entry_price + (atr_ref * (atr_div - 1))
atr_up := entry_price + (atr_ref * (atr_div + 1))
atr_current := entry_price + (atr_ref * atr_div)
// Take half of the investment if current price is 3 atr higher than entry price
if (takeProfitCondition and timePeriod and InTrade and not tookProfit)
strategy.order("take_half_profit", strategy.short, qty = 1)
tookProfit := true
// Exit position if conditions are met and reset the variables
if (stopCondition and timePeriod and InTrade)
if tookProfit
strategy.order("exit", strategy.short, qty = 1)
else
strategy.order("stop_loss", strategy.short, qty = 2)
tookProfit := false
// Plot EMA's
plot(fastEMA, color = color.blue)
plot(slowEMA, color = color.yellow)
// Plot ATR Limit/Stop positions
profit_plot = plot(series = InTrade?atr_up:na, title = "profit", color = color.green, style=plot.style_linebr)
close_plot = plot(series = InTrade?atr_current:na, title = "close", color = color.white, style=plot.style_linebr)
stop_plot = plot(series = InTrade?atr_down:na, title = "stop_loss", color = color.red, style=plot.style_linebr)
fill(profit_plot, close_plot, color = color.new(color.green, 80))
fill(close_plot, stop_plot, color =color.new(color.red,80))