The script evaluates the probabilities of the price reaching the upper and lower levels over a specified time interval.
Often the analytical reviews have the forecasts that the upward or downward movement of an instrument price is more probable, however no data on the value of this probability is given. The data on probability of reaching a certain level is not given at all. Although, before opening a position, it is necessary to know the probability of market going upwards and reaching a certain level, or alternatively, of it going towards the lower level. These issues are even more relevant if there is an open position present already. The script calculates the probabilities of five events which can happen during the specified time interval:
- event 1: the price reaches the upper level, and by the current moment of time it will not fall to the lower level;
- event 2: the price reaches the lower level, and by the current moment of time it will not rise to the upper level;
- event 3: during the specified time interval the price does not reach any of the specified levels and will stay strictly between them;
- event 4: the price reaches the upper level, regardless if the lower level had been reached before;
- event 5: the price reaches the lower level, regardless if the upper level had been reached before.
The first three events cover all the possible scenarios of the price movement, i.e. comprise the entire event group.
Knowing the specified probabilities helps when placing the levels of stop loss and take profit, as well as limit orders. If there is an open long position, then the upper level can be interpreted as the take profit and the lower one as the stop loss. And vice versa for short positions.
The calculation method is based on the Black–Scholes model, which supposes the random character of the movement and log-normal distribution of the increments of the instrument price. The model considers the trend, volatility of the instrument and the duration of the time interval, for which the probabilities are evaluated.
The calculation uses the formulas from the publication: Antoon Pelsser. Pricing Double Barrier Options: An Analytical Approach. January 15, 1997. ABN-Amro Bank Structured Products Group (AA 4410).
- Period (bars) - the number of bars until the end of the forecast period.
- points to the high level - the number of points to the upper level from the price
- points to the low level - the number of points to the lower level from the price
- distance to the comment from the left - the distance from the left edge of the screen to the comment in pixels
- distance to the comment from the top - the distance from the top edge of the screen to the comment in pixels
The script works on any timeframe and any currency pair. By default the following initial conditions are set: the number of bars in the forecast period - 24, the distance from the current price to the upper and lower levels - 500 points.
According to the results of calculations the following fields are displayed on the chart:
- the vertical line defines the end of the time interval, for which the calculation is performed
- the green and red segments show the upper and lower levels
- the tick marks the expected average value of the price at the end of the interval
- the comment, that lists the events and their probabilities, is displayed in the top right corner of the chart.
If the mark of the 'Average' expected price is above the current price, then an uptrend is expected, otherwise - downtrend. If the mark is near the current price, then a sideways movement is expected. The further the level from current price, the less the probability of it being reached. This probability also depends on the volatility of the instrument and the duration of the period, for which the forecast is made. The higher the volatility and the longer the period, the higher the probability of the level being reached.
It is not recommended to set too long (more than 100 bars) or too short (less than 10 bars) forecast periods. For example, instead of a 1440 bars period on one-minute time frame is better to set a period of 24 on the hourly chart and 96 on the 15 minute timeframe.
If the comment to the calculations does not fit on the screen, change the distance to it from the left edge (the 'distance to the comment from the left' parameter). The 'distance to the comment from the top' parameter allows to shift the comment down.