This is an intraday short-term trend following strategy based on the Supertrend indicator. Users can define the intraday trading session during which the strategy will run.
The strategy reverses the position using double quantity when the signal changes. Any open positions are squared off at the end of the intraday session.
Calculate the Supertrend indicator based on user defined multiplier and ATR period.
Plot the Supertrend line as the support and resistance.
Determine long/short conditions. Close above Supertrend line is long condition. Close below Supertrend line is short condition.
Check if current bar is within intraday session defined by user.
Issue long/short signals only when intraday session is active and long/short conditions are met.
Reverse position by taking opposite trade with double quantity when Supertrend direction changes.
Square off open positions when Supertrend direction is unchanged and intraday session ends.
Supertrend identifies trend and reduces false signals.
Combining Supertrend with close price avoids being stopped out prematurely.
Reversing position timely reduces losses.
Intraday session avoids overnight risk.
Forced exit avoids risk of forgetting to square off.
Improper Supertrend parameters may lead to poor strategy performance.
Reversing position increases trade frequency and costs.
Forced exit at session end may lead to losses.
Risk 1 can be mitigated through parameter optimization.
Risk 2 can be controlled via stop loss.
Risk 3 can be avoided using stop loss or trend filter.
Test different trend indicators like MA, KDJ etc.
Add stop loss logic.
Add trend filter to avoid forced exit losses.
Optimize multiplier and ATR period parameters.
Test on different instruments.
This strategy combines Supertrend and intraday session management to capitalize on short-term trend breaks. Position reversal and forced exit effectively controls risk. Further improvements can be made through parameter optimization, stop loss and trend filtering.
/*backtest start: 2023-08-18 00:00:00 end: 2023-09-17 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © Pritesh-StocksDeveloper //@version=4 strategy("Supertrend - Intraday", overlay=true, calc_on_every_tick = true) // ********** Strategy inputs - Start ********** // Used for intraday handling // Session value should be from market start to the time you want to square-off // your intraday strategy // Important: The end time should be at least 2 minutes before the intraday // square-off time set by your broker var i_marketSession = input(title="Market session", type=input.session, defval="0915-1455", confirm=true) var float i_multiplier = input(title = "Multiplier", type = input.float, defval = 4, confirm=true) var int i_atrPeriod = input(title = "ATR Period", type = input.integer, defval = 14, confirm=true) // ********** Strategy inputs - End ********** // ********** Supporting functions - Start ********** // A function to check whether the bar or period is in intraday session barInSession(sess) => time(timeframe.period, sess) != 0 // ********** Supporting functions - End ********** // ********** Strategy - Start ********** [superTrend, dir] = supertrend(i_multiplier, i_atrPeriod) colResistance = dir == 1 and dir == dir[1] ? color.new(color.red, 0) : color.new(color.red, 100) colSupport = dir == -1 and dir == dir[1] ? color.new(color.green, 0) : color.new(color.green, 100) plot(superTrend, color = colResistance, linewidth=2) plot(superTrend, color = colSupport, linewidth=2) // Long/short condition longCondition = close > superTrend shortCondition = close < superTrend // See if intraday session is active bool intradaySession = barInSession(i_marketSession) // Trade only if intraday session is active // Long position // When longCondition and intradaySession both are true strategy.entry(id = "Long", long = strategy.long, when = longCondition and intradaySession) // Short position // When shortCondition and intradaySession both are true strategy.entry(id = "Short", long = strategy.short, when = shortCondition and intradaySession) // Square-off position (when session is over and position is open) squareOff = (not intradaySession) and (strategy.position_size != 0) strategy.close_all(when = squareOff, comment = "Square-off") // ********** Strategy - End **********