Creating confidence interval bands that add value to technical trading analysis for Bitcoin and other cryptocurrencies.

At Gatsiva, we built an analysis API that helps cryptocurrency traders become more confident in their trades, especially when using technical indicators to determine buy or sell signals. The following article outlines how our often-used confidence band graph is constructed and why it can be a good source of additional information when using technical indicators to trade cryptocurrency.

**TLDR;** We can use the Gatsiva API to create a prediction of what is likely to happen to a cryptocurrency price after an event occurs by utilizing confidence bands. These confidence bands are risk adjustable and can be created for nearly any technical trading indicator. By utilizing them, traders can be armed with better information in order to make smart buy or sell decisions.

*Remember: Cryptocurrency trading comes with risk of loss. The following article is not meant to be investment advice nor support or advocacy of any particular cryptocurrency.*

#### The Case for Confidence Bands

Today, there is no shortage of Twitter conversation, trading room banter, and other social outlets with tens of thousands of people trading ideas on how best to trade and time the purchase or sale of cryptocurrencies.

Rising to the top of these suggestions are various technical analysis methods. By looking at patterns of price and volume movements, these technical analysis indicators claim to show oversold or overbought indicators. And we agree, since cryptocurrencies are such an emotional market with a lack of fundamentals, emotional markets like this tend to trade primarily on price signals.

But there are two key questions that are often left unanswered when evaluating recommendations from these sources:

1. *Has this really worked in the past?*

2. *How relevant is this indicator or event to the specific cryptocurrency you may be interested in?*

Answering these questions is where Gatsiva steps in.

By using and comparing our confidence bands to show return after an event, we believe traders can be better informed about the potential predictability of an event.

#### Looking at an Example

We thought it best to illustrate this approach with a event that occurred recently. You can follow the history of our Twitter account if you want to get the play by play.

On January 17th early in the morning (Japan time), we spotted a tweet claiming that both RSI (Relative Strength Index) and MACD Crossover (Moving Average Convergence / Divergence) were good indicators that Tronix (TRX) was poised to increase in price.

BothRSIandMACDare technical indicators that are typically used by traders to indicate when it may be a good time to buy or sell. To learn more, check out the tutorials on Stockcharts.com.

Taking the word of a trader on Twitter is one thing, but wouldn’t it be nice to know if these indicators actually work?

By creating and utilizing a confidence band to test this indicator, we can give a better view on whether or not to even pay attention to such a signal. So let’s get started.

**Figuring Out What Data To Look At**

To get started creating a confidence band, its first helpful to look at the general price of the cryptocurrency in question. Utilizing the Gatsiva API to get prices and a little bit of Python, we first take a look at the overall price action of Tronix priced in Bitcoin on an hourly basis (TRX:BTC:hourly) over its entire history.

Why Tronix priced in Bitcoin?Many cryptocurrencies trade in various pairs on exchanges. However, not all of them trade directly to US dollars or Euros. The price of Tronix in Bitcoin was more actively traded and much more liquid, so we chose this for the analysis. It was also the pair marked by the original trader.

What is interesting here is that the price of Tronix was pretty unremarkable up until mid-December. A quick Google Trends search shows that public interest in Tronix was also relatively low prior to this price spike. (This relationship alone might be worth future analysis.)

We can assume that the price movement prior mid-December is probably not going to be very helpful for us to predict the current price. So we make the decision that we are only interested in price action from December 14th onward.

Why ignore before December 14th?It is best to choose the set of data that best reflects the current price action. In this case, the data prior to December 14th looks and behaves nothing like the prices afterwards, so we make a judgment call and choose to ignore it.

After removing price data prior to December 14th, we can more clearly see the current prices. Here we see some variability in the early part of the run up in price up to January 4th or so, some volatility in price during a big run up over the next 3 days, and then some volatile downward price action. The data from December 14th through January 16th on an hourly basis gives us 816 data points (34 days x 24 hours) to look at and a variety of ups and downs to analyze.

**Finding the Signals**

The Gatsiva API allows any user to define technical indicators that traders use in a very easy to write language that we call the Gatsiva Language. So the first thing we have to do is define the MACD Crossover condition in our Gatsiva Language. Fortunately, this can be done easily:

**macd histogram(12,26,9) crosses above 0**

Now that we have our signal defined in our language, we make the API call and ask the Gatsiva API condition history transaction to tell us when this even was true over the period we are interested in. In our example we process this result in Python and create an illustration of when the event occurred.

From this information we learn that this rule was true 36 times over the course of the 34 days (816 hours) we are interested in. In addition, this event profile has some pretty positive characteristics.

