VALYNOXSTRATEGY RESEARCH TECHNOLOGY
AlphaPrimeAlphaPrime
ACADEMY / Indicators and signals

Entropy indicator trading: measuring randomness, and an ES test

An entropy indicator measures how evenly recent bar returns are spread across size buckets. It reports how disordered the recent moves were, not which way price goes next, so it belongs in front of a direction rule as a filter, and the honest test compares the same rule with and without it under the same costs.

By · Published · updated · Editorial policy

Contents
  1. Can an entropy indicator measure how random price moves are?
  2. How is an entropy indicator calculated?
  3. What does low entropy mean for a market, and what does high entropy mean?
  4. What window length and how many bins should an entropy indicator use?
  5. Does an entropy indicator work as a trading filter?
  6. What did an ES test of an entropy rule show, and where are its limits?
  7. Frequently asked questions
  8. References

Can an entropy indicator measure how random price moves are?

In entropy indicator trading, the indicator measures how evenly recent bar returns are spread across size buckets: a low reading means most moves were alike, a high reading means they were scattered. It tells you how disordered the recent moves were, not where price goes next, so it is a filter to test, not a signal to trust.

Think of a jar of marbles. If almost every marble is red, the jar is orderly and you can guess the colour of the next one you draw. If the marbles come in eight colours in equal numbers, the jar is mixed and a guess is close to random. Shannon entropy is a number that says how evenly a set of outcomes is spread across its possible categories, from zero when everything sits in one category to a maximum when every category holds the same share. Applied to a market, the outcomes are the last N bar returns and the categories are size buckets, so the reading describes how mixed the recent returns were.

What the jar does not tell you is whether the next marble is red or blue when the jar is mixed, and the entropy of returns does not tell you whether the next bar is up or down. A steady uptrend and a steady downtrend produce the same low reading. That is the one claim this article defends from start to finish: an entropy indicator is a randomness indicator that can gate a direction rule, and on its own it has nothing to say about direction. The guide to technical analysis tools and indicators you can test sorts indicators by what they measure, and entropy sits with the ones that describe the state of the market rather than its next move.

Two histograms of 24 returns sorted into eight size bins: on the left most returns sit in two bins and the entropy is low at 0.51, on the right the returns are spread evenly and the entropy is high at 1.00, and in both cases the direction of the next move is unknown Spread, not direction Illustration: 24 returns, 8 bins Low entropy 0.51 High entropy 1.00 Direction: ? Direction: ? Entropy says how mixed, not which way. So: pair it with a direction rule.
The same number of returns, two very different spreads. Entropy reads the spread; the direction stays unknown in both cases.

How is an entropy indicator calculated?

Shannon entropy of returns is built in four steps, and only the last one involves a logarithm. A bin is a size bucket that collects every return falling between two edges, for example all returns between plus 0.2 percent and plus 0.4 percent. Once the returns are counted per bin, the rest is arithmetic you can do in a spreadsheet.

  1. Take the last N bar returns. The return of a bar is its close divided by the previous close, minus one. N is the window length, covered in a later section.
  2. Sort them into K bins. The bin edges can be fixed widths across the range of the window, or multiples of the recent standard deviation so that the edges adjust when volatility changes. Whichever you choose, keep it the same for the whole test.
  3. Turn the counts into probabilities. Divide the count in each bin by N. Each result is the share of recent returns that landed in that bin, written p.
  4. Sum probability times the log of probability, and flip the sign. Empty bins are skipped because the log of zero is undefined. To put the result on a 0 to 1 scale, divide by the log of the bin count K, which is the value a perfectly even spread would reach.

The one formula in this article: entropy = −Σ p × log(p). Here p is the share of recent returns in one bin, log(p) is the logarithm of that share (any base works once you scale by the log of K), Σ means "add this up over every bin that holds at least one return", and the minus sign turns the negative sum into a positive number. After scaling, a reading near 1 means the returns were spread almost evenly, and a reading near 0 means almost all of them fell into one bin.

