BankNifty スーパートレンド取引戦略


作成日: 2023-12-29 17:09:57 最終変更日: 2023-12-29 17:09:57
コピー: 0 クリック数: 711
1
フォロー
1619
フォロワー

BankNifty スーパートレンド取引戦略

概要

これは,BankNifty 5分K線に基づくスーパートレンド指数取引戦略である. この戦略は,トレンドを識別し,取引時期とリスク管理ルールと組み合わせて取引を行う.

戦略原則

この戦略は,取引時間や日付範囲などの入力変数を最初に定義します.取引時間は,インド取引時間として9時15分から3時10分に設定されます.

超トレンド指標とその方向を計算する.超トレンド指標はトレンドの方向を識別する.

各取引期間の開始時に,戦略は3つのK線が形成されるのを待って,その後に入場を考慮する.これは偽の突破をフィルターするためにである.

多頭信号は,超トレンド指標方向が下から上へと変化したとき;空頭信号は,超トレンド指標方向が上から下へと変化したときである.

入場後,ストップを設定し,固定ストップポイントと追跡ストップパーセントを入力変数で調整できます.

取引期間の終わりに,戦略はすべての未決済のポジションをクリアします.

戦略的優位性

これは,指標を活用してトレンドを識別する簡単な取引戦略である.

  1. 超トレンド指数を使ってトレンドの方向を判断し,トレンドを効果的に識別できます.
  2. 取引時間を組み合わせることで,市場の最も波動的な開盤と閉盤を回避できます.
  3. ストップトラッキングを設定し,利益をロックします.
  4. 入力変数で自由に調整できるパラメータが多く,適応性が強い

戦略リスク

この戦略にはいくつかのリスクがあります.

  1. 超トレンド指標が遅れているため,ベストのタイミングを逃す可能性が高い
  2. 単一の指標判断は偽の突破の影響を受けやすく,勝利率は低い可能性があります.
  3. 株価のトレンドを考慮しないことで,株価から離れる可能性がある.
  4. ストップポイントの誤った設定は,予想以上の損失を招く可能性があります

超トレンド指標のパラメータを最適化したり,他の指標の判断を加えたりすることで,これらのリスクを軽減することができます.

戦略最適化の方向性

この戦略は,以下の点で最適化できます.

  1. 他の指標の判断を加え,ポートフォリオの取引戦略を形成し,戦略の安定性を高めることができます.
  2. 大盘の動きに対する判断を加え,大盘との離散を避ける
  3. 超トレンド指標のパラメータを最適化して,最適な長さと因数を見つけます.
  4. トレンドの動きに合わせてストップポイントを徐々に調整するなど,ストップ・ストラップ戦略の調整
  5. 戦略に最も適合する種を探すために,様々な取引品種をテストする.

要約する

この戦略は,BankNifty 5分線に基づくスーパートレンド指数取引戦略である.これは,トレンド方向を判断するためにスーパートレンド指数を使用し,取引の時間とリスク管理ルールと組み合わせて取引する.これは,単純で明快で,理解し,実行しやすい,複雑な量化戦略と比較する.これは,例の戦略として,将来の最適化と改善のための基礎と方向を提供します.

ストラテジーソースコード
/*backtest
start: 2023-11-28 00:00:00
end: 2023-12-28 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("BankNifty 5min Supertrend Based Strategy, 09:15 Entry with Date Range and Risk Management")

// Session and date range input variables
session = input("0915-1510", "Session", group="Indian Session Time")
start_date = input(title="Start Date", defval=timestamp("01 Jan 2022 00:00:00"), group="Backtest Specific Range")
end_date = input(title="End Date", defval=timestamp("01 Dec 2023 23:59:59"))
atrPeriod = input(50, "ATR Length", group="SuperTrend Setting")
factor = input.float(3.0, "Factor", step=0.1)

useDelay = input(true, "Use Delay?", group="Delay at Session Start")
Delay = useDelay ? input(10, title="Delay N numbers of candle", group="Delay at Session Start") : na

useDelay_stopLoss = input(true, "Use Stoploss Points?", group="Risk Management")
stopLoss = useDelay_stopLoss ? input(100, "Stop Loss Points", group="Risk Management"): na

useDelay_stopLossPerc1 = input(true, "Use Stoploss Trail?", group="Risk Management")
stopLossPerc1 =useDelay_stopLossPerc1 ? input.float(0.1, "Stop Loss Trail%", step=0.1,maxval = 1, group="Risk Management"): na
// Check if current time is within the specified session and date range
inSession = true

[supertrend, direction] = ta.supertrend(factor, atrPeriod)

// Wait for 3 candles to form at the start of every session
var candlesFormed = 0
if inSession and not inSession[1]
    candlesFormed := 1
else if inSession and candlesFormed > 0
    candlesFormed := candlesFormed + 1
else
    candlesFormed := 0


//

// Only enter trades if 3 candles have formed at the start of the session
entryce = (ta.change(direction) < 0) or (candlesFormed >= Delay and direction < 0)
exitce = ta.change(direction) > 0
entrype = (ta.change(direction) > 0) or (candlesFormed >= Delay and direction > 0)
exitpe = ta.change(direction) < 0
var entryPrice = 0.0
if entryce and inSession
    // Enter long trade
    onePercent = strategy.position_avg_price *stopLossPerc1
    entryPrice := close
    strategy.entry("My Long Entry Id", strategy.long, comment="long" )
    // Set stop loss at x% below entry price
    strategy.exit("My Long Exit Id", "My Long Entry Id", stop=(entryPrice - stopLoss),trail_points=onePercent )
    
if entrype and inSession
    onePercent1 = strategy.position_avg_price *stopLossPerc1
    entryPrice := close
    // Enter short trade
    strategy.entry("My Short Entry Id", strategy.short, comment="short")
    // Set stop loss at x% above entry price
    strategy.exit("My Short Exit Id", "My Short Entry Id", stop=(entryPrice + stopLoss),trail_points=onePercent1)

// Close all trades at end of session
if not inSession and strategy.opentrades > 0
    strategy.close_all()

// Plot Supertrend with changing colors
plot(supertrend, title="Supertrend", color=direction == 1 ? color.red : color.green, linewidth=2)