SSL Channel Backtester Strategy With ATR and Money Management

Author: ChaoZhang, Date: 2023-11-23 10:26:58
Tags:

img

Overview

This is a backtesting strategy based on the SSL channel indicator, integrated with functions like ATR stop loss, ATR take profit and money management to facilitate a more comprehensive test on the SSL channel strategy.

Strategy Logic

SSL Channel Indicator

The SSL channel indicator consists of the channel midline and channel bands. The channel midline contains an upper track and a lower track, which are usually simple moving averages of high and low prices over a lookback period. The channel bands are formed between the upper and lower tracks.

When price approaches the upper band, it indicates overbought conditions; when price approaches the lower band, it signals oversold conditions. A breakout of the channel bands implies a trend reversal.

The SSL channel parameter is set to ssl_period=16 in this strategy.

ATR Stop Loss/Take Profit

The Average True Range (ATR) measures market volatility and can be used to determine stop loss and take profit levels.

This strategy utilizes a 14-period ATR (atr_period=14) and dynamic multipliers atr_stop_factor=1.5 and atr_target_factor=1.0 to set adaptive stop loss and take profit based on volatility.

It also checks if the instrument has 2-decimal precision (two_digit) to adjust the stop and target accordingly for pairs like gold and JPY.

Money Management

Money management is achieved through position_size (fixed position sizing) and risk (risk percentage per trade) parameters. The money management module will be enabled when use_mm=true.

The goal is to determine the optimal position size for each trade. By using fixed risk % per trade, the allowable position size will be calculated dynamically based on the account equity to limit the loss on every single trade.

Advantage Analysis

  • SSL channel is effective in capturing trend reversal signals
  • ATR-based stops adjust automatically based on volatility
  • Money management helps control risk across all trades

Risk Analysis

  • SSL channel signals may not be completely reliable, false signals can occur
  • ATR stops may end up too wide or too tight
  • Improper money management settings can lead to oversized positions or low efficiency

These risks can be mitigated by:

  1. Adding filters to confirm signals and avoid false entries
  2. Tuning ATR period parameter for optimal stop loss/take profit levels
  3. Testing different money management parameters for ideal position sizing

Optimization Directions

The strategy can be improved in the following aspects:

  1. Optimize SSL channel parameters for best performance
  2. Enhance or replace the ATR stop mechanism
  3. Add filtering indicators to avoid unnecessary trades
  4. Incorporate position sizing to maximize risk-adjusted returns
  5. Fine-tune parameters for different instruments
  6. Add quantitative tools for more comprehensive testing

With systematic optimization, this strategy can become a robust algorithmic trading system.

Conclusion

This strategy combines the SSL channel for trend, ATR for risk control, and money management for position sizing. Comprehensive backtesting facilitates evaluating and enhancing the strategy into an automated trading system. There is also room for improvements like adding filters, optimizing parameters and expanding functionality. Overall, this forms a solid foundation for building algorithmic trading strategies.


/*backtest
start: 2023-10-23 00:00:00
end: 2023-11-22 00:00:00
period: 2h
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/
// © comiclysm

//@version=4
strategy("SSL Backtester", overlay=false)

//--This strategy will simply test the effectiveness of the SSL using
//--money management and an ATR-derived stop loss

//--USER INPUTS

two_digit = input(false, "Check this for 2-digit pairs (JPY, Gold, Etc)")
ssl_period = input(16, "SSL Period")
atr_period = input(14, "ATR Period")
atr_stop_factor = input(1.5, "ATR Stop Loss Factor")
atr_target_factor = input(1.0, "ATR Target Factor")
use_mm = input(true, "Check this to use Money Management")
position_size = input(1000, "Position size (for Fixed Risk)")
risk = input(0.01, "Risk % in Decimal Form")

//--INDICATORS------------------------------------------------------------

    //--SSL
    
sma_high = sma(high, ssl_period)
sma_low = sma(low, ssl_period)
ssl_value = 0
ssl_value := close > sma_high ? 1 : close < sma_low ? -1 : ssl_value[1]
ssl_low = ssl_value < 0 ? sma_high : sma_low
ssl_high = ssl_value < 0 ? sma_low : sma_high

    //--Average True Range
    
atr = atr(atr_period)

//--TRADE LOGIC----------------------------------------------------------

signal_long = ssl_value > 0 and ssl_value[1] < 0
signal_short = ssl_value < 0 and ssl_value[1] > 0

//--RISK MANAGMENT-------------------------------------------------------
strategy.initial_capital = 50000
balance = strategy.netprofit + strategy.initial_capital
risk_pips = atr*10000*atr_stop_factor
if(two_digit)
    risk_pips := risk_pips / 100
risk_in_value = balance * risk
point_value = syminfo.pointvalue
risk_lots = risk_in_value / point_value / risk_pips
final_risk = use_mm ? risk_lots * 10000 : position_size

//--TRADE EXECUTION-----------------------------------------------------

if (signal_long)
    stop_loss = close - atr * atr_stop_factor
    target = close + atr * atr_target_factor
    strategy.entry("Long", strategy.long, final_risk)
    strategy.exit("X", "Long", stop=stop_loss, limit=target)
if (signal_short)
    stop_loss = close + atr * atr_stop_factor
    target = close - atr * atr_target_factor
    strategy.entry("Short", strategy.short, final_risk)
    strategy.exit("X", "Short", stop=stop_loss, limit=target)
    
//--PLOTTING-----------------------------------------------------------

plot(ssl_low, "SSL", color.red, linewidth=1)
plot(ssl_high, "SSL", color.lime, linewidth=1)


More