Hypothetical example

Take a window of 20 daily returns and 4 bins. Suppose the counts are 10, 8, 1 and 1. The shares are 0.5, 0.4, 0.05 and 0.05. Using base-2 logs: 0.5 × 1 = 0.5; 0.4 × 1.32 ≈ 0.53; each 0.05 × 4.32 ≈ 0.22, twice is 0.43. The sum is about 1.46 bits. A perfectly even spread of 5, 5, 5, 5 would give 2 bits, so the scaled entropy is about 1.46 ÷ 2 ≈ 0.73. If the counts had been 18, 2, 0, 0 the scaled reading would drop to about 0.24: most returns in one bin, a far more orderly window.

Four steps from a window of returns to one number: take the last N returns, sort them into K bins, turn the counts into shares p, then sum minus p times log p and scale, so one bin holding everything gives 0 and all bins equal gives 1 From returns to one number Entropy = −Σ p × log p, scaled 0–1 Returns Bins Shares p Entropy 0: one bin 1: all equal Bins and window set the result. So: fix both before you test.
From a window of returns to one number between 0 and 1. The bins and the window length are the two choices that change the result.

What does low entropy mean for a market, and what does high entropy mean?

Low entropy means recent returns piled into a few bins, which happens in a steady trend and also in a very quiet range, while high entropy means returns scattered across many bins, which is the mark of a choppy, news-driven stretch. The reading separates orderly from disorderly, and nothing else. Two orderly markets can differ in direction and in volatility, and the entropy line will not tell them apart.

Market stateWhere the returns landEntropy readingWhat it does not tell you
Steady trendMostly in one or two bins on one side of zeroLowWhether the trend is up or down
Quiet narrow rangeMostly in the bins nearest zeroLowThat this is a range and not a trend
Choppy whipsawSpread across many bins on both sidesHighWhether the chop is ending
Single news shock inside a quiet windowOne far bin plus the near-zero binsRises a littleWhether more shocks follow

The practical consequence is that entropy pairs with other tools rather than replacing them. A regime filter that uses volatility or trend strength can split the two low-entropy states; the three states and how to measure them are laid out in market regime detection for trading strategies. An entropy line that stays low for weeks behaves like an oscillator pinned at one end, and the reasoning in what a KD or RSI stuck in the overbought zone means applies: a reading that does not move is reporting a persistent state, not a signal. Entropy also shares a trait with the Hilbert oscillator as a cycle indicator: both describe a property of the recent bars (one the spread of returns, the other the dominant cycle), and both need a separate rule to decide long or short.

Three illustrative price paths with their entropy reading: a steady trend reads low, a quiet narrow range also reads low, and a choppy whipsaw reads high, so the reading alone does not separate a trend from a range Low entropy, two markets Illustration: price path and reading Trend Range Chop Low Low High Two low readings, unlike charts. So: add a volatility or trend rule.
Two of the three panels read low. They look nothing alike on a price chart, which is why entropy needs a companion rule.

What window length and how many bins should an entropy indicator use?

The window sets how fast the reading reacts and the bin count sets how fine it is, and both have to be chosen relative to the bar size and the length of the trades you plan to take. There is no universal setting. A 20-bar window on 5-minute bars describes the last hour and forty minutes; the same window on daily bars describes a month. A setting that sorts intraday chop from intraday order is discussed with examples in what testing shows about the best indicator for intraday trading, and the same logic transfers to entropy.

SettingSmaller valueLarger valueRule of thumb
Window length NReacts fast, crosses a threshold often, noisyReacts slowly, crosses rarely, misses short regimesAbout one to three times your typical holding period, in bars
Bin count KCoarse: small shifts in spread go unseenFine: many bins hold one or zero returns, reading jumpsKeep N at least five to ten times K so bins can fill
Bin edgesFixed widths: simple, but volatility changes shift all returns to outer or inner binsVolatility-scaled: edges move with the market, reading compares like with likePick one method before testing and keep it

