ストップ・ロスの2段階戦略

作者: リン・ハーンチャオチャン開催日:2023年10月25日 18:11:30
タグ:

img

概要

この戦略の主な考え方は,利益目標の2つを設定し,最初の目標を達成した後,ストップ損失をエントリー価格に移動することです.

戦略の論理

この戦略は,ボリンジャーバンドとストーカスティック指標に基づいて取引を行う.価格がボリンジャー上部バンドを超えるとショートになり,ストーカスティックが過売りを示したときにロングする.

具体的には,入力論理は:

  1. ストーカスティックKはDを下回る. ストーカスティックKはDを下回る

  2. ストーカスティックKがDを横切るとき ストーカスティックKがDを横切るとき

戦略では,TP1が200ポイントとTP2が500ポイントと決まった2つの利益目標が設定されています.

価格が動いてTP1が起動すると,ストップ・ロスはエントリー価格に移動します.これは最初の段階から利益をロックし,ストップ・ロスの狩りを防止します.

この戦略は,TP2またはストップ・ロスが起動すると,すべてのポジションを閉じる.

利点分析

この2段階ストップ損失アプローチの最大の利点は,ストップ損失狩りを防止しながら利益をロックできるようにすることです.ストップ損失をエントリー価格に移動することにより,ストップ損失狩りの確率を軽減し,利益を保護します.

また,ボリンジャー帯とストキャスティックが混在して波動範囲を測定することで,買い過ぎ/売過ぎのエントリがより正確になります.

リスク分析

主なリスクは,ボリンジャーバンドやストーカスティック指標からの潜在的な誤った信号から生じる.不正なボリンジャーレンジは,入力が欠落したり,信号が悪いことにつながる.ストーカスティック誤ったブレイクも誤った入力を引き起こします.

また,エントリー価格に移行した後に再びストップロスが追われるリスクもあります.V形の逆転は2度目のストップロスを引き起こす可能性があります.

これらのリスクは,両方の指標のパラメータを最適化し,ストップ損失間の距離を増加することによって軽減できます.

オプティマイゼーションの方向性

この戦略のさらなる最適化:

  1. Bollinger と Stochastic の最適なパラメータを見つけるために異なるパラメータの組み合わせをテストします.

  2. 理想的な設定を見つけるために 異なる利益/損失目標をテストします

  3. 移動平均値などの他の指標を追加して 複数の指標システムを作成して より正確な結果が得られます

  4. 入場価格の代わりに 入場からの固定距離のような 代替ストップ損失ポジショニングロジックを研究します

  5. ストップ・ロスの動きを 3 段階以上まで増加させる.

結論

この戦略は,ボリンジャーバンドとストーカスティックを使用してエントリを行い,2つの取利益目標を設定し,最初のターゲットに達した後,ストップロスをエントリに移動して2段階のストップロスを形成します.これは利益を効果的にロックし,ストップロスの狩りを防止します.戦略には明確な利点がありますが,パラメータ最適化,マルチインジケーターシステム,ストップロスの論理調整を通じて改善の余地もあります.


/*backtest
start: 2022-10-18 00:00:00
end: 2023-10-24 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/
// © fpsd4ve

//@version=5

// Add Bollinger Bands indicator (close, 20, 2) manually to visualise trading conditions
strategy("2xTP, SL to entry", 
     overlay=false,
     pyramiding=0,
     calc_on_every_tick=false,
     default_qty_type=strategy.percent_of_equity,
     default_qty_value=25,
     initial_capital=1000,
     commission_type=strategy.commission.percent,
     commission_value=0.01
     )

// PARAMETERS
// Assumes quote currency is FIAT as with BTC/USDT pair
tp1=input.float(200, title="Take Profit 1")
tp2=input.float(500, title="Take Profit 2")
sl=input.float(200, title="Stop Loss")
stOBOS = input.bool(true, title="Use Stochastic overbought/oversold threshold")

// Colors
colorRed = #FF2052
colorGreen = #66FF00


// FUNCTIONS
// Stochastic
f_stochastic() =>
    stoch = ta.stoch(close, high, low, 14)
    stoch_K = ta.sma(stoch, 3)
    stoch_D = ta.sma(stoch_K, 3)
    stRD = ta.crossunder(stoch_K, stoch_D)
    stGD = ta.crossover(stoch_K, stoch_D)
    [stoch_K, stoch_D, stRD, stGD]


// VARIABLES
[bbMiddle, bbUpper, bbLower] = ta.bb(close, 20, 2)
[stoch_K, stoch_D, stRD, stGD] = f_stochastic()


// ORDERS
// Active Orders
// Check if strategy has open positions
inLong = strategy.position_size > 0
inShort = strategy.position_size < 0
// Check if strategy reduced position size in last bar
longClose = strategy.position_size < strategy.position_size[1]
shortClose = strategy.position_size > strategy.position_size[1]

// Entry Conditions
// Enter long when during last candle these conditions are true:
// Candle high is greater than upper Bollinger Band
// Stochastic K line crosses under D line and is oversold
longCondition = stOBOS ?
     low[1] < bbLower[1] and stGD[1] and stoch_K[1] < 25 :
     low[1] < bbLower[1] and stGD[1]

// Enter short when during last candle these conditions are true:
// Candle low is lower than lower Bollinger Band
// Stochastic K line crosses over D line and is overbought
shortCondition = stOBOS ?
     high[1] > bbUpper[1] and stRD[1] and stoch_K[1] > 75 :
     high[1] > bbUpper[1] and stRD[1]

// Exit Conditions
// Calculate Take Profit 
longTP1 = strategy.position_avg_price + tp1
longTP2 = strategy.position_avg_price + tp2
shortTP1 = strategy.position_avg_price - tp1
shortTP2 = strategy.position_avg_price - tp2

// Calculate Stop Loss
// Initialise variables
var float longSL = 0.0
var float shortSL = 0.0

// When not in position, set stop loss using close price which is the price used during backtesting
// When in a position, check to see if the position was reduced on the last bar
// If it was, set stop loss to position entry price. Otherwise, maintain last stop loss value
longSL := if inLong and ta.barssince(longClose) < ta.barssince(longCondition)
    strategy.position_avg_price
else if inLong
    longSL[1]
else
    close - sl

shortSL := if inShort and ta.barssince(shortClose) < ta.barssince(shortCondition)
    strategy.position_avg_price
else if inShort
    shortSL[1]
else
    close + sl

// Manage positions
strategy.entry("Long", strategy.long, when=longCondition)
strategy.exit("TP1/SL", from_entry="Long", qty_percent=50, limit=longTP1, stop=longSL)
strategy.exit("TP2/SL", from_entry="Long", limit=longTP2, stop=longSL)

strategy.entry("Short", strategy.short, when=shortCondition)
strategy.exit("TP1/SL", from_entry="Short", qty_percent=50, limit=shortTP1, stop=shortSL)
strategy.exit("TP2/SL", from_entry="Short", limit=shortTP2, stop=shortSL)


// DRAW
// Stochastic Chart
plot(stoch_K, color=color.blue)
plot(stoch_D, color=color.orange)

// Circles
plot(stOBOS ? stRD and stoch_K >= 75 ? stoch_D : na : stRD ? stoch_D : na, color=colorRed, style=plot.style_circles, linewidth=3)
plot(stOBOS ? stGD and stoch_K <= 25 ? stoch_D : na : stGD ? stoch_K : na, color=colorGreen, style=plot.style_circles, linewidth=3)

// Levels
hline(75, linestyle=hline.style_dotted)
hline(25, linestyle=hline.style_dotted)

もっと