
This strategy is a trend-following system based on Exponential Moving Average (EMA) crossovers, incorporating dynamic position sizing and risk management. It uses fast and slow EMA crossover signals to identify market trends while dynamically adjusting trade sizes through percentage risk calculations and employing trailing stops to protect profits.
The core logic relies on two EMAs with different periods (default 9 and 21). A long entry signal is generated when the fast EMA crosses above the slow EMA, while positions are closed when the fast EMA crosses below the slow EMA. Each trade size is dynamically calculated based on a fixed percentage risk (default 1%) of total account equity, with take-profit levels set according to risk-reward ratios and percentage-based trailing stops.
This is a complete trading system that combines classical technical analysis methods with modern risk management concepts. The strategy controls risk through dynamic position sizing and trailing stops while capturing trending opportunities using EMA crossovers. While there are some inherent limitations, the suggested optimization directions can further enhance the strategy’s robustness and adaptability. The strategy is particularly suitable for long-term trend trading with controlled risk.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Bitcoin Exponential Profit Strategy", overlay=true)
// User settings
fastLength = input.int(9, title="Fast EMA Length", minval=1)
slowLength = input.int(21, title="Slow EMA Length", minval=1)
riskPercent = input.float(1, title="Risk % Per Trade", step=0.1) / 100
rewardMultiplier = input.float(2, title="Reward Multiplier (R:R)", step=0.1)
trailOffsetPercent = input.float(0.5, title="Trailing Stop Offset %", step=0.1) / 100
// Calculate EMAs
fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)
// Plot EMAs
plot(fastEMA, color=color.blue, title="Fast EMA")
plot(slowEMA, color=color.red, title="Slow EMA")
// Account balance and dynamic position sizing
capital = strategy.equity
riskAmount = capital * riskPercent
// Define Stop Loss and Take Profit Levels
stopLossLevel = close * (1 - riskPercent)
takeProfitLevel = close * (1 + rewardMultiplier * riskPercent)
// Trailing stop offset
trailOffset = close * trailOffsetPercent
// Entry Condition: Bullish Crossover
if ta.crossover(fastEMA, slowEMA)
positionSize = riskAmount / math.max(close - stopLossLevel, 0.01) // Prevent division by zero
strategy.entry("Long", strategy.long, qty=positionSize)
strategy.exit("TakeProfit", from_entry="Long", stop=stopLossLevel, limit=takeProfitLevel, trail_offset=trailOffset)
// Exit Condition: Bearish Crossunder
if ta.crossunder(fastEMA, slowEMA)
strategy.close("Long")
// Labels for Signals
if ta.crossover(fastEMA, slowEMA)
label.new(bar_index, low, "BUY", color=color.green, textcolor=color.white, style=label.style_label_up)
if ta.crossunder(fastEMA, slowEMA)
label.new(bar_index, high, "SELL", color=color.red, textcolor=color.white, style=label.style_label_down)