0bps

Strategy vault / Other

3 EMA

backtest

Pine ScriptOtherEMA
Author
ChaoZhang
Complexity
Starter · 49 lines
Parameters
3
Backtest bar
5m · intraday
Tested on
BTC/USDT · futures

backtest

IMG

Parameters

NameDefaultWhat it controls
v_input_int_120Short-term Moving Average
v_input_int_250Medium-term moving average
v_input_int_3100Long-term moving average

Source Pine Script

/*backtest
start: 2022-05-03 00:00:00
end: 2022-05-09 23:59:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
indicator("3EMA ", overlay=true)

short = input.int(20, "Short-term Moving Average")
mid = input.int(50, "Medium-term moving average")
long = input.int(100, "Long-term moving average")

short_ma = ta.ema(close, short)
mid_ma = ta.ema(close, mid)
long_ma = ta.ema(close, long)

long_condition = (short_ma > mid_ma) and (mid_ma > long_ma) and (ta.rising(mid_ma, 2))

IN_LONG_AREA = long_condition and (close > mid_ma) and (close <= short_ma)

short_condition = (short_ma < mid_ma) and (mid_ma < long_ma) and (ta.falling(mid_ma, 2))

IN_SHORT_AREA = short_condition and (close <= mid_ma) and (close > short_ma)

if IN_LONG_AREA
    alert("Long " +timeframe.period+" "+ syminfo.basecurrency)
else if IN_SHORT_AREA
    alert("Short " +timeframe.period+" "+ syminfo.basecurrency)

p3 = plot(long_ma, color=color.red, linewidth=1, title='LONG EMA')
p2 = plot(mid_ma, color=color.orange, linewidth=1, title='MID EMA')
p1 = plot(short_ma, color=color.green, linewidth=1, title='SHORT EMA')


fill(p1, p2, color=long_condition?color.new(color.green, 65):color.new(color.white, 100))
fill(p1, p2, color=short_condition?color.new(color.red, 65):color.new(color.white, 100))


bgcolor(IN_LONG_AREA ? color.new(color.green, 90) : na)
bgcolor(IN_SHORT_AREA ? color.new(color.red, 90) : na)


if IN_LONG_AREA
    strategy.entry("Enter Long", strategy.long)
else if IN_SHORT_AREA
    strategy.entry("Enter Short", strategy.short)

Published by ChaoZhang on the FMZ strategy square · last modified 2022-05-12. 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/3EMA.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