移動平均と日中パターンに基づくインテリジェントなトレーリングストップロス戦略

SMA MA18 ATR
作成日: 2025-01-17 16:04:09 最終変更日: 2025-01-17 16:04:09
コピー: 4 クリック数: 361
1
フォロー
1617
フォロワー

移動平均と日中パターンに基づくインテリジェントなトレーリングストップロス戦略

概要

これは、18 日移動平均 (SMA18) をベースに、日中取引パターン認識とスマート トレーリング ストップ メカニズムを組み合わせた戦略です。この戦略は主に価格とSMA18の関係を観察し、日中の高値と安値を組み合わせ、適切なタイミングでロングポジションに入ります。この戦略では、固定ストップロス ポイントまたは 2 日間の最低ポイントのいずれかをトレーリング ストップロス ベンチマークとして使用できる柔軟なストップロス プランを採用しています。

戦略原則

戦略の中核となるロジックには、次の重要な要素が含まれます。

  1. エントリー条件は、18日移動平均に対する価格の相対的な位置に基づきます。移動平均を突破したときに市場に参入するか、移動平均を上回って参入するかを選択できます。
  2. 日中のKラインパターンを分析することで、特に内部Kライン(インサイドバー)パターンに注意を払うことで、エントリーの精度が向上します。
  3. 週の異なる取引日のパフォーマンス特性に基づいて、特定の日に選択的に取引することができます。
  4. エントリー価格は指値注文で設定され、取引の確率を高めるために安値よりわずかに高いプレミアムが付きます。
  5. ストップ ロス メカニズムは 2 つのモードをサポートしています。1 つはエントリー価格に基づく固定ストップ ロス、もう 1 つは過去 2 取引日の最低点に基づくトレーリング ストップ ロスです。

戦略的優位性

  1. テクニカル指標と価格パターンを組み合わせることで、エントリーシグナルの信頼性が高まります。
  2. さまざまな市場特性に応じて最適化できる柔軟な取引時間選択メカニズム
  3. インテリジェントなストップロスソリューションは、価格変動に十分な余裕を持たせながら利益を保護します。
  4. 戦略パラメータは高度に調整可能であり、さまざまな市場環境に適応できます。
  5. 内部Kラインパターンのスクリーニングにより、誤った信号が効果的に減少します。

戦略リスク

  1. 不安定な市場では、固定ストップは時期尚早な撤退につながる可能性がある
  2. 急速な反転の場合、トレーリングストップロスは利益を少なく固定する可能性があります
  3. 横ばいの段階では、内部ローソク足が頻繁に出現し、過剰な取引につながる可能性があります。 対策:
  • 市場のボラティリティに応じてストップロス距離を動的に調整する
  • トレンド確認インジケーターを追加する
  • 低品質の取引を除外するために最低利益目標を設定する

戦略最適化の方向性

  1. ボラティリティ指標(ATRなど)を導入してストップロス距離を動的に調整する
  2. ボリューム分析の次元を増やし、信号の信頼性を向上
  3. 過去のパフォーマンスに基づいて取引時間を自動的に最適化する、よりスマートな日付選択アルゴリズムを開発する
  4. 弱いトレンドでの取引を避けるため、トレンド強度フィルターを追加しました
  5. 内部Kライン認識アルゴリズムを最適化し、パターン認識の精度を向上

要約する

この戦略は、複数の次元からの分析方法を組み合わせることで、比較的完全な取引システムを構築します。この戦略の主な利点は、柔軟なパラメータ設定とインテリジェントなストップロス メカニズムにあり、これによりさまざまな市場環境に適応できます。継続的な最適化と改善を通じて、この戦略はさまざまな市場状況下で安定したパフォーマンスを維持することが期待されます。

ストラテジーソースコード
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-16 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/

//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © zweiprozent

strategy('Buy Low over 18 SMA Strategy', overlay=true, default_qty_value=1)
xing = input(false, title='crossing 18 sma?')
sib = input(false, title='trade inside Bars?')
shortinside = input(false, title='trade inside range bars?')
offset = input(title='offset', defval=0.001)
belowlow = input(title='stop below low minus', defval=0.001)
alsobelow = input(false, title='Trade only above 18 sma?')
tradeabove = input(false, title='Trade with stop above order?')
trailingtwo = input(false, title='exit with two days low trailing?')


insideBar() =>  //and high <= high[1] and low >= low[1] ? 1 : 0
    open <= close[1] and close >= open[1] and close <= close[1] or open >= close[1] and open <= open[1] and close <= open[1] and close >= close[1] ? 1 : 0

inside() =>
    high <= high[1] and low >= low[1] ? 1 : 0