The relation between N and K matters more than either value alone. Twenty returns sorted into eight bins average two and a half per bin, so one return changing bins moves the reading a lot. Twenty returns into four bins, as in the example above, average five per bin and give a steadier line. The test that the choice is not noise is the same one used for any parameter: run the neighbouring settings and look for a flat region. If a 30-bar window with 5 bins filters well but 25 and 35 bars do not, the setting describes the history rather than the market. Pardo (2008) describes this neighbourhood check as a standard step before trusting any optimized value, and it costs only a few extra runs.

One illustrative price path with two entropy lines on the same bars: a 20-bar window swings between 0.5 and 1.0 and crosses the 0.75 threshold 16 times, a 100-bar window moves slowly between 0.7 and 0.9 and crosses it twice Short window, many switches Illustration: same bars, threshold 0.75 Price 20 bars 100 bars 16 flips 2 flips Short windows flip the filter often. So: match the window to your trades.
Same bars, same bins, two windows. The short window produces many filter switches, the long window few; which is right depends on how long your trades last.

Does an entropy indicator work as a trading filter?

Low entropy can gate the entries of a trend or breakout rule, and the honest test runs that same rule with and without the filter under the same costs and judges the change in average trade after costs, not the change in win rate. A filter is a condition that must be true for a signal to be taken and that never opens a trade by itself. The idea behind a low-entropy filter is simple: a breakout out of an orderly stretch is more likely to be a real shift than a breakout out of chop, so the rule stands aside when the recent returns were scattered.

  1. Fix the direction rule first. For example, a channel breakout: buy when the close is above the highest high of the last 20 bars, sell short on the mirror condition, exit on the opposite signal. Set commission, slippage and next-bar execution once; commission, slippage and the average trade in a backtest explains how to size them.
  2. Run path A: every signal is taken. Record trade count, average trade after costs, profit factor and max drawdown.
  3. Run path B: a signal is taken only when the entropy reading is below your threshold. Everything else stays identical. Record the same four numbers.
  4. Compare. A useful filter removes trades that were losing on average, so the average trade after costs rises by more than the trade count falls. A filter that cuts the trade count in half and leaves the average trade where it was has removed winners and losers alike and adds nothing.
  5. Repeat with two or three thresholds and windows. The improvement should persist across neighbours, not appear at one value only.

Win rate is the wrong yardstick because a filter that removes a few large winners can raise the win rate while lowering the result. Trade count is the second number to watch: a filter that leaves 25 trades over ten years has produced a result too thin to read, whatever the average. In AlphaPrime (Valynox), both versions of the rule can go through strategy validation with the same walk-forward step, so the filtered version has to show its gain on windows the search did not tune on before it is kept.

The same breakout rule run two ways: path A takes every signal, path B takes a signal only when entropy is low; both feed one comparison of average trade after costs, trade count and max drawdown Same rule, one change B trades only when entropy is low A All signals B Low entropy Avg trade Trade count Max drawdown Judge by average trade after costs. So: change one thing, check three.
The filter is judged by the difference between two runs that share every other setting. Change one thing, measure three numbers.

What did an ES test of an entropy rule show, and where are its limits?

An AlphaPrime search on ES daily bars kept one entropy-only candidate out of 1,024 it tried, and its 44 trades, 93.41 percent time in market and after-the-fact selection show that the number flatters the idea. ES is the E-mini S&P 500 futures contract. The run tested the indicator as the only entry and exit rule, long and short, with no stop, target or filter, on daily bars from 2019-01-02 to 2025-06-30, with $20 commission and $25 slippage charged per trade. The kept candidate is the one the search retained out of 1,024 for its return against its drawdown; every other candidate was dropped.

Source: AlphaPrime product engine (CPU), run 2026-10-31. ES daily bars, 2019-01-02 to 2025-06-30, long and short, 1 contract, $20 commission and $25 slippage per trade.

