Strategy vault / Trend following
Simple Moving Average Crossover Strategy 427445
This strategy trades based on golden cross and dead cross of 3 simple moving averages. It goes long when the fast SMA crosses above mid SMA and mid SMA crosses above slow SMA; It goes short when the reverse crossover…
Overview
This strategy trades based on golden cross and dead cross of 3 simple moving averages. It goes long when the fast SMA crosses above mid SMA and mid SMA crosses above slow SMA; It goes short when the reverse crossover happens.
Strategy Logic
- Set 3 SMAs with different periods: fast, mid, slow
- Go long when fast SMA crosses above mid SMA and mid above slow SMA
- Go short when fast SMA crosses below mid SMA and mid below slow SMA
- Can set entry delay to avoid false breakouts
- Exit when reverse crossover signal triggers
Specifically, it utilizes the crossovers between 3 SMAs of different periods to trade. The fast SMA represents short term trend, mid SMA represents medium term trend, and slow SMA represents long term trend. When the three SMAs crossover upward in sequence, it signals an uptrend to go long. When downward crossover happens, it signals a downtrend to go short. Entry delay can also be set to avoid short term false breakouts.
Advantage Analysis
- Using 3 SMAs improves directional accuracy
- Delayed entry avoids false breakouts and being trapped
- Simple and intuitive logic, easy to understand
- Flexible SMA parameter tuning for different cycles
- Trend following avoids counter-trend risks
Risk Analysis
- Long holding in long cycle risks loss expansion
- SMA crossover has some lag, may miss best entry points
- Requires SMA parameter optimization, otherwise signals may be inaccurate
- Long holding introduces overnight risks
Risks can be managed through position sizing, SMA optimization, stop loss strategies etc.
Optimization Directions
- Test different SMA periods to find optimal parameters
- Evaluate entry delay to filter out signals
- Introduce stop loss adaptable to actual price action
- Study parameter preference across different products
- Test adding re-entry and pyramiding rules to optimize holding
Summary
This strategy holds positions based on 3 SMA crossovers to determine trend direction. Pros are simple clear signals and configurability; Cons are lagging signals and parameter dependency. Performance can be improved and risks controlled through parameter optimization, stop loss etc. It helps traders master using SMA and crossover strategies.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 20 | SMA Top |
| v_input_2 | 50 | SMA Mid |
| v_input_3 | 200 | SMA Low |
| v_input_4 | 5 | Long: After trigger, how many bars to wait? |
| v_input_5 | 5 | Short: After trigger, how many bars to wait? |
Source Pine Script
/*backtest
start: 2023-08-21 00:00:00
end: 2023-09-20 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// © DaynTrading
//@version=4
// strategy(
// title="Simple Moving Average Cross",
// overlay=true,
// initial_capital=5000,
// default_qty_type=strategy.percent_of_equity,
// default_qty_value=2,
// commission_type=strategy.commission.percent,
// commission_value=0.075,
// pyramiding=0
// )
sma_top_input = input(title="SMA Top", type=input.integer, defval=20)
sma_mid_input = input(title="SMA Mid", type=input.integer, defval=50)
sma_low_input = input(title="SMA Low", type=input.integer, defval=200)
bars_long = input(title="Long: After trigger, how many bars to wait?", type=input.integer, defval=5)
bars_short = input(title="Short: After trigger, how many bars to wait?", type=input.integer, defval=5)
sma_top = sma(close, sma_top_input)
sma_mid = sma(close, sma_mid_input)
sma_low = sma(close, sma_low_input)
long = sma_top > sma_mid and sma_mid > sma_low
short = sma_top < sma_mid and sma_mid < sma_low
long_condition = long and long[bars_long] and not long[bars_long + 1]
short_condition = short and short[bars_short] and not short[bars_short + 1]
close_long = sma_top < sma_mid and sma_mid < sma_low and not long[bars_long + 1]
close_short = sma_top > sma_mid and sma_mid > sma_low and not short[bars_short + 1]
plot(sma_top, title="SMA Top", color=#95f252, linewidth=2)
plot(sma_mid, title="SMA Mid", color=#FF1493, linewidth=2)
plot(sma_low, title="SMA Low", color=#6a0dad, linewidth=2)
strategy.entry("LongPosition", strategy.long, when = long_condition)
strategy.entry("ShortPosition", strategy.short, when = short_condition)
strategy.close("LongPosition", when = close_short)
strategy.close("ShortPosition", when = close_long)Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-21. 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/Simple-Moving-Average-Crossover-Strategy-427445.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
- ADX MA and EMA Long Only Trend Tracking StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- Adaptive FVG Detection and MA Trend Trading Strategy with Dynamic ResistancePine Script · Trend following · 1d
- Adaptive Risk Management Strategy Based on Dynamic ATR and Moving Average CrossoverPine Script · Trend following · 2h
- Adaptive Trading Strategy Based on Stochastic RSI Dual Line CrossoverPine Script · Trend following · 4h
- Adaptive Volatility Based Trend Following Short Strategy with Time Delay and Stop Loss ProtectionPine Script · Trend following · 2m