MACD + RSI + EMA 200 self-test, 2026-10-26T14:03:13.369Z 1. Indicators and bars (hand-worked) [ok] EMA(3) of 1..5 = -, -, 2, 3, 4 (seeded with the average of the first three): NaN, NaN, 2, 3, 4 [ok] MACD of a straight line 0, 1, 2, ...: EMA12 lags 5.5 and EMA26 lags 12.5, so MACD = 7 from bar 26 and the signal = 7 from bar 34 [ok] RSI(14), ten gains of 1 and four losses of 1: 71.4286 (= 71.4286), then a gain of 2: 75.2381 (Wilder: (avg x 13 + new) / 14) [ok] RSI with no losses = 100; with no change at all = 50 [ok] 60-minute bars close at 09:00, 10:00 (holding 09:01 and 10:00), 11:00; 15-minute bars at 09:00, 09:15, 10:00, 10:15 2. Hand-made days (Wednesday 10 Jan 2024 unless stated; stamps are bar closes, 10:00 = 600) A. a long signal at 10:00: entry 18000 at 10:01, stop 17989.75 (one tick under the swing low 17990), R 10.25; targets 18015.375 (1.5R) and 18020.5 (2R) reached at 10:30 [ok] 1.5R: 291.74 dollars [ok] 2R: 394.24 dollars, 1.9231 R [ok] reference identical (all four variants) B. RSI exactly 50 at the cross: no signal; 50.01: a signal [ok] RSI 50 -> none; 50.01 -> a trade; reference identical C. a bullish cross while the EMA 200 trend is short: no trade; a bearish cross with the trend short and a swing high 18010 above: a short [ok] against the trend: counted, no trade; reference identical [ok] short: stop 18010.25, target 17984.625 at 10:40: 291.74 dollars; reference identical D. the signal window: bars closing 09:30 and 15:35 are outside, 09:35 and 15:30 inside; on an early close (29 Nov 2024, 13:15) 12:45 is the last [ok] signal bar 9:30: no trade; reference identical [ok] signal bar 9:35: a trade; reference identical [ok] signal bar 15:30: a trade; reference identical [ok] signal bar 15:35: no trade; reference identical [ok] early close, signal bar 12:45: a trade; reference identical [ok] early close, signal bar 12:50: no trade; reference identical E. the swing stop: a swing 47 bars back is used, 48 bars back is not; a more recent swing above the signal close is skipped; equal lows are no swing [ok] swing in the bar closing 06:05 (47 back): a trade; 06:00 (48 back): none; reference identical [ok] swing 18005 at 09:45 is above the signal close 18000 -> skipped; the swing 17990 at 09:30 gives the stop 17989.75; reference identical [ok] equal lows 17990 at 09:40 and 09:45: neither is a swing, no trade; reference identical F. the first minute after the signal opens at 17985, below the stop: no trade [ok] no trade; reference identical G. one position at a time: a signal at 10:50 while the 10:00 trade is open is ignored; once the first trade has hit its target (10:30), it is taken [ok] open: 1 trade (the second signal ignored); after the target: 2 trades; reference identical H. stop and target in one minute -> the stop; I. no exit level reached -> out at the close of 16:00 [ok] stopped at 17989.75: -220.76 dollars; reference identical [ok] session close at 16:00, 84.24 dollars; reference identical J. no trade before 3 Feb 2020; K. no trade on a day with fewer than 300 session minutes [ok] 31 Jan 2020: none; 3 Feb 2020: a trade; a day with 230 session minutes is not usable; reference identical 3. Real data: engine against the independent reference 2373779 bars 2020-01-01 18:01 .. 2026-09-25 17:00 New York; 1734 usable days [ok] MRE-15-1.5R: 2433 trades, reference 2433, identical [ok] MRE-15-2R: 2307 trades, reference 2307, identical [ok] MRE-60-1.5R: 2239 trades, reference 2239, identical [ok] MRE-60-2R: 2120 trades, reference 2120, identical 4. Control at offset 0 [ok] MRE-15-1.5R: 2433 control trades reproduce the real trades (entry, exit, result) [ok] MRE-15-2R: 2307 control trades reproduce the real trades (entry, exit, result) [ok] MRE-60-1.5R: 2239 control trades reproduce the real trades (entry, exit, result) [ok] MRE-60-2R: 2120 control trades reproduce the real trades (entry, exit, result) PASSED