Probability Indicator, User's Guide

22 August 2018, 18:27
Steven Brown
0
760

Probability Indicator displays volatility bands on the price chart and calculates probabilities of price exceeding specified levels for the next bar. It does that by performing a statistical analysis of the completed bars in the chart's history, which may include years of data. The volatility bands differ from Bollinger bands in the calculation of standard deviation from the simple moving average, resulting in bands that delimit price swings in a way that is useful to the trader.


Theory of Operation

Volatility bands envelop the range of prices above and below a simple moving average in terms of the standard deviation from the SMA. They can be set to display any whole or fractional multiple of standard deviation, such as 2 or 1.4 standard deviations. The term "standard deviation" is from statistics, where it is a measure of the degree of dispersion of data points from the average or mean.  It is obtained by squaring the difference between each data point and the mean, calculating the mean of those squares to obtain the variance, and taking the square root of the variance to obtain standard deviation.

Figure 1.  A Normal 
Distribution

                                                    Figure 1.  A Normal Distribution


Figure 1 shows the familiar bell curve of a normal or Gaussian distribution of data points. Zero on the x axis represents the mean value of the data, and the negative and positive numbers to the left and right are multiples of standard deviations from the mean. Numbers along the y axis represent values of probability density. The highest value occurs at the mean, indicating the highest population of data points, and the values taper down toward zero at 4 standard deviations below and above the mean, where the fewest number of data points occur.

In a normal distribution, 68% of all data points lie within one standard deviation from the mean, 95% lie within two standard deviations, and 99.7% lie within three standard deviations from the mean. However, this indicator makes no assumption about the distribution of data but instead derives the distribution through statistical analysis of the available historical data in the chart on which the indicator is running.

Figure 2.  Distribution of historical price data

                                         Figure 2.  Distribution of historical price data.


Figure 2 shows the actual distribution of hourly close prices for the EUR/USD currency pair over a span of 4 years, encompassing 25,305 bars. It is a plot of 81 points, each one representing the relative number of close prices that occur within a range that is 0.1 standard deviations wide. The curve shows that the actual distribution is roughly normal, but it is asymmetric, having the highest probability density about 0.25 standard deviations below the mean, and it has slightly "fat tails," meaning that more data points occur far from the mean than in a normal distribution. This distribution is a function of the market and has greater practical value than an assumed normal distribution. It is not Gaussian, because fluctuations of price about a moving average are not purely random. Prices tend to oscillate in cycles or to trend in one direction, such that successive data points occur beyond a standard deviation. 

When the input variable bUseHighLow, which appears in the input dialog box as "Use bar highs and lows," is set to true, the maximum excursion of price, the high or low of each bar, is the data point from which probabilities and standard deviation are calculated. In that case, the indicator finds that, over a period of four years, 60.1% of the data points on the hourly graph of the EUR/USD currency pair lie within one standard deviation of the 30-period SMA, 93.5% lie within two standard deviations, and 98.8% lie within three standard deviations. When bUseHighLow is set to false, the closing price of each bar is the data point from which standard deviation is calculated and price excursion is measured. In that case, the indicator finds that 60.7% of closing prices lie within one standard deviation from the 30-period SMA, 91.3% lie within two standard deviations, and 98.0% lie within three standard deviations. In either case, the mean is the SMA or simple moving average of closing prices, and the distribution of prices about the mean is a characteristic of the market. Derived from a large sample of historical market data, that distribution is used to gauge the probability of price going above or below specified levels for the next bar on the graph. 

In statistics, standard deviation applies to a fixed set of data. The mean or average of the data is found, then the standard deviation of data points from the mean is calculated. However, trading involves a set of data points that is continually changing over time, as new data points are added and old data points lose significance. The mean becomes a moving average that is recalculated with every new data point, when the oldest data point is discarded. Likewise, standard deviation becomes a moving standard deviation, recalculated with every new data point. To be useful to the trader, volatility bands are best plotted in terms of standard deviation of data points from the moving averages calculated for each data point. That is how volatility bands of this indicator are calculated, but not how Bollinger bands are calculated. The difference is explained in my blog post The Flaw of Bollinger Bands. For now, let's consider how volatility bands can be useful to the trader.

