This strategy combines moving average, Bollinger bands and UT Bot Alerts indicators to implement a simple breakout trading strategy. It goes long when price breaks above Bollinger upper band and goes short when price breaks below Bollinger lower band.
## Strategy Logic
1. The 200-period EMA serves as the baseline for the trend. Price above EMA signifies uptrend and price below EMA signifies downtrend.
2. The UT Bot Alerts indicator generates buy and sell signals in combination with ATR. It triggers long signal when price and fast EMA cross above Bollinger upper band. And it triggers short signal when price and fast EMA cross below Bollinger lower band.
3. The ATR stop loss indicator sets the stop loss points. The stop loss distance is 1.5 times the ATR value.
4. After entry, stop loss, take profit and break even levels are determined by risk reward ratio.
## Advantage Analysis
1. Using Bollinger bands to identify appropriate long and short opportunities can improve profitability.
2. The UT Bot Alerts indicator can generate comparatively accurate signals.
3. By adopting risk reward ratio for stop loss and take profit, risk can be effectively controlled.
## Risk Analysis
1. Bollinger bands tend to produce false signals during ranging periods.
2. ATR has lagging effect. At the beginning of a trend, the stop loss distance may be too wide.
3. Improper risk reward ratio settings can also lead to over-aggressiveness or over-conservativeness.
## Optimization Guidelines
1. Try using other indicators to replace the UT Bot Alerts indicator.
2. Optimize the period and multiplier parameters of ATR to find more suitable stop loss distance.
3. Test different risk reward ratios to find the optimal parameters.
## Conclusion
This strategy integrates the strengths of multiple indicators and has considerable practicality. Through parameter optimization, it can become a steady and reliable breakout system. But the risks arising from indicator failure and improper parameters should also be watched out for.
// ------ Inputs for calculating position --------
initial_actual_capital = input.float(defval=10000, title = "Enter initial/current capital", group = "Calculate position")
risk_c = input.float(2.5, '% account risk per trade', step=1, group = "Position amount calculator", tooltip = "Percentage of total account to risk per trade. The USD value that should be used to risk the inserted percentage of the account. Appears green in the upper left corner")
// ------ Date filter (obtained from ZenAndTheArtOfTrading) ---------
initial_date = input(title="Initial date", defval=timestamp("10 Feb 2014 13:30 +0000"), group="Time filter", tooltip="Enter the start date and time of the strategy")
final_date = input(title="Final date", defval=timestamp("01 Jan 2030 19:30 +0000"), group="Time filter", tooltip="Enter the end date and time of the strategy")
dateFilter(int st, int et) => time >= st and time <= et
colorDate = input.bool(defval=false, title="Date background", tooltip = "Add color to the period of time of the strategy tester")
bgcolor(colorDate and dateFilter(initial_date, final_date) ? color.new(color.blue, transp=90) : na)
// ------ Session limits (obtained from ZenAndTheArtOfTrading) -------
timeSession = input(title="Time session", defval="0000-2400", group="Time filter", tooltip="Session time to operate. It may be different depending on your time zone, you have to find the correct hours manually.")
colorBG = input.bool(title="Session background", defval=false, tooltip = "Add color to session time background")
// -------------- UT BOT ALERTS INDICATOR by @QuantNomad -------------------------
// Inputs
a = input(3, title='Key Vaule', group = "UT BOT ALERTS", tooltip = "Higher amount, less trades. Changing this could be useful in some assets or time frames")
c = input(1, title='ATR Period', group = "UT BOT ALERTS", tooltip = "Higher amount, less trades. Changing this could be useful in some assets or time frames")
h = input(false, title='Signals from Heikin Ashi Candles', group = "UT BOT ALERTS")
xATR = ta.atr(c)
nLoss = a * xATR
src = h ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close, lookahead=barmerge.lookahead_off) : close
multiplier = input.float(1.5, minval=0.1, step=0.1, title='Atr multiplier', group = "Atr stop loss", inline = "A", tooltip = "Defines the stop loss distance based on the Atr stop loss indicator")
show_atr = input.bool(defval = true, title = "Show Atr stop loss ?", group = "Appearance")
plot(show_atr and long_condition_atr and bullish ? longStopLoss : na, color = color.white, style = plot.style_circles, linewidth = 2)
plot(show_atr and short_condition_atr and bearish ? shortStopLoss : na, color = color.white, style = plot.style_circles, linewidth = 2)
// ------------- Money management --------------
strategy_contracts = strategy.equity / close
distance_sl_atr_long = -1 * (longStopLoss - close) / close
distance_sl_atr_short = (shortStopLoss - close) / close
risk = input.float(2.5, '% Account risk per trade for backtesting', step=1, group = "Risk management for trades", tooltip = "Percentage of total account to risk per trade")
//fixed_amounts = input.bool(defval = false, title = "Fixed amounts ?", group = "Risk management for trades")
//fixed_amount_input = input.float(defval = 1000, title = "Fixed amount in usd", group = "Risk management for trades")
//if fixed_amounts
// long_amount := fixed_amount_input / close
//if fixed_amounts
// short_amount := fixed_amount_input / close
//
leverage=input.bool(defval=true, title="Use leverage for backtesting ?", group = "Risk management for trades", tooltip = "If it is activated, there will be no monetary units or amount of assets limit for each operation (That is, each operation will not be affected by the initial / current capital since it would be using leverage). If it is deactivated, the monetary units or the amount of assets to use for each operation will be limited by the initial/current capital.")
if not leverage and long_amount>strategy_contracts
long_amount:=strategy.equity/close
if not leverage and short_amount>strategy_contracts
short_amount:=strategy.equity/close
// ---------- Risk management ---------------
risk_reward_breakeven_long= input.float(title="Risk/reward for breakeven long", defval=0.75, step=0.1, group = "Risk management for trades")
risk_reward_take_profit_long= input.float(title="Risk/reward for take profit long", defval=3.0, step=0.1, group = "Risk management for trades")
risk_reward_breakeven_short= input.float(title="Risk/reward for break even short", defval=0.75, step=0.1, group = "Risk management for trades")
risk_reward_take_profit_short= input.float(title="Risk/reward for take profit short", defval=3.0, step=0.1, group = "Risk management for trades")
tp_percent=input.float(title="% of trade for first take profit", defval=50, step=5, group = "Risk management for trades", tooltip = "Closing percentage of the current position when the first take profit is reached.")
// ------------ Trade conditions ---------------
bullish := close > ema200
bearish := close < ema200
bought = strategy.position_size > 0
sold = strategy.position_size < 0
buy := src > xATRTrailingStop and above
sell := src < xATRTrailingStop and below
var float sl_long = na
var float sl_short = na
var float be_long = na
var float be_short = na
var float tp_long = na
var float tp_short = na
if not bought
be_long:=na
sl_long:=na
tp_long:=na
if not sold
be_short:=na
sl_short:=na
tp_short:=na
long_positions = input.bool(defval = true, title = "Long positions ?", group = "Positions management")
short_positions = input.bool(defval = true, title = "Short positions ?", group = "Positions management")
// ---------- Strategy -----------
// Long position
if not bought and buy and long_positions and bullish and inSession(timeSession)
sl_long:=longStopLoss
long_stoploss_distance = close - longStopLoss
be_long := close + long_stoploss_distance * risk_reward_breakeven_long
// ---------- Draw positions and signals on chart (strategy as an indicator) -------------
if high>tp_long
tp_long:=na
if low<tp_short
tp_short:=na
if high>be_long
be_long:=na
if low<be_short
be_short:=na
show_position_on_chart = input.bool(defval=true, title="Draw position on chart ?", group = "Appearance", tooltip = "Activate to graphically display profit, stop loss and break even")
// breakeven_long = plot(strategy.position_size>0 and high<be_long and show_position_on_chart ? be_long : na , style = plot.style_linebr, color = color.new(#1fc9fd, 60), linewidth = 1, display = display.all - display.status_line - display.price_scale)
// breakeven_short = plot(strategy.position_size<0 and low>be_short and show_position_on_chart ? be_short : na , style = plot.style_linebr, color = color.new(#1fc9fd, 60), linewidth = 1, display = display.all - display.status_line - display.price_scale)
show_break_even_on_chart = input.bool(defval=true, title="Draw first take profit/breakeven price on chart ?", group = "Appearance", tooltip = "Activate to display take profit and breakeven price. It appears as a green point in the chart")
long_stoploss_distance = close - longStopLoss
short_stoploss_distance=shortStopLoss - close
be_long_plot = close + long_stoploss_distance * risk_reward_breakeven_long
leverage_for_calculator=input.bool(defval=true, title="Use leverage ?", group = "Calculate position", tooltip = "If it is activated, there will be no monetary units or amount of assets limit for each operation (That is, each operation will not be affected by the initial / current capital since it would be using leverage). If it is deactivated, the monetary units or the amount of assets to use for each operation will be limited by the initial/current capital.")
if not leverage_for_calculator and long_amount_lev>initial_actual_capital
long_amount_lev:=initial_actual_capital
if not leverage_for_calculator and short_amount_lev>initial_actual_capital
short_amount_lev:=initial_actual_capital
// plot(buy and leverage_for_calculator ? long_amount_c : na, color = color.rgb(136, 255, 0), display = display.all - display.pane - display.price_scale)
// plot(sell and leverage_for_calculator ? short_amount_c : na, color = color.rgb(136, 255, 0), display = display.all - display.pane - display.price_scale)
// plot(buy and not leverage_for_calculator ? long_amount_lev : na, color = color.rgb(136, 255, 0), display = display.all - display.pane - display.price_scale)
// plot(sell and not leverage_for_calculator ? short_amount_lev : na, color = color.rgb(136, 255, 0), display = display.all - display.pane - display.price_scale)