The regularities of price movements: Part 2. Series of bars

 

This part will focus on exploring bar (candlestick) series.
In the script below I have used the following terminology: a rising bar is a bar with a closing price higher than the opening price and a falling bar is a bar with a closing price lower than the opening price.

To begin with, I will publish the script. I ask professionals in the field of programming to check it for logical errors in bar calculations. If there are logic errors in the calculations - I will be
grateful for your feedback.
The script calculates the minimal share of increasing and decreasing bars in a series of the given length. The series length is set in the window of source data, it is specified by default as 100 bars.

The script operation results are displayed on the chart some time after starting the script. For example, for a series of 100 bars for EURUSD TF H1, the minimum historical number of increasing bars is
34 bars (34%):

I want to draw your attention to the fact that the script runs through the whole history and if the history is long (small TF) or has large series (more than 100) the script
can perform calculations long enough, up to several minutes (depending on the PC capabilities):

Script:

// Скрипт для подсчёта минимальных долей растущих и падающих баров в серии баров //
// Skript MinRastPadBarSeriya, июнь 2012
// Примечание: скрипт подвешивает терминал при больших сериях на малых ТФ - ждите
#property  copyright "Copyright © Svinotavr-2000"
#property  link      "https://www.mql5.com/ru/users/DmitriyN" 
#property show_inputs             // Показываем окно исходных данных   

extern int DlinSer=100;           // Вводим длину серии, бар, по умолчанию - 100 бар.
   
int start()
 { 
   // Декларация переменных
   double DliPer;                 // Длительность периода исследования, лет
   double n;                      // Количество бар главного цикла, шт
   double Pogreshnost;            // Погрешность, %
   
   double progr;                  // Переменная прогресс-индикатора (доля единицы)
   
   double DolyRastBar;            // Доля растущих бар в серии, %
   double MinDolyRastBar=101;     // Минимальная доля ростущих бар %, для начала - >100
   double KolRast;                // Количество растущих баров в серии, шт
   
   double DolyPadBar;             // Доля падающих бар в серии, %
   double MinDolyPadBar=101;      // Минимальная доля падающих бар %, для начала - >100
   double KolPad;                 // Количество падающих баров в серии, шт
   
   // Берём число бар на DlinSer меньшее, чтобы не залезть за пределы истории
   n=Bars-DlinSer-1;
   // Цикл по всем барам
        Comment("Ждите, идёт расчёт");               // На мелких ТФ скрипт подвисает
        for(int j = 0; j < n; j++)                 // Главный цикл - по всем доступным барам
        { 
            KolRast=0;                             // Обнуляем счётчик для след. цикла серии
            KolPad=0;                              // Обнуляем счётчик для след. цикла серии
            for(int i = j; i < (j+DlinSer+1); i++) // Цикл серии
            {   
                if (Close[i] > Open[i]) KolRast=KolRast+1; // Добавляем к счётчику 1 бар      
                if (Close[i] < Open[i]) KolPad=KolPad+1;   // Добавляем к счётчику 1 бар              
                    
            DolyRastBar=KolRast/DlinSer*100;       // Вычисляем долю растущих бар, %
            DolyPadBar= KolPad/DlinSer*100;        // Вычисляем долю падающих бар, %
            }                                      // Конец цикла серий
         // Если доля растущих бар за этот цикл меньше, чем минимальная доля за предыдущие _
         // _ циклы, то принимаем её как минимальную в главном цикле
         if (MinDolyRastBar > DolyRastBar) MinDolyRastBar= DolyRastBar;
         // Если доля падающих бар за этот цикл меньше, чем минимальная доля за предыдущие _
         // _ циклы, то принимаем её как минимальную в главном цикле     
         if (MinDolyPadBar > DolyPadBar) MinDolyPadBar= DolyPadBar;                      
         
             // Прогресс-индикатор ======================================
             progr=(j/n)*1000 - MathFloor((j/n)*1000);
             if (progr>0.9999)                     // Частые комменты тормозят расчёты, _
             {                                     // _ поэтому ограничим число изменений
             Comment("Ждите, идёт расчёт, выполнено: ", (j/n)*100 , " %");
             } //========================================================
        }                                          //Конец цикла по всем барам
  // Вычисляем длительность периода истории исследования (календарный период)
  DliPer = n*Period()/(1440*365);
  // Вычисляем относительную погрешность расчётов (погрешность частичная)
  Pogreshnost=(DlinSer/n)*100;         
  // Формируем строки для печати
   string S0 = "\n" + "================= Результаты расчётов =================" + "\n" + "\n";  
   string S1 = "1. Исследовано бар = " + DoubleToStr(n,0)+ " шт" + "\n";
   string S2 = "2. Длительность периода исследования = " + DoubleToStr(DliPer,2)+ " лет" + "\n";
   string S3 = "3. Длина серии = " + DlinSer+ " бар"+ "\n"+ "\n";
   string S4 = "4. Минимальная доля рaстущих бар = " + DoubleToStr(MinDolyRastBar,2)+ " %"+ "\n";
   string S5 = "5. Минимальное количество рaстущих бар = " + DoubleToStr(MinDolyRastBar*DlinSer/100,0)+ " шт"+ "\n"+ "\n";
   string S6 = "6. Минимальная доля падающих бар = " + DoubleToStr(MinDolyPadBar,2)+ " %"+ "\n";
   string S7 = "7. Минимальное количество падающих бар = " + DoubleToStr(MinDolyPadBar*DlinSer/100,0)+ " шт"+ "\n"+ "\n"; 
   string S8 = "8. Погрешность расчётов (по длине серии/истории) = " + DoubleToStr(Pogreshnost,4)+ " %";  
  // Выводим строки на экран     
   Comment(S0, S1, S2, S3, S4, S5, S6, S7, S8);          
 }
