0bps

Strategy vault / Trend following

Simple Moving Average Crossover with Stop Loss Strategy

This strategy generates trading signals by crossover between Simple Moving Average and Volume Weighted Average Price, and uses Exponential Moving Average as stop loss, belonging to short-term trend following trading…

Author
ChaoZhang
Complexity
Starter · 26 lines
Parameters
0
Backtest bar
2h · intraday
Tested on
BTC/USDT · futures

Overview

This strategy generates trading signals by crossover between Simple Moving Average and Volume Weighted Average Price, and uses Exponential Moving Average as stop loss, belonging to short-term trend following trading strategies.

Strategy Logic

  1. Calculate 5-day Simple Moving Average (SMA) and Volume Weighted Average Price (VWAP).

  2. When SMA crosses above VWAP from below, generate long signal; when crossing below from above, generate short signal.

  3. SMA is sensitive to price changes and can capture short-term trends. VWAP reflects latest price dynamics. Their crossover identifies short-term trend changes.

  4. Set 9-day Exponential Moving Average (EMA) as stop loss. EMA reacts slower than SMA, providing stop loss buffer.

  5. Execute trades on long/short signals. Exit when price drops below stop loss to control risks.

The strategy mainly uses the crossover of the fast-reacting SMA and realtime VWAP to capture short-term price fluctuations, with EMA trailing stop to manage risks, simple and intuitive.

Advantage Analysis

  1. SMA and VWAP crossover is simple and effective for short-term trend changes.

  2. EMA stop loss provides buffer avoiding premature stop out.

  3. Clear signals and simple rules, easy to execute.

  4. Large optimization space, adjustable to different market environments.

  5. Can modify stop loss mechanism to control single trade loss amount.

  6. Easy to expand, can introduce other technical indicators or risk management techniques.

Risk Analysis

  1. SMA and VWAP crossover may have lags or wrong signals.

  2. Stop loss range too tight risks over-optimization. Real trading should watch for stop loss breaches.

  3. Only applicable for short-term ranges, cannot track long-term trends.

  4. Improper backtest period risks curve fitting.

  5. Need to consider trading cost impact on profitability.

Optimization Directions

  1. Test different parameter combinations for SMA and VWAP.

  2. Optimize EMA stop loss period parameter.

  3. Try other MA types or indicators for stop loss.

  4. Add position sizing and risk management strategies.

  5. Introduce machine learning algorithms for parameter optimization.

  6. Evaluate periodically adjusting parameters to adapt to market changes.

Summary

This SMA and VWAP crossover strategy with EMA trailing stop can be adjusted for short-term fluctuations via parameters, simple to operate, a typical short-term tracking strategy idea. Adding more indicators or algorithms can improve stability, also usable as a module integrated into more complex multi-strategy systems. Overall an easy to use strategy with great inspirational value for practical trading.

Source Pine Script

/*backtest
start: 2023-08-19 00:00:00
end: 2023-09-18 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © realisticDove62527

//@version=5
strategy("ROoT", overlay=true, margin_long=1, margin_short=1)

longCondition = ta.crossover(ta.sma(close, 5), ta.vwap(hlc3))
if (longCondition)
    strategy.entry("BUY", strategy.long)

shortCondition = ta.crossunder(ta.sma(close, 5), ta.vwap(hlc3))
if (shortCondition)
    strategy.entry("SELL", strategy.short)
    

stoploss = ta.ema(close, 9)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-19. 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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Simple-Moving-Average-Crossover-with-Stop-Loss-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open