
この戦略は、動的なストッププロフィットとストップロスのメカニズムと組み合わせた、二重移動平均クロスオーバー信号に基づくトレンド追跡システムです。この戦略では、5 期間および 12 期間の単純移動平均 (SMA) を使用して取引シグナルを生成し、利益確定レベルと損失停止レベルを動的に調整することでリスク リターン比を最適化します。当初のテイクプロフィットは10%に設定され、ストップロスは5%に設定されます。価格が有利な方向に動くと、テイクプロフィットレベルは20%に調整され、ストップロスは2.5%に引き下げられます。利益を守るため。
この戦略のコアロジックは、高速移動平均 (5 期間) と低速移動平均 (12 期間) 間のクロスオーバー関係に基づいています。高速ラインが低速ラインを下から上に横切ると、システムはロング シグナルを生成し、ポジションを開きます。高速ラインが低速ラインを上から下に横切ると、システムはポジションを閉じます。この戦略のユニークさは、動的なリスク管理メカニズムにあります。ポジションが確立されると、システムは価格動向をリアルタイムで監視し、価格の変化に応じて利益確定レベルと損切りレベルを動的に調整して、リスクを管理しながら利益を最大化します。 。
この戦略は、従来の移動平均クロスオーバー信号と革新的な動的リスク管理メカニズムを組み合わせることで、トレンドの効果的な把握とリスクの動的な制御を実現します。戦略設計コンセプトは明確で、実装方法は簡潔かつ効果的であり、実用性と拡張性に優れています。この戦略は、継続的な最適化と改善を通じて、実際の取引において安定した利益実績を達成することが期待されます。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-25 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("My Moving Average Crossover Strategy with Take Profit and Stop Loss", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
//risk_free_rate = float(request.security("IRUS", "D", close)/request.security("IRUS", "D", close[1]) - 1 ))
// MA periods
fastLength = input.int(5, title="Fast MA Length")
slowLength = input.int(12, title="Slow MA Length")
// Take Profit and Stop Loss
takeProfitLevel = input(10, title="Take Profit (пункты)") // Take profit % from the last price
stopLossLevel = input(5, title="Stop Loss (пункты)") // Stop loss % from the last price
takeProfitLevel_dyn = input(20, title="Dynamic Take Profit (пункты)") // Move TP if current_price higher buy_px
stopLossLevel_dyn = input(2.5, title="Dynamic Stop Loss (пункты)") // S Move SL if current_price higher buy_px
// Вычисление скользящих средних
fastMA = ta.sma(close, fastLength)
slowMA= ta.sma(close, slowLength)
// Conditions for Sell and Buy
longCondition = ta.crossover (fastMA, slowMA) // покупаем, если короткая MA персекает длинную снизу-вверх
shortCondition = ta.crossunder(fastMA, slowMA) // продаем, если короткая MA персекает длинную сверху-вниз
// Buy position condition
if (longCondition)
strategy.entry("Buy", strategy.long)
// Dynamic TP SL leveles
takeProfitPrice = strategy.position_avg_price * (1+ takeProfitLevel / 100)
stopLossPrice = strategy.position_avg_price * (1-stopLossLevel / 100)
entryPrice = strategy.position_avg_price
if (strategy.position_size > 0) // если есть открытая позиция
// takeProfitPrice := entryPrice * (1+ takeProfitLevel / 100)
// stopLossPrice := entryPrice * (1-stopLossLevel / 100)
// // Перемещение Stop Loss и Take Profit
if (close > entryPrice)
takeProfitPrice := close * (1+ takeProfitLevel_dyn / 100)
stopLossPrice := close * (1- stopLossLevel_dyn/ 100)
if (shortCondition)
strategy.close("Buy")
strategy.exit("Take Profit/Stop loss", "Buy", limit=takeProfitPrice, stop=stopLossPrice)
// Drawing MA lines
plot(fastMA, color=color.blue, title="Fast Moving Average")
plot(slowMA, color=color.orange, title="Slow Moving Average")
// Визуализация
plot(longCondition ? na : takeProfitPrice, title="Take Profit Level", color=color.green, linewidth=1, style=plot.style_line)
plot(longCondition ? na: stopLossPrice, title="Stop Loss Level", color=color.red, linewidth=1, style=plot.style_line)