Strategy vault / Tools & templates
Share ATR Example Mean Calculation Fault Tolerant Tutorial
In order to give back to the FMZ platform and community, share strategies & codes & ideas & templates Introduction: Detailed mean calculation steps, using ATR as an example. includes details such as metric calls…
In order to give back to the FMZ platform and community, share strategies & codes & ideas & templates
Introduction: Detailed mean calculation steps, using ATR as an example. includes details such as metric calls, insufficient fault tolerance for data points, and fault tolerance for unexpected data errors The key to the strategy is grasping the details.
Welcome to cooperate and communicate, learn and progress together~ v:haiyanyydss
Source JavaScript
var arecords = _C(exchange.GetRecords, 300);
var time = arecords[arecords.length - 1].Time
var nowtime = time;
var atremaarr = [];
var Onoff = 0;
function main() {
while (true) {
//Start here Put this section in a loop
var Num = 50; //Can change, average of several candles
var records = _C(exchange.GetRecords, 300);
var atr = TA.EMA(records, 9)
nowtime = records[records.length - 1].Time
if (nowtime > time || Onoff == 0) {
atr = atr.slice(atr.length - (20 + Num));
for (var i = 0; i < (atr.length - Num); i++) { //(atr.length-Num) Length minus the period, for example500Before root50The root is an inaccurate average, here we just take450
var atremTEMP = 0; //The calculation for the sum, initially set to0
for (var j = 0; j < Num; j++) { //Sum
atrTEMP = atr[i + j] > 0 ? atr[i + j] : 0; //Remove unexpected data, take values greater than O, less than O, or other casesO
atremTEMP += atrTEMP;
}
atremaarr.push(atremTEMP / Num); //Take averagePTo array
}
time = nowtime;
Onoff += 1;
Log("Calculate the:", Onoff, "times.");
}
//Settle here and put this segment into the loop
Sleep(3000)
Log("The last one:", _N(atremaarr[atremaarr.length - 1], 2)) //Get Value
//Log("Second-to-last candle:", _N(atremaarr[atremaarr.length-2],2))
}
}
Published by 作手君TradeMan on the FMZ strategy square · last modified 2023-02-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.
/agenkit build a tested, production-ready module from strategies/Share-ATR-Example-Mean-Calculation-Fault-Tolerant-Tutorial.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
- Digital Currency Futures Multi Variety ATR Strategy TeachingJavaScript · Tools & templates · 1d
- Trade04 Double Moving Average ATR Channel High and Low PointsMyLanguage · Tools & templates
- Indicator Library Python VersionPython · Tools & templates
- ML Alerts TemplatePine Script · Tools & templates · 2h
- Moon Launch Alerts Template IndicatorPine Script · Tools & templates · 5m
- Platform Price Indicator Monitoring 11JavaScript · Tools & templates