Discussion of article "What is a trend and is the market structure based on trend or flat?" - page 8

 
Maxim Dmitrievsky:

I'd go to the deputy minister's office for a two-month apprenticeship like that.

I'd become president for that.) To learn how to earn money at virtually no risk.

 

Can you please tell me what variance you take for the reference graph? The mathematical expectation is clear - 0.

 
Alexey Klenov:

Can you please tell me what variance you take for the reference graph? The mathematical expectation is clearly 0.

I did not calculate the variance for the benchmark. I built the benchmark using the table, a part of which is shown in Figure 4. I have attached an Excel file to the article, which contains an example of calculating the table.
The benchmark is constructed with the help of combinatorics. That is, the number of combinations and the probability of each combination falling out are calculated.
 

I cannot repeat the shape of the theoretical curve

If I take sigma 3.2, I fall approximately in height, but I don't hit the dips (in this case +-12).

If I take sigma 5.8, I fall in the region of (+-20), but I do not fall in height

The sum of all Y equals 100000 in both cases.

To generate a random variable according to the normal law, I took a function from the standard library.

MathRandomNormal

Apparently the combinatorics method does not produce a variant of the standard deviation according to the normal law.

....I wanted to repeat it in MQL without factorials.

 
Alexey Klenov:

Failure to replicate the shape of the theoretical curve

If I take sigma 3.2, I approximately fall in height, but do not hit the dips (in this case +-12).

If I take sigma 5.8, I fall in the region of (+-20), but I do not fall in height

The sum of all Y equals 100000 in both cases.

To generate a random variable according to the normal law I took a function from the standard library.

MathRandomNormal

Apparently, the combinatorics method does not produce a variant of the standard deviation according to the normal law.

....I wanted to repeat it in MQL without factorials.

In Figure 6, I measured the shape of the distribution for random walk, I think for 100,000 samples. The white histograms are random walk. I think I attached a file to the article, it should be called 50% or something like that. There I randomly generated 0 and 1 If it was 0, then the previous value minus 1, if it was 1, then the previous value plus 1. This is how the random wander graph is constructed. Just measure the sigma parameters on it and use it.
 
Alexey Klenov:

To generate a random variable according to the normal law, I took a function from the standard library.

MathRandomNormal

Apparently the combinatorics method does not produce a variant of standard deviation according to the normal law.

....I wanted to repeat it in MQL without factorials.

Example for the section Normal distribution?

Документация по MQL5: Стандартная библиотека / Математика / Статистика / Нормальное распределение
Документация по MQL5: Стандартная библиотека / Математика / Статистика / Нормальное распределение
  • www.mql5.com
//| Script program start function                                    | //|  Calculate frequencies for data set                              |                               //|  Calculates values for sequence generation                       |
 
Rashid Umarov:

Example for the section Normal distribution?

The basis was taken from this very example.

 
Maxim Romanov:
In Figure 6, I measured for random walk the shape of the distribution, sort of for 100,000 samples. The white histograms are random walk. I think I attached a file to the article, it should be called 50% or something like that. There I randomly generated 0 and 1 If it was 0, then the previous value minus 1, if it was 1, then the previous value plus 1. This is how the random wander graph is constructed. Just measure the sigma parameters on it and use it.

I understand that you get double quantisation of the series.

The first time you quantise by +1 -1 and the second time you quantise these "renko bars" into plots of 40 bars.

Maybe you get this form of "normal distribution".

Wouldn't it be more logical to cut the first time as you did into renko bars and then to follow the principle of directional reversals?

For example your figure 1

+3 -1 -1 +2 -2 -2 +1 -4 +2 -2 -2 +4 and so on.

as a result, there will be no values at the zero point on X (although you can consider the reversal as +1 in x0).

and already perform combinatorics with this series.

then we can take the normal distribution of MO 0 and sigma 1 as a reference.

although I am still thinking about it...

 
Alexey Klenov:

The basis was taken from this very example.

So show me the code

 
//+------------------------------------------------------------------+
//|testNormal.mq5 |
//|AlexKl |
//|https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "AlexKl"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property script_show_inputs
//+------------------------------------------------------------------+
//| Script programme start function|
//+------------------------------------------------------------------+
#include <Graphics\Graphic.mqh>
#include <Math\Stat\Normal.mqh>
#include <Math\Stat\Math.mqh>
input double mean_value=0;  // mathematical expectation (mean)
input double std_dev=1;     // standard deviation (standard deviation)
void OnStart()
  {
   long chart=0;
   string name="GraphicNormal";
   double  dNormalRandom[];   // random floating point numbers
   int iNormalRandom[];       // rounded numbers from the array dNormalRandom
   int n=100000;       // number of values in the sample
   double x[];          // histogram interval centres
   double y[];          // number of values from the sample that fall into the interval
   double max,min;      // maximum and minimum values in the sample
// generate an array of random variables according to the normal law
   MathRandomNormal(mean_value,std_dev,n,dNormalRandom);

   ArrayResize(iNormalRandom,ArraySize(dNormalRandom));
// fill the array of rounded numbers from the array of random numbers of type double
   for(int i=0; i<ArraySize(dNormalRandom); i++)
     {
      iNormalRandom[i]=(int)round(dNormalRandom[i]);
     }
   CalculateHistogramArrayItsMy(iNormalRandom,x,y);


//Drawing
   CGraphic graphic;
   if(ObjectFind(chart,name)<0)
      graphic.Create(chart,name,0,0,0,780,580);
   else
      graphic.Attach(chart,name);
   graphic.BackgroundMain(StringFormat("Normal distribution mu=%G sigma=%G",mean_value,std_dev));
   graphic.BackgroundMainSize(16);
//--- plot all curves
//--- and now let's plot the theoretical distribution density curve
   graphic.CurveAdd(x,y,CURVE_LINES,"Theory");

//--- plot all curves
   graphic.CurvePlotAll();
   graphic.Update();
   int summ=0;
   for(int i=0; i<ArraySize(y); i++)
     {
      summ+=y[i];
     }
   Print("Total amount by Y " + summ);
  }
//+------------------------------------------------------------------+
bool CalculateHistogramArrayItsMy(const int &data[],double &intervals[],double &frequency[])
  {

   double minv=data[ArrayMinimum(data)];
   double maxv=data[ArrayMaximum(data)];
   int range=maxv-minv;
   ArrayResize(intervals,range+1);
   ArrayResize(frequency,range+1);
   for(int i=0; i<range+1; i++)
     {
      intervals[i]=minv+i;
     }
   for(int i=0; i<ArraySize(data); i++)
     {
      int ii=(MathAbs(minv)+data[i]);
      frequency[ii]+=1.0;
     }
   return (true);
  }
//+------------------------------------------------------------------+