First, the occurrences of this event were pretty evenly spaced over the course of the price history we have chosen, indicating that it may be generally useful. Secondly we see very little “clustering” of events, areas where the event occurs repeatedly for a period of time. This is a good indication that the results we will get after the event are pretty representative of general results and not due to just a single event.

**Analyzing the Signals**

So what do we do with this data?

Remember our first question. What we are really interested in to create confidence bands is answer to the question: “*What happens after each event occurs?*” To begin to answer this question, it helps to start by looking at what happened after the first time this event occurred during our period of interest, on December 15th at 16:00 UTC.

This illustration above shows hours after the event on the x axis and overall return on the y axis. We can see here that after 24 hours, the return on this trade was well over 25%. If you held on for a total of 48 hours you were up around 75%, after 72 hours it began another increase ultimately landing to over 125% during the first 90 hours.

Not bad. Let’s take this a step further. How about the next two times this MACD Crossover occurred?

Here you can see the next two events, which both occurred on 12/18. The change in price of Tronix stayed mostly positive for the second event on December 18th at 4:00 UTC. The third event which occurred on Dec 18th 22:00 UTC was initially negative after about 18 hours, but recovered after about 48 hours.

**Looking at Data Differently**

Now to begin explaining how we build our confidence intervals it helps to begin looking at this data in a slightly different way. First, let’s look at this data as a series of points instead of connected lines for each event.

We can see that are we fundamentally looking at the same of data. Each return in each hour is plotted as a dot instead of a series of connected lines. Viewing the data this way starts to give us the ability to compare the results within each hour.

To get a better idea of what we mean, let’s look at the entire set of returns for all 36 events that occurred in the same way, plotting a dot for each hour after each event.

Now we can see all of the returns for all 36 events that occurred. It’s getting a little crowded but even now we can begin to perform some simple analysis on this data.

The first and easiest thing we can do simply is look at what the average return has been within each hour.

Here we’ve drawn a grey line through each hour, calculating the average return observed within that hour. This is pretty straightforward, and ultimately shows that on average, if you had purchased TRX when this MACD crossover event occurred, hour after hour, you would have seen increasing returns if you invested all 36 times.

However, you would have also seen a range of fairly volatile returns from -50% to over 200%. Even now, we’re getting closer to understanding if MACD crossover is something we should be paying attention to.

**Digging Deeper**

Now let’s see if we can extract even more insights out of this data. To illustrate how we do this, we’re first going to zoom in to the first 20 hours only, and focus specifically on one set of returns.

In the figure below, we’ve zoomed in and highlighted the returns after 12 hours as an arbitrary slice of this data. Now let’s use this data to illustrate the approach to creating a confidence band.

Now turn your head sideways to the left and let’s visualize those returns for the 12th hour horizontally instead of vertically. Ready? Here we go.

So now we are looking at the very same data for the 12th hour after that MACD event occurred, but just rotated 90 degrees for convenience, with returns observed plotted on the horizontal X axis.

We can see that the returns range from -30% to nearly 90% and that the average return after 12 hours is around 3.2% or so. So far nothing new.

So what are going to try to do now is create a method by which we can use to create some bands of confidence around these returns. Is there anything that we can determine by looking at these return that will help us determine or predict what the returns should be moving forward?

**Removing Outliers**

Looking at these returns now, the first thing we notice is the outlier on the right side. Its usually not a good idea to base your analysis off of outliers, and we should “clean” the data before making any assumptions about it.

Why remove outliers?What we will ultimately do to create confidence bands makes assumptions regarding the distribution of data. If the data we have is not normally distributed, is very difficult to make our interval assumption. However, within Gatsiva we plan to allow people to run this analysis with and without outliers as an option.

One easy way to remove outliers is to visualize them with a box and whisker chart. This chart will help us see what is happening with this data by plotting the quartiles of the resultant data. Data that falls out of range will be considered outliers and removed.

In this particular case, we use standard 1.5 IQR (Inter Quartile Range) to determine the outliers. (For more information see IQR on Wikipedia).

Voila! Now we can see that the three most right hand observations at about 32%, 38% and our friend at 88% are deemed outliers — we should probably remove them. Having done this, we now have a clean data set that we can try to make some assumptions from.

**On Our Way To Confidence**

So let’s pause here and take stock in what we’re looking at.

First thing to notice is that our average return went down significantly, from 3.22% to -1.43%. The influence of those three outliers was significant when looking purely at averages.

