8 Hours EMA
JavaScript strategy by Crypto Joe.
The original spec has no written description. Read the source below.
Source JavaScript
/*backtest
start: 2022-11-01 00:00:00
end: 2024-05-14 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Binance","currency":"BTC_USDT","stocks":0}]
*/
function main(){
let lastK;
let bought;
exchange.SetMaxBarLen = 1000;
while (true) {
const records = exchange.GetRecords(PERIOD_H1 * 8);
// if (records.length <= 676) continue;
// Log(records.length);
if (!lastK || records[records.length - 1].Time != lastK.Time) {
lastK = records[records.length - 1];
} else {
continue;
}
// records The last one k The line is generated at the opening k line needs to be removed because we only care about the closing K Line
records.splice(-1);
const ema169 = talib.EMA(records, 169);
const ema12 = talib.EMA(records, 12);
const ema676 = talib.EMA(records, 676);
$.PlotLine('EMA169', ema169[ema169.length - 1]);
$.PlotLine('EMA12', ema12[ema12.length - 1]);
$.PlotLine('EMA676', ema676[ema676.length - 1]);
const account = _C(exchange.GetAccount);
const ticker = _C(exchange.GetTicker);
const cross = _Cross(ema12, ema169);
if (!bought && cross > 0) {
exchange.Buy(ticker.Last, 0.99 * account.Balance / ticker.Last);
bought = true;
}
if (bought && cross < 0) {
exchange.Sell(ticker.Last, account.Stocks);
bought = false;
}
}
}Published by Crypto Joe on the FMZ strategy square · last modified 2024-05-15. 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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/8-Hours-EMA.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- Test About the Long Term Effect of MartinJavaScript · Other · 1d
- Three Moving Average System ExodusJavaScript · Other · 1h
- Digital Currency Spot Multi Variety Double Moving Average Strategy TeachingJavaScript · Other
- Teaching Strategy TCI Strategy Mai Language TransplantationJavaScript · Other · 1d
- Test Using KDJ and VOL Volume to Filter for Coins with Potential to RiseJavaScript · Other · 1d
- Digital Currency Futures Double Moving Average Turning Point Strategy TeachingJavaScript · Other · 1h