Hey everyone! Does anyone know of a indicator that plots standard deviation on the graph in relation to a MA? One that curves with the graph?

I am making a strategy and this would be very helpful.

Thanks!

Hey everyone! Does anyone know of a indicator that plots standard deviation on the graph in relation to a MA? One that curves with the graph?

I am making a strategy and this would be very helpful.

Thanks!

The most popular one for this kind of thing is Bollinger Bands. For those that like to do things differently, use Bands.

I have this which i coded myself. It sits on one chart and you tell it what other instrument you want to compare it with.

Could you post it here for us to use?

There are 3 versions

The basic way they work is to take the difference/spread between 2 instruments. A moving average of x periods is taken (default is 100 but can be changed). It calculates the Std Dev (again based on the same x periods). It then works out how many std devs the current spread is from the moving average and plots it. So - instead of having a wavey moving average line with wavey sdt devs everything is plotted against 0. So you can see in the chart i posted the spread tends to be around the 0 but we can see at one point it went almost 4 std devs out before returning.

The first version (HSZScore) works exactly as above. The spread is taken from close of each instrument (then averaged etc). You put it on one chart (first instrument) and then tell it which other instrument you want to compare it to.

The second (HSZScoreThirdInstrument) is the same as above but has parameters for both instruments meaning you can compare EURUSD / GBPUSD but put the indi on a different chart.

The third (HSZScore-Percentage) uses a different method of calculating the spread (but to be honest 9 times out of 10 it looks exactly the same).

A couple of things to note. I have played with cointegration stuff before and i am not convinced. Most of the time it does work but when it goes off you can lose a hell of a lot. The problem is the averaging period. As its a moving average if price is divergent for a long time then rather than the spread reverting to the mean you will see the mean changing to the current spread (or a shorter average of it). If this happens the spread might revert to 0 but you will still be at a loss. Using a longer period might help but then you dont get many trades.

second i am quite busy so wont really be able to support these indicators very much. Obviously i will look into the thread from time to time and if you find a profitable way of using them then thats great for all of us.

As well as showing the lines if the spread is more than 0.5 it will tell you (in the comments) which instrument to trade and suggested lot sizes (well 1 lot of the base and how many needed of the second).

I actually use the Bollinger Bands in a different way than most retail traders. However, I am skeptical that it will still be useful if everyone else used it the same way. Generally if most data falls within 1 to 3 derivations then it is said to be a good model of the data. So sample size is important in finding more actuate models.

Cheers

Does this indicator tell how many standard deviations the two pairs are away from their mean?

If you are replying to me then yes. The vertical scale is std deviations. So on the screenshot you can see it went to almost 4 std deviations but recoverd back to mean. There are some levels preset (-3,-2,0,2,3) but obviously you can change this.

[QUOTE=“Mata Nui;544805”] If you are replying to me then yes. The vertical scale is std deviations. So on the screenshot you can see it went to almost 4 std deviations but recoverd back to mean. There are some levels preset (-3,-2,0,2,3) but obviously you can change this.[/QUOTE]

Yes sorry I didn’t quote it. So if I’m comparing EURUSD and GBPUSD and the std dev is at 2. This means the two pairs are 2 std dev away from their combined average?

Yes, but it is the average over the periods set in the parameters (so default is 100 but you can change this).

I remember reading your original thread on stat arb a while ago. One of the points constantly raised was that the EURUSD / GBPUSD pairing was the same as just trading EURGBP. Well one of these indicators was written specifically to test that idea by letting you run it on one chart but compare 2 others. The included screenshot is the EURGBP (today) with the EURUSD and GBPUSD. Looks like it might have been ok today.

Note that the indi appears reversed on GBPUSD but the shape is exactly the same.

[QUOTE=“Mata Nui;544820”]I remember reading your original thread on stat arb a while ago. One of the points constantly raised was that the EURUSD / GBPUSD pairing was the same as just trading EURGBP. Well one of these indicators was written specifically to test that idea by letting you run it on one chart but compare 2 others. The included screenshot is the EURGBP (today) with the EURUSD and GBPUSD. Looks like it might have been ok today. Note that the indi appears reversed on GBPUSD but the shape is exactly the same.[/QUOTE]

Thanks so much brother! This is exactly what I needed. I’ll let you know if I make a breakthrough lol. Where are u from btw?

UK, North Wales. Any breakthrough really will be in minimizing risk and knowing when to get out if things dont go the right way i think. Have a look at this idea. Watch for it go go out past 3 deviations then come back in (2 deviations will get you a couple of trades each day or more but it can go back out again). Then take a position on the third pair or opposing positions on the main pairs. You can have a look back on the charts as the indis dont repaint. It looks quite good BUT there are occasions when it will go horribly wrong, also you wont get a trade every day.

