LIVE
connecting to the live quote stream…
--:--:--UTC
easyTrading○
#42

Donchian breakout

easyTradingacceptance —~15 min

Implement donchian_signals(highs, lows, closes, window) — for every bar t >= window, emit 1 if the close is STRICTLY above the highest high of the previous window bars (highs[t - window : t], today excluded), -1 if STRICTLY below the lowest low of those bars, else 0.

Buy the breakout, sell the breakdown — the turtle rule, and the workbench's Donchian bot. Return the list of signals, one per bar from t = window onward.

example 1
input
highs=[10.0, 11.0, 12.0, 13.0], lows=[9.0, 10.0, 11.0, 12.0], closes=[9.5, 10.5, 11.5, 12.9], window=2
output
[1, 1]
example 2
input
highs=[10.0, 11.0, 12.0, 13.0], lows=[9.0, 10.0, 11.0, 12.0], closes=[9.5, 10.5, 11.0, 12.5], window=2
output
[0, 1]
note

The third close sits exactly on the prior low — inside the channel, a 0.

constraints
  • 1 ≤ window < len(closes) ≤ 10_000
  • lows ≤ closes ≤ highs elementwise
teacher · 2 hints · the first is free
↗ read the theory
the chapter this problem is cut from
▶ open in the workbench
run the same math on a real tape
●solution.py· utf-8 · spaces:4
ln 1, col 1tab indent · esc leave editor
python 3.13 · pyodide
+ 6 hidden on submit
input · keyword arguments to donchian_signals()
highs=[10.0, 11.0, 12.0, 13.0], lows=[9.0, 10.0, 11.0, 12.0], closes=[9.5, 10.5, 11.5, 12.9], window=2
expected
[1, 1]

the judge calls donchian_signals() with exactly these inputs · outputs are compared to 6 decimal places

● standing bypython 3.13 in your browser · pyodide 0.28.3 · judged on the server to 6 dp⌘↵ run · ⌘⇧↵ submit
paper only · educational · not advice