ランダムエントリーに基づく複合ストップ損失と収益戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-24 15時38分49秒
タグ:

img

概要

この戦略の主なアイデアは,エントリーポイントをランダムに決定し,リスクを管理し,各取引の利益と損失を制御するために3つの取利益ポイントと1つのストップ損失ポイントを設定することです.

戦略の論理

この戦略は,ロングエントリーポイントを決定するために11から13の間のランダム数 rd_number_entryを使用し,ポジションの終了を決定するために20から22の間の rd_number_exitを使用します.ロングした後,ストップロスはエントリー価格マイナス atr (tr) (14) に設定されます.sllx.同時に,3つの取利益ポイントが設定されます.最初の取利益ポイントはエントリー価格プラス atr (t) 14です.2 ポイントは入場価格+2 です.3つ目は入場価格+3です.短縮の原則は類似しますが,エントリー決定は異なるrd_number_entry値を取っており,取利益とストップロスの方向は反対です.

リスクは,tpx (取利益係数) とslx (ストップ損失係数) を調整することによって制御できます.

利点分析

この戦略の利点は以下の通りです.

  1. ランダム入力を使用すると,曲線フィッティングの確率を減らすことができます
  2. 複数のストップ・ロストとテイク・プロフィートポイントを設定することで,単一の取引のリスクを制御できます.
  3. ATR を使って,Take Profit と Stop Loss を設定することで,市場の変動をベースにできます.
  4. 取引リスクは,係数を調整することで制御できる.

リスク分析

この戦略のリスクには以下も含まれる.

  1. ランダムなエントリでトレンドを見逃す可能性があります
  2. ストップ損失が小さすぎると,簡単にストップアウトすることができます
  3. 空間を占める利益が大きすぎる場合,利益は不十分かもしれません.
  4. 不適切なパラメータは,より大きな損失につながる可能性があります

リスクは,取利益とストップ損失の係数を調整し,ランダムエントリーロジックを最適化することによって軽減できます.

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

戦略は以下の側面で最適化できます.

  1. ランダムエントリーロジックを改善し,トレンドインジケーター判断を組み込む
  2. 利益率をより合理的にするために,利益とストップ損失の係数を最適化
  3. ポジション制御を増やして,異なる段階で異なる利益占拠スペースを使用する
  4. マシン学習アルゴリズムでパラメータを最適化

結論

この戦略はランダムなエントリに基づい,単一の取引のリスクを制御するために複数の取利益とストップ損失ポイントを設定する.高いランダム性により,曲線フィッティングの確率が軽減できる.パラメータ最適化によって取引リスクが軽減できる.さらなる最適化と研究にはまだ多くの余地がある.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Random Strategy with 3 TP levels and SL", overlay=true,max_bars_back = 50)

tpx = input(defval = 0.8, title = 'Atr multiplication for TPs?')
slx = input(defval = 1.2, title = 'Atr multiplication for SL?')
isLong = false
isLong := nz(isLong[1])

isShort = false
isShort := nz(isShort[1])

entryPrice = 0.0
entryPrice := nz(entryPrice[1])
tp1 = true
tp1 := nz(tp1[1])
tp2 = true
tp2 := nz(tp2[1])

sl_price = 3213.0
sl_price := nz(sl_price[1])

sl_atr = atr(14)*slx
tp_atr = atr(14)*tpx

rd_number_entry = 1.0
rd_number_entry := (16708 * nz(rd_number_entry[1], 1) % 2147483647)%17

rd_number_exit = 1.0
rd_number_exit := ((16708 * time % 2147483647) %17)


//plot(rd_number_entry)

shortCondition = (rd_number_entry == 13? true:false) and (year >= 2017) and not isLong and not isShort
longCondition = (rd_number_entry == 11 ? true:false) and (year >= 2017) and not isShort and not isShort
//Never exits a trade:
exitLong = (rd_number_exit == 22?true:false) and (year >= 2018) and not isShort
exitShort = (rd_number_exit ==  22?true:false) and (year >= 2018) and not isLong


//shortCondition = crossunder(sma(close, 14), sma(close, 28)) and year >= 2017
//longCondition = crossover(sma(close, 14), sma(close, 28)) and year >= 2017

//exitLong = crossunder(ema(close, 14), ema(close, 28)) and year >= 2017
//exitShort = crossover(ema(close, 14), ema(close, 28)) and year >= 2017

if (longCondition and not isLong)
    strategy.entry('Long1', strategy.long)
    strategy.entry('Long2', strategy.long)
    strategy.entry('Long3', strategy.long)
    isLong := true
    entryPrice := close
    isShort := false
    tp1 := false
    tp2 := false
    sl_price := close-sl_atr

if (shortCondition and not isShort)
    strategy.entry('Short1', strategy.short)
    strategy.entry('Short2', strategy.short)
    strategy.entry('Short3', strategy.short)
    isShort := true
    entryPrice := close
    isLong := false
    tp1 := false
    tp2 := false
    sl_price := close+sl_atr
    
if (exitShort and isShort)
    strategy.close('Short1')
    strategy.close('Short2')
    strategy.close('Short3')
    isShort :=  false

if (exitLong and isLong)
    strategy.close('Long1')
    strategy.close('Long2')
    strategy.close('Long3')
    isLong :=  false

if isLong
    if (close > entryPrice + tp_atr) and not tp1
        strategy.close('Long1')
        tp1 := true
        sl_price := close - tp_atr
    if (close > entryPrice + 2*tp_atr) and not tp2
        strategy.close('Long2')
        tp2 := true
        sl_price := close - tp_atr
    if (close > entryPrice + 3*tp_atr)
        strategy.close('Long3')
        isLong := false
    if (close < sl_price)
        strategy.close('Long1')
        strategy.close('Long2')
        strategy.close('Long3')
        isLong := false

if isShort
    if (close < entryPrice - tp_atr) and not tp1
        strategy.close('Short1')
        sl_price := close + tp_atr
        tp1 := true
    if (close < entryPrice - 2*tp_atr) and not tp2
        strategy.close('Short2')
        sl_price := close + tp_atr
        tp2 := true
    if (close < entryPrice - 3*tp_atr)
        strategy.close('Short3')
        isShort := false
    if (close > sl_price)
        strategy.close('Short1')
        strategy.close('Short2')
        strategy.close('Short3')
        isShort := false
plot(atr(14)*slx)
plot(sl_price)

もっと