
이것은 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)