# hg_selftest.js, 2026-11-18T06:56:06.639Z PASS 1 indicators by hand: up-trend bars (EMA seed 20, DI from bar 14, ADX from bar 27) PASS 1 indicators by hand: flat bars (EMA seed 20, DI from bar 14, ADX from bar 27) PASS 1b bar building by hand, 5-minute bars (break, weekend, old halt, 16:15 Friday close, 13:00 holiday close, missing slot) PASS 1b bar building by hand, 60-minute bars (break, weekend, old halt, 16:15 Friday close, 13:00 holiday close, missing slot) PASS 2 hand-built TGT: A: arm on a cross of 30, swing-high tie (latest), target exit; arm on the bar a setup ends; no room; arms ignored in a trade; cut PASS 2 hand-built TRL: A: arm on a cross of 30, swing-high tie (latest), target exit; arm on the bar a setup ends; no room; arms ignored in a trade; cut PASS 2 hand-built TGT: B: no arm at 30 / falling / DI equal / rising without a turn; arm on a turn; DI-cross cancel; touch on the arm bar; previous close below the EMA; unfilled; ADX-to-30 cancel and re-arm PASS 2 hand-built TGT: C: gap fill at the open, stop, re-entry at the original level with its stop, re-entry target; TRL re-entry held to the cut PASS 2 hand-built TRL: C: gap fill at the open, stop, re-entry at the original level with its stop, re-entry target; TRL re-entry held to the cut PASS 2 hand-built TGT: D1: re-entry expires at the trend end T PASS 2 hand-built TGT: D2: no re-entry when T closed before the loss exit PASS 2 hand-built TGT: D3: re-entry filled at or beyond the target is not taken PASS 2 hand-built TGT: D4: only one re-entry (the re-entry is stopped, price comes back, no third trade) PASS 2 hand-built TGT: E: short side; stop and target in one minute (stop); re-entry gap fill at the open; cancel and opposite arm on one bar; TRL short trail PASS 2 hand-built TRL: E: short side; stop and target in one minute (stop); re-entry gap fill at the open; cancel and opposite arm on one bar; TRL short trail PASS 2 hand-built TGT: F: TRL update time, 1-tick buffer, never moving down, a trailing exit above the entry (no re-entry); TGT new arm then no room PASS 2 hand-built TRL: F: TRL update time, 1-tick buffer, never moving down, a trailing exit above the entry (no re-entry); TGT new arm then no room PASS 2 hand-built TGT: G1: first fill at or beyond the target is not taken PASS 2 hand-built TGT: G2: stop in the fill minute, then a re-entry in the same bar PASS 2 hand-built TGT: G3: the target is not checked in the fill minute PASS 2 hand-built TGT: M: a gap through the target fills at the open PASS 2 hand-built TGT: G4: held over the 17:00 break on the roll Thursday (one roll charged); a stop gapped at the 18:01 reopen fills at the open; re-entry expiry PASS 2 hand-built TGT: H: the order is cancelled at the cut PASS 2 hand-built TGT: I: a second arm while ARMED keeps the first arm bar PASS 2 hand-built TGT: J: after a winner, no setup until a new arm PASS 2 hand-built TGT: K1: a low exactly at the EMA is a touch PASS 2 hand-built TGT: K2: a low 1 tick above the EMA is not a touch PASS 2 hand-built TGT: K3: a previous close exactly at the EMA gives no touch PASS 2 hand-built TGT: L: a target 1 tick above the entry is a valid trade (an open at the target fills there) PASS 3 the two readers give the same minutes 5864336 minutes to 2026-11-16 17:00, test part 3436628 to 2019-12-31 17:00 PASS 3 engine = re-implementation HG5-TGT test: setups, trades, indicators at 1,000 seeded bars setups 10237/10237, trades 2307/2307 PASS 3 engine = re-implementation HG5-TGT replication: setups, trades, indicators at 1,000 seeded bars setups 16971/16971, trades 4340/4340 PASS 3 engine = re-implementation HG5-TRL test: setups, trades, indicators at 1,000 seeded bars setups 9658/9658, trades 2360/2360 PASS 3 engine = re-implementation HG5-TRL replication: setups, trades, indicators at 1,000 seeded bars setups 15983/15983, trades 4448/4448 PASS 3 engine = re-implementation HG60-TGT test: setups, trades, indicators at 1,000 seeded bars setups 890/890, trades 307/307 PASS 3 engine = re-implementation HG60-TGT replication: setups, trades, indicators at 1,000 seeded bars setups 1529/1529, trades 502/502 PASS 3 engine = re-implementation HG60-TRL test: setups, trades, indicators at 1,000 seeded bars setups 826/826, trades 318/318 PASS 3 engine = re-implementation HG60-TRL replication: setups, trades, indicators at 1,000 seeded bars setups 1420/1420, trades 521/521 PASS 4 end truncation HG5-TGT: 50 seeded cuts, every setup, fill and exit before the cut equals the full run's 653695 event comparisons PASS 4 end truncation HG5-TRL: 50 seeded cuts, every setup, fill and exit before the cut equals the full run's 667151 event comparisons PASS 4 end truncation HG60-TGT: 50 seeded cuts, every setup, fill and exit before the cut equals the full run's 61956 event comparisons PASS 4 end truncation HG60-TRL: 50 seeded cuts, every setup, fill and exit before the cut equals the full run's 65389 event comparisons PASS 5 start truncation HG5-TGT: indicators equal after 500 bars (1e-6), setups and trades equal from the first bar both runs are IDLE 2012: IDLE in both from 2012-01-05 02:15, 14907 setups; 2014: IDLE in both from 2014-01-06 02:15, 12816 setups; 2016: IDLE in both from 2016-01-05 13:00, 10828 setups; 2018: IDLE in both from 2018-01-03 13:00, 8805 setups; 2021: IDLE in both from 2021-01-05 13:00, 5673 setups; 2024: IDLE in both from 2024-01-03 12:45, 2753 setups PASS 5 start truncation HG5-TRL: indicators equal after 500 bars (1e-6), setups and trades equal from the first bar both runs are IDLE 2012: IDLE in both from 2012-01-05 02:15, 14038 setups; 2014: IDLE in both from 2014-01-06 02:15, 12071 setups; 2016: IDLE in both from 2016-01-05 13:00, 10178 setups; 2018: IDLE in both from 2018-01-03 13:35, 8276 setups; 2021: IDLE in both from 2021-01-05 13:00, 5313 setups; 2024: IDLE in both from 2024-01-03 12:45, 2592 setups PASS 5 start truncation HG60-TGT: indicators equal after 500 bars (1e-6), setups and trades equal from the first bar both runs are IDLE 2012: IDLE in both from 2012-02-02 06:00, 1357 setups; 2014: IDLE in both from 2014-02-10 06:00, 1188 setups; 2016: IDLE in both from 2016-02-02 16:00, 999 setups; 2018: IDLE in both from 2018-01-31 16:00, 824 setups; 2021: IDLE in both from 2021-02-03 10:00, 551 setups; 2024: IDLE in both from 2024-01-31 16:00, 258 setups PASS 5 start truncation HG60-TRL: indicators equal after 500 bars (1e-6), setups and trades equal from the first bar both runs are IDLE 2012: IDLE in both from 2012-02-02 06:00, 1262 setups; 2014: IDLE in both from 2014-02-10 06:00, 1100 setups; 2016: IDLE in both from 2016-02-02 16:00, 927 setups; 2018: IDLE in both from 2018-01-31 16:00, 762 setups; 2021: IDLE in both from 2021-02-03 10:00, 514 setups; 2024: IDLE in both from 2024-01-31 16:00, 247 setups PASS 6 control at offset 0 = the real trades, HG5-TGT test 8561 setups moved (3 outside the usable days), 2306 trades PASS 6 control at offset 0 = the real trades, HG5-TGT replication 6322 setups moved (0 outside the usable days), 2033 trades PASS 6 control at offset 0 = the real trades, HG5-TRL test 8078 setups moved (3 outside the usable days), 2359 trades PASS 6 control at offset 0 = the real trades, HG5-TRL replication 5940 setups moved (0 outside the usable days), 2088 trades PASS 6 control at offset 0 = the real trades, HG60-TGT test 818 setups moved (0 outside the usable days), 307 trades PASS 6 control at offset 0 = the real trades, HG60-TGT replication 571 setups moved (0 outside the usable days), 195 trades PASS 6 control at offset 0 = the real trades, HG60-TRL test 761 setups moved (0 outside the usable days), 318 trades PASS 6 control at offset 0 = the real trades, HG60-TRL replication 534 setups moved (0 outside the usable days), 203 trades PASS 7 mutation detected: sma (HG60-TGT) setups 952/890, trades 333/307 PASS 7 mutation detected: noRise (HG60-TGT) setups 1448/890, trades 414/307 PASS 7 mutation detected: adxAny (HG60-TGT) setups 1044/890, trades 367/307 PASS 7 mutation detected: noTick (HG60-TGT) setups 891/890, trades 313/307 PASS 7 mutation detected: order2 (HG60-TGT) setups 871/890, trades 415/307 PASS 7 mutation detected: tgt20 (HG60-TGT) setups 876/890, trades 312/307 PASS 7 mutation detected: trail4 (HG60-TRL) setups 833/826, trades 323/318 PASS 7 mutation detected: noReentry (HG60-TGT) setups 902/890, trades 270/307 62 of 62 checks passed (25 hand-built runs); SELF-TEST PASSED; 166 s