;; https://www.investopedia.com/articles/active-trading/101014/basics-algorithmic-trading-concepts-and-examples.asp (define-trade-algo (given (moving-average (stock "USD/gold") (duration (days 200)))) (let ((short-term-trend (moving-average (stock "USD/gold") (duration (days 50)))) (long-term-trend (moving-average (stock "USD/gold") (duration (days 200)))) (significant-difference 0.1)) (cond ((> (- short-term-trend long-term-trend) significant-difference) (buy (stock "USD/gold") 50)) ((< (- short-term-trend long-term-trend) significant-difference) (sell (stock "USD/gold") 50))))) ;; might expand into the following asynchronous callback code (begin (let ((queue (obtain-queue!))) (exchange-orders (lambda (exchange) (let ((command (dequeue! queue))) (case command ((buy) (fix! exchange 'buy "USD/gold" 50)) ((sell) (fix! exchange 'sell "USD/gold" 50)))))) (monitor-stock (lambda (backlog) (let ((short-term-trend (moving-average backlog (* 50 duration/days))) (long-term-trend (moving-average backlog (* 200 duration/days))) (significant-difference 0.1)) (cond ((> (- short-term-trend long-term-trend) significant-difference) (enqueue! queue 'buy)) ((< (- short-term-trend long-term-trend) significant-difference) (enqueue! queue 'sell))))))))