0bps

Strategy vault / Trend following

AlphaTrend use mfi

Pine Script strategy by 发明者量化.

Author
发明者量化
Complexity
Starter · 28 lines
Parameters
3
Backtest bar
1d · swing
Tested on
BTC/USD · spot

IMG

Parameters

NameDefaultWhat it controls
v_input_float_15Multiplier
v_input_114Common Period
v_input_source_10source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4

Source Pine Script

/*backtest
start: 2021-05-05 00:00:00
end: 2022-05-04 23:59:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
*/


indicator('AlphaTrend', shorttitle='AT', overlay=true)

coeff = input.float(5, 'Multiplier')
AP = input(14, 'Common Period')
ATR = ta.sma(ta.tr, AP)
src = input.source(close, "source")
upT = low - ATR * coeff
downT = high + ATR * coeff
AlphaTrend = 0.0
AlphaTrend := ta.mfi(hlc3, 14) >= 50 ? upT < nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : upT : downT > nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : downT

plot(AlphaTrend)

if ta.crossover(low, AlphaTrend)
    strategy.entry("BUY", strategy.long)
else if ta.crossunder(high, AlphaTrend)
    strategy.entry("SELL", strategy.short, when=ta.crossunder(high, AlphaTrend))

Published by 发明者量化 on the FMZ strategy square · last modified 2022-05-06. 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/AlphaTrend-use-mfi.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