NumberResult
Net profit (closed trades)$128,582.5
Max drawdown$55,412.5
Trades44
Win rate70.45%
Profit factor1.992
Average trade$2,922.33
Time in market93.41%

This run tested a stand-in for the article's subject: the indicator worked alone as entry and exit, not as a filter in front of a direction rule as the previous section describes. Read with that in mind, four things stand out.

  • 44 trades over six and a half years is too few to read a per-trade figure. The average trade of $2,922.33 could move a long way if three or four trades were different. Judge a rule by hundreds of trades, as splitting in-sample from out-of-sample and counting out-of-sample trades explains.
  • 93.41 percent time in market means the rule was almost always holding a position. With no stop and no filter, the result is close to what one long or short position held for months at a time would have earned on a market that rose for most of the period. The entropy reading was switching the side rarely, which is a property of the window, not evidence of a timing edge.
  • The max drawdown of $55,412.5 is 43 percent of the net profit. For a single contract that is a deep hole relative to what came out, and a drawdown over a period with 44 trades says little about the next drawdown.
  • Picking the kept candidate after the fact flatters it. One candidate out of 1,024 was retained because of its return against its drawdown. Bailey, Borwein, López de Prado and Zhu (2014) show that the best result of a large search carries a selection bonus that grows with the number of candidates, and Harvey and Liu (2015) argue for discounting a result by the number of tests behind it. Nothing in this table says the indicator earned that money, and nothing in it says a reader can expect it.
Look at how much of the climb sits in a few long stretches with the position held one way, and how deep and how long the drawdown is relative to the climb before it.
Look at how much of the climb sits in a few long stretches with the position held one way, and how deep and how long the drawdown is relative to the climb before it. ES · daily · 2019-01-02 to 2025-06-30 · CPU engine backtest

What this run does show is the shape of the next test. The indicator needs a direction rule in front of it, a window and bin count that hold up across neighbouring values, a trade count in the hundreds, and an out-of-sample stretch that the search never touched. Take a breakout rule you already trade or test, run it on your own bars with and without a low-entropy filter at three window lengths, and write down the average trade after costs for all six runs before you look at any equity curve.

Frequently asked questions

What is Shannon entropy in trading?

Shannon entropy is a number that says how evenly a set of outcomes is spread across categories. In trading, the outcomes are the last N bar returns and the categories are size bins. A reading near 1 (after scaling) means the recent returns were spread evenly across the bins; a reading near 0 means almost all of them fell into one bin. It describes how mixed the recent moves were, not their direction.

What does low market entropy mean?

Low entropy means the recent returns piled into a few bins. That happens in a steady trend, where most returns are of similar size on one side of zero, and in a very quiet range, where most returns sit near zero. The reading alone does not separate those two states, and it does not say whether a trend is up or down. A volatility or trend-strength measure is needed alongside it.

What window length should an entropy indicator use?

Choose the window relative to your bar size and your typical holding period, roughly one to three times the holding period in bars. Keep the window at least five to ten times the bin count so that each bin can hold several returns, otherwise the reading jumps when one return changes bins. Then run the neighbouring window lengths and keep the setting only if they behave alike.

Can an entropy indicator be used alone to trade?

It can open and close trades, but a reading about the spread of returns carries no information about direction, so an entropy-only rule is mostly guessing which side to hold. The ES daily-bar run in this article used the indicator alone and sat in the market 93.41 percent of the time over 44 trades; that result is one candidate kept out of 1,024 and says little about the indicator. A direction rule with entropy as a filter is the design worth testing.

References

  • Bailey, D. H., Borwein, J., López de Prado, M., & Zhu, Q. J. (2014). Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society, 61(5), 458–471.
  • Harvey, C. R., & Liu, Y. (2015). Backtesting. The Journal of Portfolio Management, 42(1), 13–28.
  • Pardo, R. (2008). The Evaluation and Optimization of Trading Strategies (2nd ed.). John Wiley & Sons.