See what you can come up with, start a thread maybe or either way if you figure something out send me a message.

[QUOTE=“Mata Nui;544955”] UK, North Wales. Any breakthrough really will be in minimizing risk and knowing when to get out if things dont go the right way i think. Have a look at this idea. Watch for it go go out past 3 deviations then come back in (2 deviations will get you a couple of trades each day or more but it can go back out again). Then take a position on the third pair or opposing positions on the main pairs. You can have a look back on the charts as the indis dont repaint. It looks quite good BUT there are occasions when it will go horribly wrong, also you wont get a trade every day. See what you can come up with, start a thread maybe or either way if you figure something out send me a message.[/QUOTE]

How did you make these indicators? What formula was used?

They are quite simple really, as you see i have given you the mql files so you can have a proper look yourself but I spent quite a bit of time researching cointegration and Z scores before creating these. I guess you will have had a look as well and found most of the stuff on the web is pretty math intensive and because its all written for academic use there are not any examples that are very easy to follow. What i discovered though is that most of the difficult stuff is about finding how cointegrated pairs are (to find profitable pairings). The actual measurement of if they are following that model is pretty simple. Also i wanted something that would just fit onto an mt4 chart so it had to be basic. So this is how i did it:

First find the spread between the 2 selected instruments. There are a few ways you can do it, you can subtract one from the other (As its MT4 charts use the close of the bar), divide one by the other or one example i saw used logs of each close price. It doesnt matter really, i tried them all and the graph looks EXACTLY the same in each case. So these indicators besides the percentage one which i will explain later use the close of instrument1/close of instrument2 to find the spread. - This gives us a value for current spread at close of that bar.

Then find the average spread. I do this by using the MAOnArray function in MT4 to find the moving average over 100 periods of the spread. - So we now have the current spread and an average spread.

Then find the Std Dev for the same period. MT4 has a function for StdDevOnArray so i just plug the same array into that to find the Std Dev over our 100 period average. - So we now have the current spread, an average spread and the Std Deviation.

I could have plotted those as they are but i would have ended up with wavey lines on top of wavey lines and it wouldnt look too good. I know this because i had experimented with plotting the average and current then applying b-bands to the average. It worked (sort of) but was a mess to look at. Since i only really needed to know how many deviations from the mean the current spread is i used the following formula to kind of normalize it against a 0 axis.

z = (diff-mean)/stDev

Then i just plot z.

I have no idea if this is how it should be done and only have high school maths (OK, slightly better since i am a programmer but its not something i have really done before) but it does seem to show what it is meant to show. I am sure it could be improved on though.

The percentage indicator is similar but it doesnt use the difference in close prices directly. It looks at relative movement. So it compares how far each instrument has moved since the open of the day bar as a percentage of that open value. As you can see the chart is the same. I did it as an experiment really. I thought it might work better for comparing currency and index values (so GBPUSD and FTSE for example) but it doesnt make much difference.

I might take a look at this as well from an analytic standpoint. Don’t know if I would ever use this but I have been using Statistics in my own trading. Maybe I can improve on it… What time frames are you sampling?? Just M5? I see sample size of 100 as default is that to making percent change calculations easier? Sounds like your doing a Z Score comparison looking for a variance or divergence.

Cheers.

[QUOTE=“JavaPro;545492”] I might take a look at this as well from an analytic standpoint. Don’t know if I would ever use this but I have been using Statistics in my own trading. Maybe I can improve on it… What time frames are you sampling?? Just M5? I see sample size of 100 as default is that to making percent change calculations easier? Sounds like your doing a Z Score comparison looking for a variance or divergence. Cheers.[/QUOTE]

Javapro where are you from?

Live out in Oklahoma these days. Still travel quite a bit for work. Just did a job in Maryland last month.

[QUOTE=“JavaPro;546666”] Live out in Oklahoma these days. Still travel quite a bit for work. Just did a job in Maryland last month.[/QUOTE]

Nice I’m in Va. In your post describing the formula, what’s is the formula for the z score? What is the diff-mean?

As I suspect what you doing is close to a two - Sample z-Test of the difference between means. z = (observed difference) - (hypothesized difference) / (Standard error).

Can be used to test the difference between two population means u1 and u2 when a large sample (at least 30) is randomly selected from each population are independent.

Two-Sample z-test for Comparing Two Means

Here a showing the two sample and single sample test:

Two-Sample-Z-Test - YouTube

Cheers.