Volatility bands that envelop a percentage of prices necessarily exclude a percentage of prices that occur outside the bands. If the bands at two standard deviations from the SMA enclose 93.5% of closing prices, then 6.5% (100% - 93.5%) occur outside the bands. That 6.5% includes data points above the upper band and below the lower band, so roughly half or 3.25% occur above the upper band, and 3.25% occur below the lower band. As that distribution is derived from a large sample of data, it can be inferred that the probability of any one data point occurring above two standard deviations is 3.25%. That probability would take all bars on the graph into account, including successive bars above and below two standard deviations from the SMA. The probabilities of price staying or closing within the upper and lower bands is calculated as the ratio of such bars to the total number of bars.


Figure 3

Figure 3.  One of the bars that determine probability.


Of particular interest to the trader is the probability of a data point occurring above n standard deviations above the SMA, or below n standard deviations below the SMA, when the previous bar was within n standard deviations of the SMA. Here n is the value of the input variable "Band standard deviations." The indicator calculates that probability as the percentage of bars within the upper and lower bands that are followed by a bar that extends above the upper band or below the lower band. Figure 3 shows one such bar, indicated by the white arrow. Entirely within the upper and lower bands, it is followed by a bar whose high extends above the upper band, colored red. The blue line is the SMA, and the yellow line is the EMA. The EMA being above the SMA at the close of that bar increases the probability that the following bar will extend above the upper band. 

The indicator calculates the probability of price going above n standard deviations above the SMA separately from the probability of price going below n standard deviations below the SMA. For the purpose of trading, that probability is applied as a predictive tool to the next data point, for the current bar which is not yet completed. For example, using default settings on the hourly graph, when the high and low of the most recent completed bar lie within one standard deviation of the SMA, and the EMA is above the SMA, the probability is 5.36% that price will go above one standard deviation above the current SMA at some time during the current bar not yet completed. If the EMA is below the SMA, the probability is much lower, only 0.297%. For the trader, it is useful to know the probability of price going beyond one band is higher than the probability of price going beyond the opposite band.

When the indicator is running on a chart that is being updated with new ticks, the EMA is updated with each new tick and is compared against the SMA updated at the close of the last completed bar. In that case, pressing the P key while the chart has the input focus updates the printout of probabilities in the terminal, taking the updated value of the EMA into account.  

To be useful as a predictive tool, the indicator ascertains the distribution of data points in terms of the previous SMA and standard deviation at each data point. For example, say the length of the SMA is set to 20 periods. When the indicator is doing the statistical analysis and gets to a bar for the hour 22:00, it compares the data point for that bar against the SMA and standard deviation calculated for the bars 02:00 through 21:00. It is done that way to optimize the indicator such that when it is applied for prediction, the values of the SMA and standard deviation are already known, and the only unknown is the data point (high, low, or close) of the current bar not yet completed. The indicator gives the probability of that future data point going beyond levels specified by the user, in terms of standard deviations above and below the current SMA, by the close of the current bar. Knowing the probabilities of price going beyond specified levels by the close of the current bar, the trader can set the stop loss and profit targets to minimize the probability of the stop being hit, and maximize the probability of the profit target being hit during that bar.

The probabilities of price going above n standard deviations above the SMA and below n standard deviations below the SMA are usually found to be equal, or nearly equal, if trend is disregarded, as when the input variable "EMA periods" is set to zero. Taking into account the trend, ascertained by the position of the EMA relative to the SMA, the probabilities are found to be unequal. It is usually the case that the probability of price going above n standard deviations above the SMA is higher when the EMA is above the SMA, and lower when the EMA is below the SMA. When the input variable "EMA periods" specifies a number of periods greater than zero, the indicator uses trend to improve the reliability of calculated probabilities.   