I would also like to draw your attention to the fact that the script does not take into account zero bars, i.e. bars with the opening price equal to the closing price.

If anyone has any criticism of the script's calculations or any results in the field of similar research, please speak up.
Later I will join the discussion of regularities related to the series of bars and some tasks related to this topic.
 

my results show a series probability of 0.5^n

On MA it is the same

 
Rorschach:
According to my results, the probability of a series is 0.5^n
By my results too. For example, the probability of a series of 30 bars is somewhere around one billionth. If they were one-minute bars, then considering that there are 1440 minutes in a day and 365 days in a year (calendar period), the series
would have fallen out the last time around Christmas time (a couple thousand years ago).
 
is the length of the series interrupted by a rain or opposite-looking candle with a small body?
 

There is a reason why they call "short" a short and "long" a long.

In equities the disproportion will mostly be good, in forex it should be quite blurred.

 
sever32:
Is the length of the series interrupted by a doj or an opposite candle with a small body?

It is clear that yes.

The question was about a long series being interrupted by a doj or an opposite candle and then the previous series can repeat again.

There is no profit here, but there is a topic to talk about.)

 

I can't figure out what such an analysis can do, but let's chalk it up to my ineptitude.
But there is an observation about the essence of the analysis.
As I understood it, zero-height candlesticks are excluded from the calculation. Are candlesticks of minimal height (1, 2, 3) very much different from them? I think it doesn't differ much.
I think it would be more correct to consider only the candlesticks of "significant" length. As a criterion of significance we can take a modulus of (O-C)/(H-L) ratio.
The threshold value should be considered separately.

 

This is what the result looks like for a 4 o'clock series:

A series of 100 bars should have at least 36 rising bars.
From this you can conclude that if on a series of 50 bars you have already had 10 rising bars,
then on the next 50 bars you must have at least 36-10=26 rising bars (at least).
Consequently, the falling bars there will be about 50-26=24.
I.e. there will be about the same number of falling and rising bars.

Of course, the height of the bar is not taken into account.

 
DmitriyN:

This is what the result looks like for a 4 o'clock series:

A series of 100 bars should have at least 36 rising bars.
From this you can conclude that if on a series of 50 bars you have already had 10 rising bars,
then on the next 50 bars you must have at least 36-10=26 rising bars (at least).
Consequently, the falling bars there will be about 50-26=24.
I.e. there will be about the same number of falling and rising bars.

Of course, the height of the bar is not taken into account.

that's the tricky part.
 
MikeM:

I can't get a handle on what this kind of analysis can do_

I have written about this many times, that professionalism is made up of a large number of elements of understanding the process. Each element does not and cannot give anything in isolation.
However, it is quite possible to benefit from the totality of elements.
What good is a processor? None, as long as it is the only one. But if you add a motherboard, a graphics card, a power supply, etc ... - you know what happens.
 
DmitriyN:
This ficus picus can easily be eliminated by digitising the price, i.e. converting it to a digital format - a grid with a set pitch. But more on that later.

that's where you should have started.
Reason: