Can someone please suggest me a method to programatically identify trending/consolidating market condition by reading ohlc data?

Currently I'm thinking of checking the current price within last n number of candles to check if the same price can be observed multiple times before.

Any other suggestions would be highly appreciated!


1 Answer 1


To start, it very much depends on your outlook. Do you believe that the future price movement is independent of previous price movement? If so you probably wouldn't look for trending or consolidating markets (it would be entirely random). On the other hand, maybe you have a fractal view of the market (search for fractional Brownian motion, regime switching models, ect.) where you think there is some deterministic or perhaps autocorrelated aspect to the price series of the asset. No one can say with certainty (although some statistical studies have indicated certain structural aspects). Really you should ask what you are trying to do with this information. Is it relevant? What time scales are you looking at? One technique that you could try that I like to look at is as follows: take the time series $X_t$ where $t\in\mathbb{N}$. I then define $\mu(t)$ such that $\mu(t)=0$ if $X_t<X_{t-1}$ and $\mu(t)=1$ if $X_t\ge X_{t-1}$. Doing this for some finite run you will get a series of 0s and 1s. Try computing the Shannon entropy or approximate entropy. You may find some interesting results. Long runs of 0s and 1s may indicate trends. However, for your purposes it may be best to see if there is anything interesting happening before a trend begins.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.