At this point, the reader may doubt the usefulness of a prediction that applies only to the current bar not yet completed. However, it needs to be understood that the indicator can be applied to a graph on any time frame, and the current bar can enclose an interval from minutes to hours to days. It is possible to run the indicator on charts for standard and non-standard timeframes, such as H2, H3, etc. In Metatrader 5, timeframes such as H3 are standard, and in Metatrader 4, non-standard timeframes can run as "offline charts," on which the indicator can run and which Metatrader can update in real time as new ticks arrive from the trade server. Details are explained in the section of this user's guide titled "Non-standard timeframes."


Input Variables

When the indicator is opened on a chart, Metatrader displays a dialog box in which values of input variables can be set by the user. Those variables have default values intended to optimize the usefulness of the indicator, but the user is free to experiment with other values. Descriptive phrases, instead of the actual names of input variables, appear in the dialog box. The following explains the function of each input variable.

"SMA Periods" specifies the number of bars that go into the calculation of the simple moving average against which the volatility bands are plotted.

"EMA Periods" specifies the number of bars or periods of the exponential moving average which is plotted to show which way prices are trending. An uptrend is indicated when the EMA is above the SMA, and a downtrend is indicated when the EMA is below the SMA. When the value of this input variable is greater than zero, the indicator derives probabilities of price going above or below specified levels when the EMA is above or below the SMA. When it is zero, no EMA is displayed or applied to the calculation of probabilities. A non-integer value, such as 3.5, may be entered for this variable, and the alpha for the EMA will be calculated accordingly.

"Band standard deviations" is the multiple of standard deviations to display on the graph and on which to calculate probabilities. It is normally a whole or fractional number from 1 to 3, although other values can be specified.

"Use bar highs and lows" is the descriptive phrase for the input variable bUseHighLow. It is set to true by default, in which case standard deviation and probabilities are calculated from the maximum excursion of price away from the SMA for each bar. Maximum excursion is the greater of the high minus SMA or SMA minus the low of the bar. Probabilities are calculated for the high of the current bar going above the specified number of standard deviations above the SMA and for the low of the current bar going below the specified number of standard deviations below the SMA.

When bUseHighLow is set to false, standard deviation is calculated from the closing price of each bar. Probabilities are calculated for the closing price of the current bar going above the specified number of standard deviations above the SMA and for the closing price of the current bar going below the specified number of standard deviations below the SMA.

"Use Bollinger calculation" is set to false by default, in which case the indicator uses the improved method to calculate standard deviation. This input variable can be set to true to force the indicator to use the Bollinger method of calculating standard deviation, so the user can see the difference as to how the bands envelope price excursions on the graph. The setting of this variable affects the calculation of probabilities.

"Significant digits" is set to 3 by default, in which case the printing of probabilities on the terminal is rounded to 3 significant digits. Examples of numbers rounded to 3 significant digits are 123, 12.3, 1.23, 0.123, and 0.0123. The user can set this variable to a higher number for greater precision in the printing of probabilities.

"Exclusion threshold" is set to 1.0 by default. It is the number of standard deviations, set by the input variable "Band standard deviations," below which bars above or below the opposite band are counted in the calculation of probability of price going above or below the level set by "Band standard deviations." It is explained in greater detail later in this guide.


Using Probability Indicator

With a distribution derived from market data, the reliability of probabilities inferred from that distribution depends on the size of the sample of data. The larger the sample, the greater is the practical value of the distribution. The chart on which the indicator runs should have at least 10,000 and preferably 25,000 or more bars.

When the indicator is launched on a chart, it plots the SMA, EMA, and volatility bands, performs a statistical analysis of the available data, from the oldest to the newest bars, then calculates and prints probabilities in the Metatrader terminal. A comment in the upper-left corner of the chart displays values of the SMA, the standard deviation, the upper band, and the lower band, updated every bar. The second line of the comment displays the current price in terms of standard deviations from the SMA, and the EMA, updated every tick.

The statistical analysis and calculation of probabilities can be repeated by pressing the P key while the chart has the input focus, which can be set by clicking the mouse pointer on the chart. Clicking on the chart also displays a price according to the position of the mouse pointer on the y (vertical) axis, then the indicator calculates and prints the number of standard deviations and the probabilities for that price. An exact value for price can be selected after clicking the crosshairs tooltip in the Metatrader toolbar. Pressing the C key while the chart has the input focus causes the indicator to print the current price and its distance from the SMA in terms of standard deviation.

