Target:
Due to the creation of an indicator, which needed to determine the direction of a trend formed earlier in order to further solve the algorithm, I came up with a certain formula to measure the trend strength (closeness of this trend to the ideal) as a percentage.
Below is represented the illustration that to my point of view symbolizes the ideal trend (on the left side is the down trend, on the right side is the up trend). Next to each trend are indicated existence conditions of an ideal trend:
The algorithm:
At first, to write this function I decided to enter the rating system, i.e. for every true condition some “ball” variable gets one rating. Further on these ratings were formed into this variable and after calculating the ratings at last the received number of ratings was divided by the maximum possible number and multiplied by 100% that allows conversing the received ratings into a percentage.
Actually the function itself is given in the Func_Trend.mqh.
Another type of analysis:
Then I came up with another idea, which supposed a non-uniform accrual of ratings. For example, for the most important conditions more ratings would be accrued. So the idea of counting the ratings by power of two was created and the more important the condition is, the higher the power of two will be.
Below is represented the illustration with a lot of number of conditions for each trend. More important conditions are located at the beginning of the list:
The conditions were added into the functions and the sense of calculating the ratings changed, but, in general, the trend percentage remained the same. It can be seen in the Func_Trend_2.mqh.