
This strategy is a trend-following trading system based on multiple technical indicators, integrating Moving Average (MA), Relative Strength Index (RSI), Bollinger Bands (BB), Moving Average Convergence Divergence (MACD), and Stochastic oscillator. It identifies market trends and trading opportunities through cross-confirmation between indicators. The strategy employs percentage-based position management, using 1% of funds for each trade by default.
The strategy determines trading signals through the following dimensions: 1. Uses 14-period Simple Moving Average (SMA) as trend indicator baseline 2. RSI indicator for overbought/oversold conditions, with 30 and 70 as key thresholds 3. Bollinger Bands for price volatility range, with 20-period 4. MACD indicator (12,26,9) for trend confirmation 5. Stochastic oscillator (14,3) for momentum judgment
Long conditions must simultaneously satisfy: - RSI below 30 (oversold) - MACD line crosses above signal line - Stochastic K value below 20 - Closing price above Bollinger Band middle line - Previous closing price below Bollinger Band lower line
Short conditions must simultaneously satisfy: - RSI above 70 (overbought) - MACD line crosses below signal line - Stochastic K value above 80 - Closing price below Bollinger Band middle line - Previous closing price above Bollinger Band upper line
This strategy establishes a relatively complete trend-following trading system through the comprehensive use of multiple technical indicators. The strategy features reliable signals and controllable risk, but still needs continuous parameter and logic optimization in live trading based on market conditions. Through continuous improvement and refinement, this strategy has the potential to achieve stable returns in different market environments.
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"TRB_USDT"}]
*/
//@version=5
strategy("TradingBot Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1)
// Input parameters
lotSize = input.float(0.1, title="Lot Size")
maPeriod = input.int(14, title="MA Period")
rsiPeriod = input.int(14, title="RSI Period")
bbPeriod = input.int(20, title="Bollinger Bands Period")
macdFast = input.int(12, title="MACD Fast EMA")
macdSlow = input.int(26, title="MACD Slow EMA")
macdSignal = input.int(9, title="MACD Signal SMA")
stochK = input.int(14, title="Stochastic %K")
stochD = input.int(3, title="Stochastic %D")
// Indicators
ma = ta.sma(close, maPeriod)
rsi = ta.rsi(close, rsiPeriod)
[bbUpper, bbMiddle, bbLower] = ta.bb(close, bbPeriod, 2)
[macdLine, signalLine, _] = ta.macd(close, macdFast, macdSlow, macdSignal)
k = ta.stoch(close, high, low, stochK)
d = ta.sma(k, stochD)
// Plot indicators
plot(ma, color=color.blue, title="MA", linewidth=1)
hline(70, "RSI Overbought", color=color.red)
hline(30, "RSI Oversold", color=color.green)
plot(rsi, color=color.purple, title="RSI", linewidth=1)
plot(bbUpper, color=color.orange, title="Bollinger Bands Upper", linewidth=1)
plot(bbMiddle, color=color.gray, title="Bollinger Bands Middle", linewidth=1)
plot(bbLower, color=color.orange, title="Bollinger Bands Lower", linewidth=1)
hline(0, "MACD Zero", color=color.gray)
plot(macdLine, color=color.blue, title="MACD Line", linewidth=1)
plot(signalLine, color=color.red, title="MACD Signal Line", linewidth=1)
hline(80, "Stochastic Overbought", color=color.red)
hline(20, "Stochastic Oversold", color=color.green)
plot(k, color=color.blue, title="Stochastic %K", linewidth=1)
plot(d, color=color.red, title="Stochastic %D", linewidth=1)
// Trading logic
longCondition = rsi < 30 and macdLine > signalLine and k < 20 and close > bbMiddle and close[1] < bbLower
shortCondition = rsi > 70 and macdLine < signalLine and k > 80 and close < bbMiddle and close[1] > bbUpper
if (longCondition)
strategy.entry("Buy", strategy.long, qty=lotSize)
label.new(bar_index, low, text="BUY", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small, yloc=yloc.belowbar)
if (shortCondition)
strategy.entry("Sell", strategy.short, qty=lotSize)
label.new(bar_index, high, text="SELL", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small, yloc=yloc.abovebar)