BankNifty 슈퍼트렌드 거래 전략

저자:차오장, 날짜: 2023-12-29 17:09:57
태그:

img

전반적인 설명

이 전략은 슈퍼트렌드 지표를 이용한 BankNifty의 5분 K 라인을 기반으로 하는 거래 전략입니다. 이 전략은 주로 트렌드를 식별하기 위해 슈퍼트렌드 지표를 활용하고 거래 세션과 리스크 관리 규칙을 결합하여 거래합니다.

전략 원칙

전략은 먼저 거래 세션 및 날짜 범위와 같은 입력 변수를 정의합니다. 거래 세션은 인도 거래 세션으로 9:15 AM에서 3:10 PM까지 설정됩니다.

그 다음 슈퍼트렌드 지표와 그 방향을 계산합니다. 슈퍼트렌드 지표는 트렌드의 방향을 식별 할 수 있습니다.

각 거래 세션의 시작에서 전략은 거래에 참여하는 것을 고려하기 전에 3 개의 촛불이 형성되도록 기다립니다. 이것은 거짓 브레이크를 필터하기 위해 있습니다.

긴 신호는 슈퍼트렌드 지표 방향이 아래에서 위로 변할 때, 짧은 신호는 슈퍼트렌드 방향이 위에서 아래로 변할 때 나타납니다.

입력 후, 중지 손실 설정됩니다. 고정 중지 손실 포인트와 후속 중지 손실 비율 모두 입력 변수를 통해 조정 할 수 있습니다.

거래 세션이 끝나면 전략은 모든 오픈 포지션을 닫습니다.

전략 의 장점

이것은 트렌드를 식별하기 위해 지표를 사용하는 간단한 거래 전략입니다. 다음과 같은 장점이 있습니다.

  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)





더 많은