-
Notifications
You must be signed in to change notification settings - Fork 1k
Improve AMA indicator parity with Cython #2626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ten practical ways to put
|
# | Use-case | Why AMA adds value | How you’d wire it in |
---|---|---|---|
1 | Dynamic trend-following strategy | AMA hugs price when markets are quiet and backs off in noisy bursts, reducing whipsaws vs. fixed-length EMAs. | Feed live QuoteTick s; go long when price crosses above AMA, flat/short on cross-down. |
2 | Adaptive trade exit filter | Instead of a static stop, trail the AMA a few ticks behind the position—lag expands in choppy phases, avoiding premature exits. | Recompute AMA on every trade tick; update stop-loss to AMA(value) – k·ATR . |
3 | Signal confirmation layer | Pair with fast oscillators (RSI, Stoch). Trade only when oscillator crosses and price is also on the AMA’s “right” side. | Require RSI > 70 and price > AMA for shorts, the reverse for longs. |
4 | Volatility-weighted position sizing | AMA’s α adapts to Efficiency Ratio; its smoothing constant is a real-time proxy for noise. Larger dispersion ⇒ smaller size. | Compute sc = (ER·α_diff + α_slow)^2 ; scale order size by 1 / sc . |
5 | Regime detection (trend vs. range) | Flat AMA (low slope) + low ER → ranging; steep AMA + high ER → trending. | Monitor slope = (AMA_t – AMA_{t-1}) / price ; switch strategies per regime. |
6 | Event-driven alpha tests | Measure how quickly AMA “snaps” after news releases—fast convergence implies strong consensus. | Timestamp news headline; record ticks until ` |
7 | Portfolio rotation filter | On daily bars across a watch-list, rank symbols by distance above/below their AMA; rotate into top momentum names. | Batch-update AMA per symbol in a nightly job; sort by (close/AMA – 1) . |
8 | Latency-robust back-tester | Because AMA embeds its own noise filter, it’s forgiving of sparse historical trade data—fewer look-back artifacts than HMA/TEMA. | Drive update_raw() with OHLC Bar s instead of tick data. |
9 | Risk clock for market-making | Widen spreads when AMA widens (indicating volatility) and tighten when AMA compresses. | Compute σ of (price – AMA) over sliding window; map to spread tier. |
10 | Embedded metric in on-chain oracle | AMA’s low-noise property lends itself to DeFi price oracles that must resist manipulation spikes but stay reactive. | Run AMA in a Rust WASM module; publish AMA.value to the chain each block. |
Implementation pointers
- Period selection – Common combos:
(ER=10, fast=2, slow=30)
intraday;(ER=20, fast=2, slow=20)
daily. Tune with walk-forward. - Feed choice – Pass
PriceType::Last
for mid-quotes;PriceType::Bid
/Ask
for aggressive market-making logic. - Thread safety –
AdaptiveMovingAverage
is#[repr(C)]
but notSend + Sync
; wrap inMutex
for multi-threaded engines. - Zero-state re-use – Call
reset()
between back-test runs to avoid cross-contamination of statistics.
Thanks, I like your practical ways table, I suppose it's possible to get similar tables from LLMs for other indicators, it's useful. |
Great work @nicolad! Many thanks for the contribution 🙏, the chart and table are useful. |
cjdsellers
approved these changes
May 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Detailed comparison
slow > fast
count
incrementsprior_value
resetRelated to #2507