ランダムエントリーに基づく複合ストップロスおよびテイクプロフィット戦略


作成日: 2024-01-24 15:38:49 最終変更日: 2024-01-24 15:38:49
コピー: 5 クリック数: 688
1
フォロー
1617
フォロワー

ランダムエントリーに基づく複合ストップロスおよびテイクプロフィット戦略

概要

この戦略の主な考えは,入場点をランダムな数値で決定し,リスク管理のために3つのストップポイントと1つのストップポイントを設定し,取引毎の損失を制御するということです.

戦略原則

この戦略は,ランダムな数rd_number_entryを使用して11から13の間の多入場点を決定し,rd_number_exitを使用して20から22の間の平定を決定する.多入場後にストップロスを入場価格に減算するatr(14) * slx。同時に,3つのストップポイントを設定し,最初のストップポイントは入場価格に加算するatr(14) * tpx,第2のストップポイントは入場価格に加算する2* tpx,第3のストップポイントは入場価格に加算する3* tpx。空白の原理に類似する.

この戦略は,tpx ((止まる係数) とslx ((止まる係数) を調整することでリスクを制御することができる.

優位分析

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

  1. ランダムなエントリーを使用すると,曲線適合の確率を減らすことができます.
  2. 複数のストップ・ストップ・ポイントを設定し,単一の取引のリスクを制御します.
  3. 市場波動に基づいて利益のポイントを設定するatrのストップ・ロスを使用します.
  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)