We can also calculate the standard deviation of these returns. Standard deviation measures the amount of variation that occurs within a data set. Though not illustrated in the chart above, trust us when we say that the standard deviation of the returns observed above is approximately 11.3%.

The next thing we want to do is check to see if our data is normally distributed. A quick visual check via a histogram is a good way to see if we have that classic “bell curve” shape.

Looking good! We can see that we see a relatively normal distribution with a little skew. A quick test using Python and the scipy.stats library normaltest function gives us a p-value of 0.92, well above the threshold of 0.05. We can be confident that this data set resembles one that comes from a normally distributed data set.

Now that our data for the periods after 12 hour are confirmed to be normally distributed and we know their standard deviation, what can they tell us?

Well for one thing, normally distributed populations have interesting properties. One most easily understandable is the Empirical Rule.

The Empirical Rule, also known as the three-sigma rule, states that for a normal distribution approximately 99.7% the data will fall within about 3 standard deviations of the mean, 95% of the data will fall within the first two standard devisions, and that only about 68% of the data will fall within the first standard deviation.

Using this approach, let’s take our data distribution we have here for 12 hours and visualize it in the same way.

Here our histogram is still present, but moved to the background so its out of the way. Over this, we’ve plotted a density curve which shows the distribution of returns.

Now utilizing the same concept that underlies the Empirical Rule, we can use a calculation technique called “percentile point function”, or PPF, to calculate the range of returns that represent various confidence levels. For example, the image below, we calculate the return range that represents 75% confidence below in the light gray borders on either side of the average.

Why use only 75%?Historically, cryptocurrency returns have been quite volatile. Aiming for 95% confidence is a pretty high bar to achieve on nearly any indicator. In a world where people are rolling the dice on 50/50 chance of losing all their money or making a lot of it, we think 75% is a good compromise. That said, this analysis can be easily generated with a higher or lower confidence interface if necessary.

Pretty cool, now we have our 75% confidence interval for these returns. We can now see that if we want to be 75% confident that the mean of the returns after 12 hours will be somewhere between -14.5% up to 11.5%.

Now let’s go back to our dot plot and mark those points we found for 75% confidence and indicate the band in-between with a dark shade.

We can now see much more clearly, a band between which we can expect to be 75% confident of the average return after 12 hours following a MACD crossover event, based on past historical data.

Now, let’s flip this back to the prior chart we had and show this band in the context of the zoomed in returns we showed earlier.

So all that work we just did on that little slice for the 12th period is now adjusted. The outliers are gone, we’ve recalculated the average, and we’ve created confidence bands.

Now if we take this concept and apply it to all periods, creating the average and the confidence interval for each hour we’ve tracked returns, we can easily create our confidence band. All we have to do is repeat this calculation for every period on the x-axis, remove the underlying dot returns, and draw a line through the average.

Here, we’ll do the hard work for you.

There you go. Here is our final product: a confidence band for a MACD Crossover event as it occurs on Tronix priced in BTC on an hourly basis utilizing data from December 14th through January 16th.

**Using Confidence Bands**

Once a confidence band has been created, it can be utilized very intuitively. Two uses that have resonated with followers of Gatsiva have been:

**Determining if we can be confident in an event’s positive or negative direction**

Using the example above, we can see that after about 66 hours, the confidence band is well above zero. This tells us that we can be 75% confident that the average return we should expect will be above zero after 2.5 days or so. In addition, the width of the band can give you an idea of the predictability or consistency of the event you want to analyze. Both approaches can be very powerful when evaluating a potential opportunity.

Furthermore, confidence bands that span across zero may indicate that there is very little predictability to the event you are analyzing.

**Tracking future events**

One thing we like to do is track the performance of future events within a previously created confidence band. This can help us understand if a trade is likely to revert back to the average.

For example, our tweet shortly after the Tronix event occurred showed an indication that all four events were well above the average. We cautioned that a move back to the average was likely and this is exactly what happened.

This type of analysis can be helpful for determining exit points and stop losses.

#### Learning More

Are you interested in the more technical details of this article? If so, you can join our community to get an access key to the API, access to code samples and tools, and insights. We’re looking for like-minded tinkerers and crypto geeks to give us feedback that shape our API and make our platform more valuable to traders and enthusiasts alike.

If not, that’s ok too. Our collaborators are helping us build world-class statistical tools to support crypto traders directly. If you still want to benefit from our insights including regularly published analysis, follow us on Twitter for our periodic insights or subscribe to our mailing list on our website for email updates.

Finally, if you like what you just read: Feel free to bookmark this article, clap, or leave a comment! It helps us help more people!