enterIndex = 0.0
enterIndex := enterIndex[1]

inPosition = not na(strategy.position_size) and strategy.position_size > 0
if inPosition and na(enterIndex)
    enterIndex := bar_index
    enterIndex



//if strategy.position_size <= 0 

//    strategy.exit("Long", stop=low[0]-stop_loss,comment="stop loss")


//if not na(enterIndex) and bar_index - enterIndex + 0 >= 0 

//    strategy.exit("Long", stop=low[0]-belowlow,comment="exit")

//    enterIndex := na

T_Low = request.security(syminfo.tickerid, 'D', low[0])
D_High = request.security(syminfo.tickerid, 'D', high[1])
D_Low = request.security(syminfo.tickerid, 'D', low[1])
D_Close = request.security(syminfo.tickerid, 'D', close[1])
D_Open = request.security(syminfo.tickerid, 'D', open[1])

W_High2 = request.security(syminfo.tickerid, 'W', high[1])
W_High = request.security(syminfo.tickerid, 'W', high[0])
W_Low = request.security(syminfo.tickerid, 'W', low[0])
W_Low2 = request.security(syminfo.tickerid, 'W', low[1])
W_Close = request.security(syminfo.tickerid, 'W', close[1])
W_Open = request.security(syminfo.tickerid, 'W', open[1])

//longStopPrice  = strategy.position_avg_price * (1 - stopl)
// Go Long - if prev day low is broken and stop loss prev day low
entryprice = ta.sma(close, 18)

//(high[0]<=high[1]or close[0]<open[0]) and low[0]>vwma(close,30) and time>timestamp(2020,12,0,0,0)

showMon = input(true, title='trade tuesdays?')
showTue = input(true, title='trade wednesdayy?')
showWed = input(true, title='trade thursday?')
showThu = input(true, title='trade friday?')
showFri = input(true, title='trade saturday?')
showSat = input(true, title='trade sunday?')
showSun = input(true, title='trade monday?')

isMon() =>
    dayofweek(time('D')) == dayofweek.monday and showMon
isTue() =>
    dayofweek(time('D')) == dayofweek.tuesday and showTue
isWed() =>
    dayofweek(time('D')) == dayofweek.wednesday and showWed
isThu() =>
    dayofweek(time('D')) == dayofweek.thursday and showThu
isFri() =>
    dayofweek(time('D')) == dayofweek.friday and showFri
isSat() =>
    dayofweek(time('D')) == dayofweek.saturday and showSat
isSun() =>
    dayofweek(time('D')) == dayofweek.sunday and showSun


clprior = close[0]
entryline = ta.sma(close, 18)[1]
//(isMon() or isTue()or isTue()or  isWed() 
noathigh = high < high[1] or high[2] < high[3] or high[1] < high[2] or low[1] < ta.sma(close, 18)[0] and close > ta.sma(close, 18)[0]

if noathigh and time > timestamp(2020, 12, 0, 0, 0) and (alsobelow == false or high >= ta.sma(close, 18)[0]) and (isMon() or isTue() or isWed() or isThu() or isFri() or isSat() or isSun()) and (high >= high[1] or sib or low <= low[1])  //((sib == false and inside()==true) or inside()==false) and (insideBar()==true or shortinside==false)
    if tradeabove == false
        strategy.entry('Long', strategy.long, limit=low + offset * syminfo.mintick, comment='long')
    if tradeabove == true and (xing == false or clprior < entryline)  // and high<high[1] 
        strategy.entry('Long', strategy.long, stop=high + offset * syminfo.mintick, comment='long')


//if time>timestamp(2020,12,0,0,0) and isSat()  
//    strategy.entry("Long", strategy.long, limit=0, comment="long")


//strategy.exit("Long", stop=low-400*syminfo.mintick)

//strategy.exit("Long", stop=strategy.position_avg_price-10*syminfo.mintick,comment="exit")
//strategy.exit("Long", stop=low[1]-belowlow*syminfo.mintick, comment="stop")

if strategy.position_avg_price > 0 and trailingtwo == false and close > strategy.position_avg_price
    strategy.exit('Long', stop=strategy.position_avg_price, comment='stop')

if strategy.position_avg_price > 0 and trailingtwo == false and (low > strategy.position_avg_price or close < strategy.position_avg_price)
    strategy.exit('Long', stop=low[0] - belowlow * syminfo.mintick, comment='stop')

if strategy.position_avg_price > 0 and trailingtwo
    strategy.exit('Long', stop=ta.lowest(low, 2)[0] - belowlow * syminfo.mintick, comment='stop')