One of my favorite TV shows is Nova on PBS, which recently showed an hour long feature on the history of math. Now I know that would put most of you to sleep, but my initial reaction was, “Sweet!”.
Not two minutes into the show, the moderator starts discussing the number pi (π) and all the unusual places where it shows up. It’s not just the ratio of a circumference to the diameter of a circle. It shows up in statistics and, oddly enough, in the distance between a river’s path and its distance as the crow flies.
Look at the map of the Brisbane River above. The blue line is the river while the red line is the direct distance. If you take the distance that the blue line travels with all the wiggles and bends in the river, then divide it by the distance of the red line, you should get a ratio approximating π.
Will the ratio of the river exactly equal pi? No. But if you take the ratio of all rivers in the world, then average them together, you should get something pretty close to π.
Does this apply to forex?
The alarm bell immediately goes off in my head. “Whoa, maybe I can use that for trading!”
So, I made a mad dash for the office. I mean seriously, like a full on sprint 30 feet racing to get a pen and paper.
The idea for forex is a little different. It’s possible for the price not to go anywhere in 50 bars. It might move 0 pips.
If I used the river formula of walk/distance and the distance equals 0, bad things happen mathematically. I made a minor adjustment and decided to compare the distance/walk, the inverse. The expected outcome is now 1/π.
Analyze the Power of Pi in R
R is one of my favorite analysis platforms. If you’d like to the code that, you can download it.
Getting the price data is easy. Just go to MT4 and click File, Save. The currently selected chart can then save it’s data. The R code opens up the csv and does the analysis. Each list will look like this after processing the MT4 data.
The last step is to take the mean of the ratio column on the far right.
I started doing that for different currency pairs on H1 charts and found something odd
Currency | Time Frame | Mean Ratio |
---|---|---|
EURUSD | H1 | 0.1614123 |
AUDNZD | H1 | 0.145748 |
GBPJPY | H1 | 0.1587237 |
USDSEK | Daily | 0.182126 |
1/π = 0.318
The average of the values in the table is 0.162.
1/2π = 0.159
Now we’re on to something interesting! The ratio of distance to movement or any given currency looks like it might be 1/2π. I’ve only analyzed a handful of charts so far. This isn’t conclusive, but it’s an interesting early observation.
Graphs
The this is for those of you more analytically inclined. The probability distribution frequency histograms of these very different currency pairs appear to have equal slopes, if you normalize the frequency values.
Digital Signal Processing
The more that I’ve thought about this idea, the more that I realize it’s a pure concept from digital signal processing (DSP).
Engineers analyze signals like this and call it the signal to noise ratio. The idea is simple – how much real information is contained within the observed data?
Using 1/2π as our assumed barrier, we now have a convenient way to categorize market conditions.
Ranging markets – the signal to noise ratio (SNR) <= 1/2π
Trending markets – SNR > 1/2π
I did a quick check in R using the code
range<- audnzd$ratio[audnzd$ratio <= limit]
length(range)/length(audnzd$ratio)
[1] 0.6083298
According to this rough guideline, the market ranges 60% of the time and trends 40% of the time. If I use 1/π as the barrier for a strong trend, the relative frequency drops to only 8%-12%, depending on the instrument.
Conclusion: If you wait for the SNR to reach the weak trend zone above 1/2π before accepting any trend trades, then approximately 1 in 5 trades should experience a significant trend.
The logic runs as follows:
- 40% of the time is spent in a trend
- 8-12% of the time is spent in a strong trend
- 8/40 = 0.2, which is 20%. Strongly trending pairs may experience up to 30% significant trends.
How do you think we should use the SNR in a trading strategy? Share your ideas in the comments section below.
I have a small problem with the premise of the river to straightline ratio.
I think the ratio may not be getting determined so much by some rule of nature as much as it is a being a byproduct of human impact on rivers.
“Wild” rivers will normally take a much shorter path to lakes and/or the ocean but when dams are put along their course it slows them down and they take a more meandering path.
But maybe it still applies to FX price movement. I guess I’ve always had a hard time believing in things like Fibonacci, magic ratios and such.
I’m not privy to the research, so I don’t know whether the river measurements are pre or post damn construction.
I like the SNR because it’s mechanical – there’s no subjectivity involved.
It relies on the fact that the water cannot flow uphill. If the river makes a turn that results in it moving slower, later on it will have to move faster to make up the distance.
At the extremes, the water must either go straight across or straight down. If you built a flat bridge from the water source all the way to the sea, then drop down in a waterfall, the water would still need to move the same distance as the most meandering river.
yes if I forget about the River part and look at market movement in terms of SNR, it makes more sense. Anyhow if the math works out and can be used predictively, I guess you go with it.
i think this is an interesting observation. Be keen to see some data. However, i am still of the belief that there are no magic formulas for predicting price movements with any degree of consistency. Find a formula to protect downside & profits take care of themselves.
My vision is to use this as a filter for strategy types rather than a direct market indicator.
Can relate to your excitement. Will definitely shortlist this idea to play with. Thanks for sharing.
Let me know if you find anything interesting!
I know as much about maths as my cat knows about astrophysics,
but hey, if you can produce an indicator that tells me when to get in and out of the market, I think that would be awsome.
That’s certainly the plan. The math is nerdy, but the indicator should produce a simple range/trend output.
I think of indicators like cars. I have no idea how the engine works, but I know how to use the accelerator and brake. Basic knowledge is often good enough.
I like your Idea. I think it needs to be optimized. When is the 60% market ranges most likely to occur time wise (London/USA)(Asian)? and what time does the 40% trend happen? Are they the same time everyday? Is it different for different pairs? When and what time of day are the strong trends most likely to happen ? on what pairs and when? After News release? Before News release? Do they happen the opening or closing of certain markets? Do they happen in all markets on all pairs? Should we avoid certain Pairs? Or certain pairs at certain times? I think it has potential but needs to be worked out for a clearer understanding against random market conditions…Thanks
Very interesting, Shaun. Though I am not a Math expert, I can see you are on to something good. Keep it up.
Hopefully, you will come up with a reliable trade filter…
Thanks for your good effort and nice newsletter.
Thanks for the feedback. I plan to keep everyone updated on the filter research.
Shaun, please provide a print feature for these useful articles on your blog… so they can be saved as PDF or text or HTML for future reference. Thanks
I’m now promoting my most popular articles from subpages off of my front page. I hope that helps you find them more easily.
Anything that helps identify ranging and trending markets can only be of benefit. Any chance of providing some preliminary code so we can check it out against our own strategy? Keep up the great blogs
The R code is in the article, but I realize that’s not useful to 99% of the readers. I want to avoid doing any MT4 coding until I’m certain of the usefulness. I’m happy to share any MT4 code whenever I get it coded.
From where do you have a data ? Nice article.
Hey Panta,
I downloaded it straight out of MT4. I normally advise against this for high frequency strategies. My default time frame is usually H1, which is fairly safe to download as a data source. That’s especially true if you only trade based on the bar open.
Hi Shaun,
I like it! Categorizing “Range|Trend” is ubiquitous in the field — it makes us feel better. In reality, is not the end of the trend most likely at the edge-of-the-range? IOW, the view of “trend” is most clear looking back.
I’m thinking you are describing something similar to “Escape Velocity”. Trade initiation at the make-or-break point is certainly desirable— especially with calculations to identify said point. Good stuff in your post; please keep us informed.
Hey Scott,
Actually, I expect the probabilities to work like volatility. If the volatility of the last bar was x and x has a probability of 10%, then the probability of the next bar having volatility > x jumps well above 10% on the next bar.
Trends are very similar. The next bar is likely to continue trending. But the long term average must be for a range. When the price does snap back, it does so with a vengeance!
–Shaun
Hi Shaun. Worked on MQL4 – just sent you something – pls have a look.
M
Mario,
Your code looks great! It’s exactly what I envisioned. Would you be willing to share this with the community?
–Shaun
Hey Shaun, Hopefully you remember me, couple years ago you coded for me an EA. You did an excellent job. As soon i saw this article, i went to see the documentary, it was awesome, Thank you for that. For some reason, i have been obsessed with Rocket science, since this past year, and endlessly watch rocket launches, docking to ISS, undocking from iss, etc.. I find it intriguing, how precise, and accurate every tiny detail has to be for rocket launches, and somehow i want to relate it to trading, i don’t know how exactly yet, but so far, it has taught me, my trading strategy has to be as precise, Systematic & to be really disciplined. And, now after seeing the doc, and reading your observation, i really really believe you are onto something, its just in my mind i am relating it to rocket launches, docking, undocking and the math they use to do all that , and now what you said about pie, and trading somehow makes sense. Since my approach to trading is trend following, what you are working on looks like, something i definitely would like to add to my strategy. Thank you for your hard work, and for sharing awesome information.
Eskinder
Hey Eskinder,
That’s awesome and what a great update. The killer for most trending strategies is that they get chopped up in ranges. So long as a trend strategy has the ability to catch signals when the SNR signals a trend, then I would expect to see dramatic improvements.
another great article. and thanks for the R code…. been meaning to get into that, and this is a great stepping stone.
Cheers, Mark.
R is great if you expect to need to graph the data. The one thing that really tripped me up was the apply functions. They’re pretty unusual, at least for a C# coder.
Hi Shaun, the books by Bill Williams, Chaos Trading, mention this subject. maybe of interest,
cheers baz
Absolutely. Many thanks for the referral.
Thanks Josh and Mario!
Interesting.
I put an 8sma signal smoothing line on it, which picks out trending situations rather well.
Good idea! Mario seemed to favor the 14 period instead of 50 as it’s more responsive.
https://www.youtube.com/watch?v=9tTq12QoaMA
Here is link, Bill Williams mentions measuring path of river and Mandelbrot number. Thanks Mario i have downloaded sig/noise indicator. Im unsure how to interpret what i see at the moment, welcome your advice cheers baz
If it’s less than 0.159, it’s a range. If it’s greater than .159, it’s a trend. If it’s greater than .318, it’s a strong trend.
Hi Shaun, Hope this trend filter from Mario can be made available for NinjaTrader users.… Many thanks
Maybe you can sweet talk someone into coding it by posting a link on the NinjaTrader forum?
Good idea and good work by mario. I appreciate effort. However, I use the ADX to find how strong the momentum of the trend or move. I don’t find the file attachment feature here. However, you can download the “Advanced ADX” indicator from the net. Both your new indicator and the ADX gives out the same information, that is the strength of the trend. On comparison the ADX is more clear and better to be with the trend. Wish you all goodluck.
Sampath
Thank you for proposing an alternative. It’s nice to have multiple options.
This is really interesting Shaun! Just as you did I jumped when I saw this article.
Some time ago you pointed to the guys at TRAIDE and at their website I saw an interesting algorithm for EURUSD H4. It works like a charm from 2013, it is possible to push it to 100% per month in test (not that I would do that in live, but as a kind of stress test). For the whole of 2012 it is just a disaster. So I have been thinking about what difference there was in the market in 2012 compared to 2013/14. Maybe your article has the answer?
I downloaded the MT4 indicator (Thanks Mario!!) and made a visual inspection but I can’t see any major differences on the charts. Then I added a moving average to the indicator, a moving average of the signal to noise ration. 8 periods did not show any visual difference, also not 50 and also not 200. Then I added another moving average and displayed 50 and 200 on top of each other. Then I thought I saw something. Can it be so that when the 50 moving average of the signal to noise ration is too much different from the 200 then this algorithm does not give any profit but when the 50 is more stable then there is profit?
Visual inspection is of course of no real value but can be a good start. So the next question is then, can this be measured in some way? Can it be measured what profit an algorithm gives at certain conditions? Can this be done in MT4? Can it be done in R?
Thanks for a really interesting topic
/Thomas
The difference between 2012 and 2013 was volatility. 2013 set record lows for FX volatility – almost nothing was happening.
You could look at the differences in the noise ratios over time. I try not to dig into the 5th layers of things. It violates my KISS mantra. But I do think it could probably work or provide more info than a solo smoothing filter.
Hey Shaun
I’m pretty sure that tech Analysis of Stocks & Commodities magazine came out with a similar DSP algo about 6months-a year ago. You may need to look it up.
I like the premise! As a trend trader, I would love to compare it to my standard trend filters.
Cheers
Hey Paul,
I actually published this a year ago. Maybe they stole it from me! 😉
–Shaun
Interesting article Shaun but I noticed it was dated earlier in 2015. Did anything come about as a result of the research? Thanks.
Yes, I later incorporated the signal to noise ratio as a filter for QB Pro.
Hi Shaun,
The only thing I can say regarding this post is that Nova has become my TV show of choice. Unfortunately I can’t watch as soon as it releases new episodes because I live in Europe, but the ones I can find on Youtube, wow, amazing stuff.
Regarding your findings and calculations, oh man, I still have so much to learn. I’ll keep reading your posts so hopefully at some point I will be able to give more inputs.
Thanks!
Thanks, Luiz. Keep on reading the articles. You’ll start to learn by absorption.
Interesting read.. makes sense. I’m also in the middle of watching that Bill Williams video where he talks about the rivers. Crazy. Hey.. I don’t see the indicator posted here from mario. Can I find it somewhere so I can see what you guys are seeing?
Mario never decided to share the file with everyone.
Hey Shaun,
Thanks for this article…honestly I am so lost because I am not yet a coder. All I know is that it will be great to have such system.
Hi Sea,
It’s intended as a filter instead of as a trading system. I only want to range trade when the market is ranging, or trend trade when the market is trending.
–Shaun
What brought me here was this last post (#88) from: https://www.forexfactory.com/showthread.php?t=130707&page=5
Interesting article you have here Shaun. Reminds me of the work Bill Williams did regarding fractals occupying the 1.5 dimension of the classical three dimensions 3D; length, width, & depth, and 2D a line) therefore the fractal dimension is assigned 1.5D.
In case you aren’t so familiar with Bill Williams hiring two theoretical mathematicians working on a rented Cray super-computer (in the 1980’s) discovering fractal geometry dimension as it relates to trading also having the same fractal dimensions of a river. A lecture video of Bill in his younger days giving a lecture explains (on youtube).
My thoughts about a previous post here regarding “natural river flows” vs. man made “interference” i.e.: dams, dikes, are relating to trading would be instead of a natural flowing market we also have dams and dikes read that: banks and hedge funds, which of course respectively, pool resources and redirect flow.
Hey Clint,
Thanks for posting how you found me. I spent a lot of time looking at the fractal nature of the market. My experience is that fractals are great for understanding the general behavior of prices, but they don’t help much with predicting market direction. I use much simpler indicators for that.
–Shaun
Hola Shaun, de donde sacas el valor WALK y LOOKBACKSHIFT de la planilla.