
The Spaced Out Trading Strategy is a trend-following strategy based on moving averages. It utilizes a 30-day exponential moving average (EMA) to identify price trends and enters trades when prices break out above/below the EMA. It exits trades when prices fall back below/above the EMA line. This strategy works well with 30-min to daily timeframes.
The core logic relies on the relationship between price and the 30-day EMA to generate entry and exit signals. Specifically:
By capturing trend breakouts, it aims to capitalize on momentum moves and trend-following opportunities.
The main advantages of this strategy include:
Some of the key risks are:
Some ways the strategy can be upgraded:
The Spaced Out Trading Strategy aims to capture trends by trading price breakouts of EMA levels. It is a simple and practical quantitative strategy. With customizable loss limits and judicious optimizations, it can be a stable strategy providing sustainable returns across medium to long-term holding periods.
/*backtest
start: 2024-01-23 00:00:00
end: 2024-02-22 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Spaced Out Trading Strategy", overlay=true)
// Define strategy parameters
emaPeriod = input(30, title="EMA Period") // Longer EMA period for more spaced-out trades
stopLossPct = input(2.0, title="Stop Loss Percentage") // Stop loss percentage
takeProfitPct = input(3.0, title="Take Profit Percentage") // Take profit percentage
// Calculate EMA
emaValue = ta.ema(close, emaPeriod)
// Define entry and exit conditions
enterLong = ta.crossover(close, emaValue)
exitLong = ta.crossunder(close, emaValue)
// Place orders
contractsQty = 5 // Number of contracts to buy
var float lastTradePrice = na // Track the last trade price
if enterLong and strategy.position_size == 0
strategy.entry("Buy Call", strategy.long, qty = contractsQty)
lastTradePrice := close
else if exitLong and strategy.position_size > 0
strategy.close("Buy Call")
lastTradePrice := na
// Calculate stop loss and take profit
stopLossPrice = lastTradePrice * (1 - stopLossPct / 100)
takeProfitPrice = lastTradePrice * (1 + takeProfitPct / 100)
strategy.exit("Sell Call", "Buy Call", stop = stopLossPrice, limit = takeProfitPrice)