Probabilities are also calculated for the next bar crossing below n standard deviations above the SMA or crossing above n standard deviations below the SMA when preceding bars lie above the upper band or below the lower band. Each statement of probability printed to the terminal indicates the number of bars from which the calculation of probability is made. For example, the statement "Probability of new bar crossing and closing below 0.500 standard deviations above SMA when EMA is below SMA is 0.0599 or 5.99% of 217 bars" means that 217 bars in the chart's history were found to be above 0.5 standard deviations above the SMA when the EMA is below the SMA and that 5.99% of them were followed by a bar that closed below 0.5 standard deviations above the SMA. The number of  bars from which the calculation is made is relevant to the statistical significance of the calculation. Many bars provide a more reliable gauge of probability than few bars. In the case where no bars meet the specified criteria, no probability for that condition is printed to the terminal.

The user should understand that a probability printed to the terminal applies only in the case where the stated condition exists. For example, the statement "Probability of new bar closing above 1.00 standard deviations above SMA when EMA is above SMA is 0.0373 or 3.73% of 10938 bars" applies to the current bar only if the preceding bar is below 1.00 standard deviations above SMA and the EMA is above the SMA.

Here a more detailed explanation of the "Exclusion threshold" input variable is in order. Probability of the next bar extending beyond n standard deviations from the SMA is calculated as the percent of bars within n standard deviations from the SMA that immediately precede a bar that extends beyond n standard deviations above or below the SMA. It is done that way to improve the predictive value of the calculated probability, because bars extending beyond a band are unlikely to be immediately followed by a bar extending beyond the opposite band, while bars within n standard deviations from the SMA are more likely to be followed by a bar that extends beyond n standard deviations from the SMA. That holds true as long as the bands are far apart. When the bands are close together, when the input variable "Band standard deviations" is set to a low value, such that the space between the bands is likely to encompass one or a few bars, it becomes more likely that a bar beyond one band can be followed by a bar that extends beyond the opposite band. 

When the value of the input variable "Exclusion threshold" is greater than the value of the input variable "Band standard deviations," the probability of the next bar extending above n standard deviations above the SMA is calculated as the percent of all bars below n standard deviations above the SMA that immediately precede a bar that extends above n standard deviations above the SMA. In that case, bars that extend beyond the opposite band are not excluded from the calculation. For clarity, this explanation is in terms of calculating the probability of the next bar extending above n standard deviations above the SMA, but it also applies to calculating the probability of the next bar extending below n standard deviations below the SMA.


Non-standard timeframes

Metatrader 5 has many available timeframes including non-standard ones such as M20 and H3, which are available from the Timeframes sub-menu of the Charts menu. Metatrader 4 has only the M1, M5, M15, M30, H1, H4, D1, W1, and MN standard timeframes. However, charts for non-standard timeframes, on which Probability Indicator can run, can be opened in Metatrader 4. To do that, it is necessary to open a chart for a standard timeframe and run the script named PeriodConverter on that chart. For example, to open a chart for the H3 timeframe, first open an H1 chart and run the PeriodConverter script on it. Metatrader Help explains how to run a script. When the script is executed on the H1 chart, it presents a dialog box to enter a value for the input variable "Period multiplier factor." To derive an H3 chart from an H1 chart, enter 3 as the value for that variable. When you click OK, the script generates a history file for the H3 timeframe. Select "Open Offline" from the File menu, select the H3 file that the script generated, and click Open. Metatrader opens a new chart, labeled "H3 (offline)." Although it is an offline chart, it can be updated in real time as long as the PeriodConverter script is still running on the H1 chart. The script updates the H3 history file as new ticks arrive in the H1 chart. Therefore it is necessary to keep the H1 chart open and the PeriodConverter script running in order for the H3 chart to be updated in real time. If Metatrader is closed and opened again, the H1 and H3 charts will be there, but the PeriodConverter script will have to be restarted on the H1 chart.


Share it with friends: