
これは,BankNifty 5分K線に基づくスーパートレンド指数取引戦略である. この戦略は,トレンドを識別し,取引時期とリスク管理ルールと組み合わせて取引を行う.
この戦略は,取引時間や日付範囲などの入力変数を最初に定義します.取引時間は,インド取引時間として9時15分から3時10分に設定されます.
超トレンド指標とその方向を計算する.超トレンド指標はトレンドの方向を識別する.
各取引期間の開始時に,戦略は3つのK線が形成されるのを待って,その後に入場を考慮する.これは偽の突破をフィルターするためにである.
多頭信号は,超トレンド指標方向が下から上へと変化したとき;空頭信号は,超トレンド指標方向が上から下へと変化したときである.
入場後,ストップを設定し,固定ストップポイントと追跡ストップパーセントを入力変数で調整できます.
取引期間の終わりに,戦略はすべての未決済のポジションをクリアします.
これは,指標を活用してトレンドを識別する簡単な取引戦略である.
この戦略にはいくつかのリスクがあります.
超トレンド指標のパラメータを最適化したり,他の指標の判断を加えたりすることで,これらのリスクを軽減することができます.
この戦略は,以下の点で最適化できます.
この戦略は,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)