ジョーカー移動ストップ戦略は,移動平均に基づくトレンド追跡戦略である.移動ストップと移動ストップの特性を組み合わせ,有利な方向に進むときに利益を最大限にロックすることを目的としている.また,不利な方向に進むときにできるだけ早く損失を止めることができる.
この戦略は,高速移動平均と遅い移動平均を使ってトレンドフィルターを構築する.高速移動平均の上に遅い移動平均を横切るときは,多めに行い,高速移動平均の下に遅い移動平均を横切るときは,空いて行きます.
戦略は,配置されたストップパーセンテージに基づいて最初のストップ価格を計算します. 移動ストップ機能が有効になっている場合,取引品種の最小変動価格と配置された移動ストップパーセンテージに基づいて移動ストップのステップサイズを計算します.
ポジション保持方向が信号方向と一致している場合,移動ストップが有効でない場合は,限値単発のスミッター方式でストップ;移動ストップが有効である場合は,ステップサイズに応じてストップ価格を継続的に調整する追跡ストップ方式を使用します.
移動平均を使って主要トレンドの方向を判断し,市場ノイズによる戦略の干渉を避ける.
モバイルストップを有効にすると,市場動向に応じてストップの位置を調整することができ,ストップの位置が常に価格に緊密に付いていることを保証します. これは,固定ストップの価格を設定するよりも柔軟で効率的です.
移動ストップは,より多くの利益をロックし,戦略の落札のリスクを軽減します. また,固定ストップのみを設定すると,ストップ位置があまりにも保守的で,利益を早期にロックする問題を回避します.
モバイルストップは,不良な動きが起きた時に,できるだけ早くストップできるという,設定されたストップの利点を維持している.
移動平均は価格が激しく波動するときに誤信号または信号遅れが形成されやすい.これは戦略逆転のポジション損失につながる可能性がある.移動平均のパラメータを適切に調整するか,またはフィルターを追加して最適化することができます.
ストップ比率を過大に設定すると,戦略のポジション保持時間が増加し,実際のストップ価格と理論価格の偏差が増加します.ストップ比率を適切に低減することで,このリスクが軽減されます.
モバイルストップのステップ比が小さすぎると,移動頻度が高くなり,取引費用と滑り場リスクが増加する. モバイルストップのステップを適切に調整して最適化することができます.
移動ストップは,撤回を考慮せず,単面的な動きのみを考慮する。これは,価格が再び逆転することを意味し,移動ストップは下調しない。これは,ストップの最終的な実行価格が理論価格から偏っていることを引き起こす。双面的な移動ストップの仕組みを考慮して最適化することができる。
市場の変動率の動向に応じて移動平均のパラメータを調整し,波動が大きくなる時に周期を拡大し,波動が小さくなる時に周期を縮小することを考えることができる.
異なる品種や市場の特徴を研究し,異なるデフォルトのストップ比率を設定し,ストップ偏差のリスクを低減します.
双方向の移動ストップの仕組みを研究することができる.価格が新しい高点に達したときにストップを上へと移動し,引き下がったときにストップを下へと移動し,ストップを価格に近くさせる.
トレンド強度指標と組み合わせて,トレンド強度が弱いときにストップ比率を下げ,トレンド強度が強いときにストップ比率を増やすことも考えられます.
機械学習モデルと組み合わせて,モデルが予測した価格区間を利用して,ストップスロープ比率を動的に設定することを考えることができます.
ジョーカーの移動ストップ戦略は,トレンドの方向を判断するために移動平均を使用し,その後,移動ストップ位置を動的に調整して利益をロックする.移動ストップと移動ストップの両方の利点を持ち,トレンドを効果的に追跡しながらリスクを制御することができます.パラメータの最適化と停止メカニズムの改善により,戦略をさらに完善させ,より複雑な市場環境に対応することができます.全体的に,この戦略はさらなる研究と応用に値する.
/*backtest
start: 2023-08-23 00:00:00
end: 2023-09-22 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(title='Joker Trailing TP Bot', shorttitle='Joker TTP Bot', overlay=true, pyramiding=0, process_orders_on_close=false, close_entries_rule='ANY', calc_on_every_tick=false, calc_on_order_fills=false, commission_type=strategy.commission.percent, commission_value=0.07, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000, currency=currency.USD) //, max_labels_count=500)
fromDate = input(timestamp('01 Jan 2021 00:00 UTC'), 'From Date')
toDate = input(timestamp('31 Dec 2121 23:59 UTC'), 'To Date')
fastMALen = input.int(23, 'Fast SMA Length')
slowMALen = input.int(50, 'Slow SMA Length')
longTakeProfitPerc = input.float(0.5, 'Long Take Profit %', minval=0.05, step=0.05) * 0.01
shortTakeProfitPerc = input.float(0.5, 'Short Take Profit %', minval=0.05, step=0.05) * 0.01
enableTrailing = input.bool(true, 'Enable Trailing')
trailingTakeProfitPerc = input.float(0.01, 'Trailing Take Profit %', minval=0.01, maxval=100, step=0.01) * 0.01
float fastMA = ta.sma(close, fastMALen)
float slowMA = ta.sma(close, slowMALen)
bool isWithinPeriod = true
bool openLongPosition = isWithinPeriod and ta.crossover(fastMA, slowMA)
bool openShortPosition = isWithinPeriod and ta.crossunder(fastMA, slowMA)
bool longIsActive = openLongPosition or strategy.position_size > 0
bool shortIsActive = openShortPosition or strategy.position_size < 0
float longTakeProfitPrice = na
longTakeProfitPrice := if longIsActive
if openLongPosition and not (strategy.position_size > 0)
close * (1 + longTakeProfitPerc)
else
nz(longTakeProfitPrice[1], close * (1 + longTakeProfitPerc))
else
na
float shortTakeProfitPrice = na
shortTakeProfitPrice := if shortIsActive
if openShortPosition and not (strategy.position_size < 0)
close * (1 - shortTakeProfitPerc)
else
nz(shortTakeProfitPrice[1], close * (1 - shortTakeProfitPrice))
else
na
float longTrailingTakeProfitStepTicks = longTakeProfitPrice * trailingTakeProfitPerc / syminfo.mintick
float shortTrailingTakeProfitStepTicks = shortTakeProfitPrice * trailingTakeProfitPerc / syminfo.mintick
strategy.entry(id = 'Long Entry', direction = strategy.long, when = openLongPosition, alert_message = 'Long(' + syminfo.ticker + '): Started')
strategy.entry(id = 'Short Entry', direction = strategy.short, when = openShortPosition, alert_message = 'Short(' + syminfo.ticker + '): Started')
strategy.exit(id = 'Long Take Profit', from_entry = 'Long Entry', limit = enableTrailing ? na : longTakeProfitPrice, trail_price = enableTrailing ? longTakeProfitPrice : na, trail_offset = enableTrailing ? longTrailingTakeProfitStepTicks : na, when = longIsActive, alert_message = 'Long(' + syminfo.ticker + '): Take Profit activated')
strategy.exit(id = 'Short Take Profit', from_entry = 'Short Entry', limit = enableTrailing ? na : shortTakeProfitPrice, trail_price = enableTrailing ? shortTakeProfitPrice : na, trail_offset = enableTrailing ? shortTrailingTakeProfitStepTicks : na, when = shortIsActive, alert_message = 'Short(' + syminfo.ticker + '): Take Profit activated')
plot(series = fastMA, title='Fast SMA', color = color.blue, linewidth = 1, style = plot.style_line)
plot(series = slowMA, title='Slow SMA', color = color.orange, linewidth = 1, style = plot.style_line)
plot(series = longTakeProfitPrice, title='Long Take Profit', color = color.green, linewidth = 1, style = plot.style_cross, offset = 1)
plot(series = shortTakeProfitPrice, title='Short Take Profit', color = color.red, linewidth = 1, style = plot.style_cross, offset = 1)
plot(series = strategy.position_avg_price, title='Position', color = color.white, linewidth = 1, style = plot.style_linebr)