0bps

Strategy vault / Breakout

Moving Average Breakthrough

JavaScript strategy by Crypto Joe.

JavaScriptBreakout
Author
Crypto Joe
Complexity
Starter · 35 lines
Parameters
1
Backtest bar
1d · swing
Tested on
BTC/USDT · spot

The original spec has no written description. Read the source below.

Parameters

NameDefaultWhat it controls
PERIOD120Skip daily line

Source JavaScript

/*backtest
start: 2019-02-01 00:00:00
end: 2024-03-04 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/

function main(){
    var bought = false;
    var lastTime = 0;
    while (true) {
        var needCalculate = false;
        var records = exchange.GetRecords(PERIOD_D1);
        var lastK = records[records.length-1];
        if (lastTime == 0 || lastK.Time > lastTime) {
            lastTime = lastK.Time;
            // Only need to consider whether to trade when new daily data comes in
            needCalculate = true;
        }
        if (!needCalculate) continue;
        var ma = TA.MA(records, PERIOD);
        var lastMa = ma[ma.length - 1];
        var account = exchange.GetAccount();
        var ticker = exchange.GetTicker();
        if (lastK.Close >= lastMa && !bought) {
            exchange.Buy(ticker.Last, account.Balance * 0.95 / ticker.Last);
            bought = true;
        } else if (lastK.Close < lastMa && bought) {
            exchange.Sell(ticker.Last, account.Stocks);
            bought = false;
        }
    }

}

Published by Crypto Joe on the FMZ strategy square · last modified 2024-03-24. 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/Moving-Average-Breakthrough.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