0bps

Strategy vault / Mean reversion

Four Exponential Moving Averages and Volume Strategy

This strategy combines multiple EMAs with different parameter settings and the EOM volume indicator to determine trends across multiple timeframes and build a trading strategy with both long-term and short-term…

Author
ChaoZhang
Complexity
Intermediate · 48 lines
Parameters
8
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

Overview

This strategy combines multiple EMAs with different parameter settings and the EOM volume indicator to determine trends across multiple timeframes and build a trading strategy with both long-term and short-term judgments. It aims to leverage the multi-timeframe resonance of different period moving averages to uncover longer-lasting trend patterns.

Strategy Logic

The strategy uses 4 groups of EMAs with different period parameters - 13, 21, 50 and 180. These 4 EMAs establish multiple time dimensions to determine price trends and uncover longer-term trend patterns.

The strategy uses the EOM volume indicator to confirm trends. The EOM combines trading volume and price volatility range to effectively gauge buying and selling pressure. The strategy determines long conditions when EOM is above 0 and short conditions when EOM is below 0.

The strategy has two options. Option 1 goes long when shorter EMA crosses above longer EMA and closes long when shorter EMA crosses below longer EMA. Option 2 goes long when shorter EMA crosses above intermediate EMA and closes long when shorter EMA crosses below intermediate EMA. The two options allow more comprehensive trend confirmation.

Advantages

  • Using multi-timeframe EMAs to determine trends can uncover longer-term trend patterns
  • EOM volume indicator effectively gauges buying/selling pressure, avoiding false signals from temporary pullbacks
  • Two optional entry methods enable more comprehensive trend confirmation
  • Scaling out with layered exits reduces single exit exposure

Risks

  • EMAs have lag and may miss fast reversals
  • Volume indicators can give false signals
  • Multiple condition criteria creates unclear entry
  • Layered exits may be too mechanistic

Enhancement Opportunities

  • Test more EMA period combinations to find optimal parameters
  • Add other indicators like MACD for entry confirmation
  • Adopt dynamic trailing stop loss to follow trends
  • Adjust position sizing based on market conditions

Summary

This strategy integrates multi-timeframe EMA trend determination and volume indicator filtering to achieve trend following and noise removal. There is still large room for optimization by testing different parameter combinations and adding more indicators to further improve robustness. Meanwhile, dynamic stop loss and position sizing can also significantly optimize performance.

Parameters

NameDefaultWhat it controls
v_input_113ema1l
v_input_221ema2l
v_input_350ema3l
v_input_4180ema4l
v_input_514length
v_input_610000Divisor
v_input_7trueoption1
v_input_8falseoption2

Source Pine Script

/*backtest
start: 2022-10-02 00:00:00
end: 2023-10-08 00:00:00
period: 1d
basePeriod: 1h
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/
// © SoftKill21

//@version=4
strategy("4x ema + volume", overlay=true,initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent , commission_value=0.1 )

//ema x 4
ema1l=input(13)
ema2l=input(21)
ema3l=input(50)
ema4l=input(180)

ema1=ema(close,ema1l)
ema2=ema(close,ema2l)
ema3=ema(close,ema3l)
ema4=ema(close,ema4l)

long1 = close > ema1 and ema1 > ema2 and ema2> ema3 and ema3 > ema4
long2 = crossover(ema1,ema2) and crossover(ema1,ema3)

short1 = close < ema1 and ema1 < ema2 and ema2< ema3 and ema3 < ema4
short2= crossunder(ema1,ema2) and crossunder(ema1,ema3)


//eom
length = input(14, minval=1)
div = input(10000, title="Divisor", minval=1)
eom = sma(div * change(hl2) * (high - low) / volume, length)


option1=input(true)
option2=input(false)

if(option1)
    strategy.entry("long",1,when=long1 and eom>0)
    strategy.close("long",when=short1 and eom<0)
 
if(option2)
    strategy.entry("long",1,when=long2 and eom>0)
    strategy.close("long",when=short2 and eom<0)   

Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-09. 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/Four-Exponential-Moving-Averages-and-Volume-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