This strategy generates Entries and Exits signals based on the SuperTrend channel indicator to realize automated quant trading. The SuperTrend channel indicator can identify breakout points and support/resistance levels clearly to determine the trend direction. This strategy incorporates the advantages of this indicator to conduct both long and short trading.
This strategy uses ATR and Donchian Channel to calculate two stop-loss lines for long and short positions. Specifically, it computes the ATR value using the ATR period and multiplier parameters, then adds and subtracts it from the average of highest high and lowest low to obtain the long and short stop-loss lines. When the closing price breaks above the long stop-loss line upwards, a long signal is generated. When the closing price breaks below the short stop-loss line downwards, a short signal is triggered.
After taking long or short positions, the stop-loss lines are updated dynamically to lock in profits. The new stop-loss line will not be lower or higher than the previous one, avoiding stop-loss penetration. When a new high or low appears between the current and previous stop-loss line, the stop-loss line is adjusted to the latest price.
The biggest advantage of this strategy is that the SuperTrend channel indicator can clearly identify the trend direction and key support/resistance levels. Together with the dynamic ATR stop-loss, it can effectively control single trade loss.
Specifically, the two stop-loss lines in the SuperTrend channel indicator represent the position cost basis and the latest support/resistance. They offer very clear guidance for Entries and Exits. Meanwhile, the stop-loss line updates dynamically to lock in profits and prevent stop-loss penetration.
In general, this strategy enters timely when the trend is determined, controls risk via dynamic stop-loss, making it a relatively robust quantitative trading strategy.
The major risk of this strategy lies in the possibility of stop-loss penetration. When price fluctuates violently, the new stop-loss line may become lower or higher than the previous one, causing stop-loss penetration and increased losses.
Besides, the Entries signals generated by the SuperTrend channel indicator do not work well in ranging markets, leading to wrong trades occasionally. Manual intervention is required to determine the trend direction before enabling the strategy.
This strategy can be optimized in the following aspects:
Optimize the ATR period and multiplier parameters to find the best combination through backtesting various values and analyzing metrics like return and Sharpe ratio.
Add other indicators for signal filtration to avoid wrong Entries in ranging markets. Moving averages, Bollinger Bands etc. can be used to determine the trend direction.
Incorporate volume indicators to fine tune the stop-loss position. Stop-loss lines can be adjusted based on volume surges to further lock in profits.
Introduce machine learning models for adaptive parameter optimization. Techniques like RNN and LSTM can be leveraged to predict optimal parameter values dynamically.
This strategy originates from the SuperTrend channel indicator with a clear judgment of trend direction and relatively high winning rate. It also applies dynamic ATR tracking stop-loss to control single trade loss. Performance can be further improved through parameter optimization, indicator optimization etc. In general, it is a robust strategy suitable for automated quant trading.
/*backtest start: 2024-01-05 00:00:00 end: 2024-02-04 00:00:00 period: 2h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 //EU ESCREVI ISSO TUDO, PARA FICAR BEM CLARO strategy("SuperTrend Strategy", overlay=true) //AQUI OS INPUTS PARA A SUPERTREND length = input(title="ATR Period", type=input.integer, defval=7) mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=7) showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=true) //AQUI O CALCULO DO ATR STOPS atr = mult * atr(length) //AQUI A TRANSFORMAÇÃO DO ATR STOPS EM SUPERTREND //- //A LÓGICA PARA LONGSTOP longStop = hl2 - atr longStopPrev = nz(longStop[1], longStop) longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop //A LÓGICA PARA SELLSTOP shortStop = hl2 + atr shortStopPrev = nz(shortStop[1], shortStop) shortStop := close[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop //DIREÇÃO DO INDICADOR dir = 1 dir := nz(dir[1], dir) dir := dir == -1 and close > shortStopPrev ? 1 : dir == 1 and close < longStopPrev ? -1 : dir //DEFININDO AS CORES DAS LINHAS DA SUPERTREND longColor = color.lime shortColor = color.red //PLOTANDO NO GRÁFICO A SUPERTREND E A ESTRATÉGIA plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=3, color=longColor) buySignal = dir == 1 and dir[1] == -1 plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=3, color=shortColor) sellSignal = dir == -1 and dir[1] == 1 //DEFININDO AS FUNÇÕES DE COMPRA E VENDA strategy.entry("long", strategy.long, when = buySignal) strategy.entry("short", strategy.short, when = sellSignal)template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6