
Đây là một chiến lược giao dịch chỉ số siêu xu hướng dựa trên đường K 5 phút của BankNifty. Chiến lược này chủ yếu sử dụng chỉ số siêu xu hướng để xác định xu hướng, kết hợp với thời gian giao dịch và các quy tắc quản lý rủi ro để giao dịch.
Chiến lược này đầu tiên xác định các biến đầu vào như giờ giao dịch và phạm vi ngày. Thời gian giao dịch được thiết lập theo giờ giao dịch của Ấn Độ, từ 9:15 AM đến 3:10 PM.
Sau đó tính toán chỉ số siêu xu hướng và hướng của nó. Chỉ số siêu xu hướng có thể xác định hướng của xu hướng.
Khi bắt đầu mỗi giai đoạn giao dịch, chiến lược là chờ đợi 3 đường K hình thành trước khi xem xét vào. Điều này nhằm lọc các đột phá giả.
Tín hiệu đa đầu là khi chỉ số xu hướng siêu thay đổi hướng từ dưới lên; tín hiệu đầu trống là khi chỉ số xu hướng siêu thay đổi hướng từ lên xuống.
Sau khi vào sân, bạn có thể thiết lập điểm dừng, số điểm dừng cố định và tỷ lệ dừng theo dõi có thể được điều chỉnh bằng cách nhập các biến.
Khi kết thúc giai đoạn giao dịch, chiến lược sẽ thanh toán tất cả các vị trí chưa thanh toán.
Đây là một chiến lược giao dịch đơn giản sử dụng các chỉ số để xác định xu hướng. Nó có những lợi thế sau:
Chiến lược này cũng có một số rủi ro:
Những rủi ro này có thể được giảm bớt bằng cách tối ưu hóa các tham số của chỉ số siêu xu hướng hoặc thêm các phán đoán về các chỉ số khác.
Chiến lược này cũng có thể được tối ưu hóa theo các khía cạnh sau:
Chiến lược này là một chiến lược giao dịch chỉ số siêu xu hướng dựa trên đường 5 phút của BankNifty. Nó sử dụng chỉ số siêu xu hướng để xác định hướng xu hướng, kết hợp với thời gian giao dịch và các quy tắc quản lý rủi ro để giao dịch.
/*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)