
Simple Methods of Forecasting Directions of the Japanese Candlesticks
Introduction
Japanese candlesticks represent one of the ways of displaying information on prices over a certain period of time showing the correspondence between open, close, high and low prices. Candlesticks are primarily used in technical analysis and interpreted in accordance with well-known models.
After writing several indicators for forecasting the direction of the market movement, I came up with an idea of analyzing the possibility of doing a basic forecast of directions of the Japanese candlesticks based on the available data on the directions of the preceding candlesticks.
The article deals with a few simple forecasting methods and introduces several EAs for testing the ideas and assessing their effectiveness.
The first method is based on the assumption that the direction of the next candlestick coincides with the direction of the preceding one. The second method assumes that the direction of the next candlestick will be opposite to that of the preceding one. The benefit of these methods lies in their simplicity. We will review them in the "Naive Methods" section.
The third method is a combination of the first two. At first, we choose either the first or the second method and the chosen method is then used unless and until the forecast appears to be different from the reality (in case an error is detected). In this case the method that is currently in use is replaced with the other one. This method is more complex than the first two as it takes into consideration errors that occurred at the previous stages. We will therefore review this method in the "Adaptive Method" section.
Basic Data for Forecasting
All the methods under consideration rest upon the information on the direction of the preceding candlestick. Therefore, we should first think of a way of getting the information on the direction of any given candlestick.
The term "direction of the candlestick" will be used to refer to the value characterizing the sign of the difference between opening and closing prices of a given candlestick. In view of this, the direction of any candlestick can take one of three values - "direction up", "direction down" and "no direction".
Information on opening and closing prices of the candlestick can be accessed using the Open and Close arrays, respectively. These arrays use shifts as indices. A shift is the number of a candlestick counted from the right hand side of the chart, starting with zero. That means that the shift of the current candlestick is zero, while the shift of the preceding candlestick is one.
// getting the direction of the candlestick double GetCandleDirection(int shift) { double diff=Close[shift]-Open[shift]; if (diff>0.0) { return (DIRECTION_UP); } else if (diff<0.0) { return (DIRECTION_DOWN); } else /*if (diff==0.0)*/ { return (DIRECTION_NONE); } }
The function receives the shift of the candlestick and calculates the difference of its opening and closing prices. Depending on the sign of the resulting figure, the function returns the value of one of the three constants, DIRECTION_UP, DIRECTION_DOWN or DIRECTION_NONE. These constants correspond to "direction up", "direction down" and "no direction", respectively.
Note that values of the constants used for indicating different directions should be defined so as not to cause difficulties when calculating the opposite direction. The sign change can serve as one of the ways of calculating the opposite direction. These constants can then be defined as follows:
// determining the possible candlestick directions #define DIRECTION_NONE 0 #define DIRECTION_UP 1 #define DIRECTION_DOWN -1
Let's arrange a separate output of the candlestick directions in the chart, using the CandleColor.mq4 indicator attached to the article. The indicator displays the directions of the candlesticks (the blue and red histograms), as well as a simple moving average based on the data on the directions which allows us to get a general idea of the candlesticks prevailing over a certain period of time.
Candlestick directions: Behavior over time.
As shown by the indicator, the directions of candlesticks very often change, alternating or remaining the same for a few candlesticks in a row. Clearly, forecasting the direction of even a single candlestick is a challenging task.
Let's now proceed to the consideration and detailed analysis of the proposed methods.
Naive Methods
We will start with the first two methods:
- The direction of the next candlestick will coincide with the direction of the preceding one.
- The direction of the next candlestick will be opposite to that of the preceding one.
To test the effectiveness of both methods, an Expert Advisor (the CandlePredTest_naive.mq4 file attached to the article) was developed and tested.
The Expert Advisor uses opening prices. On each new bar, it closes all positions that were opened earlier (takes profit or stops loss) and opens a position in accordance with the hypothesized direction of the next candlestick (just now opened). The forecast of the next candlestick direction is performed by the ModelPredict function:
// forecasting based on the current model int ModelPredict() { if (modelState==STATE_NORMAL) { return (GetCandleDirection(1)); } else /*if (modelState==STATE_REVERSE)*/ { return (-GetCandleDirection(1)); } }
The function implements two forecasting methods. The choice of the method depends on the value of the modelState variable.
If the modelState variable takes on the value of STATE_NORMAL, the forecasting will follow the first method whereby the function calls GetCandleDirection(1) for the direction of the preceding candlestick and returns the obtained value as the direction of the next candlestick.
The second forecasting method is used if the modelState variable value is STATE_REVERSE. In this case, the calculation of the opposite direction is done through the sign change, i.e. the ModelPredict function returns the value of -GetCandleDirection(1).
Although the modelState variable is missing from the list of parameters of the Expert Advisor, its value is copied from the initialModelState external variable upon launching the Expert Advisor:
// model state extern int initialModelState=STATE_NORMAL;
This additional complication of the code is provided due to the fact that the number of states may further increase, while not all of those states will be allowed at the start of operation. You can use any values as indications of states. For example, in the Expert Advisor under consideration, they are defined as follows:
// defining the model states #define STATE_NORMAL 0 #define STATE_REVERSE 1
The remaining code of the Expert Advisor is provided with very detailed comments and should not be of any difficulty to the reader.
The conditions for testing the Expert Advisor are as shown below:
- Position volume - 0.1 lot.
- Initial deposit - $10,000.
- Time frames - all time frames available.
- Operation modes - STATE_NORMAL, STATE_REVERSE.
- Testing period - all available history.
- Instruments:
- USDCHF
- GBPUSD
- EURUSD
- USDJPY
- AUDUSD
- USDCAD
- EURGBP
- EURCHF
- EURJPY
- GBPJPY
- GBPCHF
- EURAUD
The criteria according to which the results were compared are net profit and percentage of profitable trades.
The following two tables demonstrate the results of testing the Expert Advisor in the STATE_NORMAL mode (first method).
Net profit:
M1 | M5 | M15 | M30 | H1 | H4 | D1 | |
---|---|---|---|---|---|---|---|
USDCHF | -9902 | -9900 | -9903 | -9907 | -9901 | -9900 | -9927 |
GBPUSD | -9868 | -9864 | -9869 | -9887 | -9873 | -9868 | -9924 |
EURUSD | -9921 | -9957 | -9949 | -9941 | -9934 | -9910 | -9879 |
USDJPY | -9900 | -9905 | -9900 | -9905 | -9935 | -9926 | -9904 |
AUDUSD | -9952 | -9957 | -9966 | -9962 | -9961 | -9956 | -10000 |
USDCAD | -9901 | -9903 | -9901 | -9900 | -9902 | -9904 | -8272 |
EURGBP | -9862 | -9861 | -9864 | -9869 | -9875 | -9871 | -5747 |
EURCHF | -9862 | -9865 | -9865 | -9874 | -9869 | -9862 | -5750 |
EURJPY | -9866 | -9877 | -9964 | -9877 | -9869 | -9867 | -10000 |
GBPJPY | -9848 | -9841 | -9840 | -9845 | -9848 | -9870 | -9849 |
GBPCHF | -9891 | -9885 | -9850 | -9844 | -9857 | -9856 | -9891 |
EURAUD | -9865 | -9863 | -9868 | -9874 | -9861 | -9891 | -10000 |
Percentage of profitable trades:
M1 | M5 | M15 | M30 | H1 | H4 | D1 | |
---|---|---|---|---|---|---|---|
USDCHF | 19.55 | 27.82 | 31.50 | 38.18 | 39.86 | 43.29 | 43.95 |
GBPUSD | 21.18 | 27.81 | 30.29 | 33.81 | 35.20 | 41.39 | 46.71 |
EURUSD | 26.06 | 33.20 | 34.59 | 37.55 | 41.64 | 43.73 | 44.37 |
USDJPY | 19.28 | 31.68 | 34.13 | 35.48 | 39.04 | 42.99 | 46.85 |
AUDUSD | 19.71 | 21.30 | 26.25 | 27.20 | 33.15 | 39.96 | 44.69 |
USDCAD | 21.88 | 25.13 | 27.59 | 31.79 | 33.07 | 39.48 | 46.40 |
EURGBP | 21.78 | 28.90 | 31.49 | 34.55 | 35.24 | 42.11 | 47.04 |
EURCHF | 28.70 | 27.86 | 27.85 | 31.13 | 32.90 | 39.08 | 47.65 |
EURJPY | 23.69 | 30.62 | 35.81 | 38.89 | 39.06 | 44.04 | 48.16 |
GBPJPY | 10.11 | 19.47 | 33.48 | 37.39 | 37.75 | 43.09 | 47.42 |
GBPCHF | 23.17 | 23.95 | 30.84 | 33.50 | 36.03 | 42.43 | 47.90 |
EURAUD | 1.65 | 7.35 | 16.55 | 22.24 | 27.65 | 36.11 | 44.64 |
The testing of the first method showed poor results. Regardless of the period, we see the loss of the deposit for all the instruments; that said, the number of profitable trades increases on bigger time frames but it never exceeds 50%.
The following two tables show the results of testing the Expert Advisor in the STATE_REVERSE mode (second method).
Net profit:
M1 | M5 | M15 | M30 | H1 | H4 | D1 | |
---|---|---|---|---|---|---|---|
USDCHF | -9900 | -9912 | -9902 | -9917 | -9915 | -9901 | +83 |
GBPUSD | -9864 | -9866 | -9869 | -9874 | -9870 | -9911 | -5565 |
EURUSD | -9920 | -9917 | -9923 | -9947 | -9922 | -9886 | +4249 |
USDJPY | -9906 | -9901 | -9906 | -9900 | -9900 | -9928 | +2003 |
AUDUSD | -9955 | -9956 | -9957 | -9956 | -9969 | -9947 | +1203 |
USDCAD | -9900 | -9900 | -9900 | -9900 | -9901 | -9906 | -3129 |
EURGBP | -9868 | -9862 | -9862 | -9863 | -9867 | -9902 | -9867 |
EURCHF | -9863 | -9861 | -9863 | -9862 | -9869 | -9869 | -6556 |
EURJPY | -9861 | -9864 | -9866 | -9868 | -9897 | -9886 | -10000 |
GBPJPY | -9850 | -9887 | -9905 | -9857 | -9969 | -9848 | -9964 |
GBPCHF | -9846 | -9841 | -9842 | -9842 | -9886 | -9914 | -9850 |
EURAUD | -9870 | -9866 | -9874 | -9910 | -9872 | -9872 | -2411 |
Percentage of profitable trades:
M1 | M5 | M15 | M30 | H1 | H4 | D1 | |
---|---|---|---|---|---|---|---|
USDCHF | 18.38 | 27.41 | 33.76 | 37.46 | 42.28 | 46.71 | 52.15 |
GBPUSD | 18.59 | 27.71 | 34.07 | 39.01 | 43.79 | 47.33 | 49.39 |
EURUSD | 23.37 | 33.88 | 41.05 | 43.80 | 43.56 | 48.16 | 52.56 |
USDJPY | 16.88 | 30.39 | 38.13 | 40.29 | 43.94 | 46.62 | 49.34 |
AUDUSD | 18.84 | 22.52 | 25.39 | 29.83 | 36.36 | 43.51 | 49.84 |
USDCAD | 22.44 | 24.04 | 27.07 | 31.06 | 35.69 | 43.51 | 49.84 |
EURGBP | 20.52 | 28.89 | 35.18 | 38.82 | 42.41 | 45.82 | 45.55 |
EURCHF | 27.43 | 31.82 | 32.80 | 35.05 | 36.74 | 43.89 | 46.04 |
EURJPY | 18.79 | 28.15 | 37.09 | 39.80 | 43.05 | 44.15 | 46.92 |
GBPJPY | 10.02 | 19.76 | 31.92 | 38.06 | 41.84 | 44.32 | 47.53 |
GBPCHF | 19.87 | 27.24 | 33.72 | 35.70 | 39.74 | 47.59 | 46.11 |
EURAUD | 1.43 | 7.66 | 17.24 | 26.95 | 34.46 | 41.29 | 47.07 |
We have got mixed results when testing the second method. The results on all the time frames, except for D1, have been about the same as the ones obtained for the first method. Trading on D1, the Expert Advisor gained profit on four instruments out of the twelve. The percentage of profitable trades was close to 50%, reaching 52% in two cases.
In general, the Expert Advisor's testing results leave much to be desired. Let's try to use a combination of the naive methods to cancel out their disadvantages.
Adaptive Method
The essence of the third method is that we do the forecast using one of the two naive forecasting methods which is replaced with the other one in case of an error. In this way, this method adapts to the behavior of the forecast series.
The effectiveness of this method was verified by testing the corresponding Expert Advisor (the CandlePredTest_adaptive.mq4 file attached to the article).
This Expert Advisor represents an improved version of the CandlePredTest_naive Expert Advisor. Its key difference is in that each previous forecast is analyzed for errors on each new bar.
// working function of the Expert Advisor int start() { // positions are opened once on each bar if (!IsNewBar()) { return (0); } // close all open positions TradeClosePositions(DIRECTION_UP); TradeClosePositions(DIRECTION_DOWN); // update the model state if (prediction!=DIRECTION_NONE) { ModelUpdate(prediction==GetCandleDirection(1)); } // predict the color of the next candlestick prediction=ModelPredict(); if (prediction==DIRECTION_NONE) { return (0); } // open a position in the right direction TradeOpenPosition(prediction,""); return (0); }
Errors are analyzed only if the Expert Advisor opened positions on the previous bar, i.e. if the forecast did not return the DIRECTION_NONE constant. The errors are all cases of discrepancy between the forecast and the actual direction of the closed candlestick whose shift becomes equal to one upon opening of the new bar.
One naive forecasting method is replaced by the other one using the ModelUpdate function that receives the forecast correction flag (prediction==GetCandleDirection(1)) as a parameter.
// updating the model state void ModelUpdate(bool correct) { // if the forecast was erroneous, change the model state if (!correct) { if (modelState==STATE_NORMAL) { modelState=STATE_REVERSE; } else /*if (modelState==STATE_REVERSE)*/ { modelState=STATE_NORMAL; } } }
The function analyzes the forecast correction flag (correct) and in case of an error replaces the selected naive method of forecasting by changing the value of the modelState variable. The initial value of the modelState variable is copied from the initialModelState variable upon initialization. It is not material as the Expert Advisor can change the forecasting method during the course of its operation.
Forecasting is the responsibility of the ModelPredict function similar to that used in the CandlePredTest_naive Expert Advisor. As a result of changes in the modelState variable value, the forecast is performed based on the first and second methods, alternating each other.
The Expert Advisor was tested under the same conditions, with the only exception being the initialModelState variable value which was fixed (STATE_NORMAL).
Net profit:
M1 | M5 | M15 | M30 | H1 | H4 | D1 | |
---|---|---|---|---|---|---|---|
USDCHF | -9903 | -9905 | -9902 | -9915 | -9902 | -9907 | -3738 |
GBPUSD | -9866 | -9875 | -9876 | -9864 | -9867 | -9933 | -6404 |
EURUSD | -9924 | -9924 | -9931 | -9920 | -9920 | -9903 | -3779 |
USDJPY | -9904 | -9900 | -9900 | -9904 | -9920 | -9902 | -6493 |
AUDUSD | -9955 | -9954 | -9955 | -9995 | -9955 | -9965 | -8649 |
USDCAD | -9903 | -9902 | -9901 | -9911 | -9900 | -9904 | -1525 |
EURGBP | -9861 | -9867 | -9865 | -9862 | -9881 | -9877 | -9913 |
EURCHF | -9861 | -9862 | -9872 | -9881 | -9870 | -9875 | -9258 |
EURJPY | -9861 | -9865 | -9866 | -9868 | -9876 | -9905 | -9880 |
GBPJPY | -9842 | -9844 | -9867 | -9840 | -9919 | -10000 | -9933 |
GBPCHF | -9841 | -9843 | -9917 | -9840 | -9893 | -9848 | -9895 |
EURAUD | -9866 | -9869 | -9863 | -9872 | -9867 | -9904 | -7656 |
Percentage of profitable trades:
M1 | M5 | M15 | M30 | H1 | H4 | D1 | |
---|---|---|---|---|---|---|---|
USDCHF | 19.22 | 26.82 | 32.29 | 35.71 | 40.29 | 44.15 | 47.93 |
GBPUSD | 20.12 | 28.16 | 32.01 | 34.87 | 40.05 | 41.97 | 49.39 |
EURUSD | 25.24 | 32.65 | 38.32 | 39.48 | 41.50 | 45.81 | 48.88 |
USDJPY | 19.16 | 29.48 | 35.02 | 37.03 | 40.19 | 44.45 | 47.34 |
AUDUSD | 19.63 | 21.67 | 25.76 | 28.16 | 32.11 | 41.11 | 46.76 |
USDCAD | 22.84 | 24.46 | 27.39 | 29.79 | 34.44 | 42.26 | 48.46 |
EURGBP | 21.44 | 29.45 | 33.05 | 36.55 | 38.19 | 41.86 | 46.23 |
EURCHF | 27.51 | 29.98 | 30.92 | 34.44 | 34.09 | 40.87 | 44.27 |
EURJPY | 21.24 | 28.56 | 35.58 | 38.78 | 40.50 | 44.23 | 47.12 |
GBPJPY | 11.30 | 19.90 | 31.91 | 37.15 | 36.76 | 41.11 | 46.24 |
GBPCHF | 22.00 | 26.81 | 32.13 | 34.38 | 36.99 | 43.11 | 47.16 |
EURAUD | 1.50 | 6.56 | 15.14 | 22.25 | 31.63 | 37.96 | 47.70 |
The testing did not show significantly better results as compared to the first and second methods. The profit was negative for all instruments on all time frames, while the percentage of profitable trades did not exceed 50%.
Conclusion
The testing results provided in the article have demonstrated poor effectiveness of the reviewed methods.
- The first method turned out to be extremely ineffective. Probably, the assumption that the direction of the next candlestick coincides with the direction of the preceding one needs further verification in forecasting.
- The second method showed the best results out of all other methods under consideration. However it requires a more detailed analysis. For example, data on the number of trades, profit on which was not taken might prove interesting.
- The third method demonstrated average results compared to the first and second method and needs further improvement. The main idea behind it was the improvement of the characteristics as compared to the characteristics used in the naive methods. However it did not bring about any improvements. Apparently, this method very often interchanges the forecasting methods which leads to additional errors.
Translated from Russian by MetaQuotes Ltd.
Original article: https://www.mql5.com/ru/articles/1374





- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm a researcher. As I see, as we got a result, regardless of it is good or bad one, it is a result we can consider it in an other researches or avoid using the same concept to save other researchers time and effort. Also, it could direct to some new ideas or directions for the same topic.
So, I personally consider it a value added info for adding a new info to our knowledge.
Thanks to the author, Evgeniy Logunov :)
This is an old article. I have read with interest.
I chanced upon the "miracle of candlesticks" recently when I was talking to someone about what kind of market structure will trading be more successful.
Then it falls on me that that market structure is actually a particular candlestick on a higher time frame.
And so, I have also begun coding an independent test module for it. Of course, this article becomes one of my references.
Win ratio is almost guaranteed for a specific candlestick of a certain category, but only for certain time frames.
My own opinion is that I think you cannot trade every candlestick that comes, like what the author did in his case.
Then it will be like throwing multiple darts and hoping at least some of them land accurately and wins exceed losses.
That explains the negative report in this article.
Well I think if more people contribute their ideas, even this seemingly useless article can also become an interesting topic in itself.
Just need more people to see the rationale behind it.