LIVE·WAITING…
connecting to the live quote stream…
--:--:--UTC
#41
SMA crossover signals
easyTradingacceptance —~15 min
Implement sma_cross_signals(closes, fast, slow) — for every bar where both simple moving averages exist (from index slow - 1 onward), emit 1 if the fast SMA is strictly above the slow, -1 if strictly below, and 0 when they are exactly equal.
It is the oldest trend signal there is and the workbench's first bot. Return the list of signals.
example 1
input
closes=[10.0, 11.0, 12.0, 13.0, 12.0, 11.0], fast=2, slow=3
output
[1, 1, 1, -1]
example 2
input
closes=[10.0, 12.0, 11.0, 11.0, 11.0, 13.0], fast=2, slow=3
output
[1, -1, 0, 1]
note
Three flat closes make the two averages equal — a 0, not a buy.
constraints
- 1 ≤ fast < slow ≤ len(closes) ≤ 10_000
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 sma_cross_signals()
closes=[10.0, 11.0, 12.0, 13.0, 12.0, 11.0], fast=2, slow=3
expected
[1, 1, 1, -1]
the judge calls sma_cross_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