Strategy vault / Machine learning
Spaced Out Trading Strategy
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…

Overview
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.
Strategy Logic
The core logic relies on the relationship between price and the 30-day EMA to generate entry and exit signals. Specifically:
- Calculate the 30-day EMA as the benchmark for the trend.
- Enter long trades when prices break out above the EMA.
- Exit trades when prices fall back below the EMA.
By capturing trend breakouts, it aims to capitalize on momentum moves and trend-following opportunities.
Advantage Analysis
The main advantages of this strategy include:
- Simple logic that is easy to understand and implement at low costs.
- Smoothens price fluctuations using EMA and focuses on the main trend.
- The 30-day EMA provides a medium-term lens to capture both swing and long-term trends.
- Customizable parameters adaptable across products and market regimes.
Risks and Mitigations
Some of the key risks are:
- Whipsaw risk from prices reversing after temporary breakout of EMAs. Can use longer EMA periods.
- Risk of accumulated losses from sustained trend reversal. Can set stop-loss limits.
- Suboptimal EMA period risk. Can ensemble adaptive EMA or multiple EMAs.
Enhancement Opportunities
Some ways the strategy can be upgraded:
- Add adaptive EMAs tailored to market volatility and asset characteristics.
- Build multi-EMA systems combining short and long-term EMAs.
- Incorporate stop-loss mechanisms e.g. moving average stop, range bound stop.
- Combine with other indicators e.g. momentum, volatility for signal filtering.
- Parameter optimization via machine learning algorithms.
Summary
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.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 30 | EMA Period |
| v_input_2 | 2 | Stop Loss Percentage |
| v_input_3 | 3 | Take Profit Percentage |
Source Pine Script
/*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)Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-23. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Spaced-Out-Trading-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- AI Driven Dynamic Volatility Adaptive Trend Breakout Trading StrategyPine Script · Machine learning · 2d
- Dual Moving Average Matching Strategy Based on Bollinger BandsPine Script · Machine learning · 1h
- Dynamic Weighted Moving Average Trading StrategyPine Script · Machine learning · 1d
- EMA and RSI Quantitative Trading StrategyPine Script · Machine learning · 1h
- Fibonacci Retracement Dynamic Stop Loss StrategyPine Script · Machine learning · 1h
- MACD Robot Trading StrategyPine Script · Machine learning · 1d