Difference calculus, examples. - page 12

 
Aleksey Panfilov:

Ideas are welcome.

Since there are no suggestions, let's go "off the beaten track".

Appended to this article the basic indicator and the version of the Expert Advisor for MT5.

Optimization on the 5-minute timeframe.

The figures are in Excel.

 

We still use only the indicator signals.

We assume the main signal on M5 and refinement of the entry on M1. Optimized on M1 on the opening prices. In the testing folder, the selected (not very carefully) variant by "open prices" and by "all ticks". I see no fundamental differences. Testing on the interval twice as big as the optimization interval.


 
Aleksey Panfilov:

For example, here is another variant of using price increments as new information. Here, the increment is read explicitly as a difference.

1*Y1-1*Y2-2*Y2+3*Y3-1*Y4 =0

1*Y1-1*Y2-3*Y2+6*Y3-4*Y4 + 1*Y5 =0

1*Y1-1*Y2-4*Y2+10*Y3-10*Y4 + 5*Y5 -1*Y6=0

1*Y1-1*Y2-5*Y2+15*Y3-20*Y4 + 15*Y5 -6*Y6 + 1*Y7=0

1*Y1-1*Y2-6*Y2+21*Y3-35*Y4 + 35*Y5 -21*Y6 + 7*Y7 -1*Y8=0

...

The figure shows that the line (red) built conditionally by the polynomial of the fifth degree (according to the number of connected points) also began to steadily hold near the graph.


We, as it were, due to the polynomial of the fourth degree on the first differences (price increments) have increased (by the number of points) the degree to the fifth.

Is this it, regularization?


I looked at the figures, compared them with the picture from the VIKI "Binomial coefficient", it turns out they are the same:


These are "coefficients in the expansion of (1+x)^n in a power series.

"The rows in a Pascal triangle divided by 2^n (the sum of all the numbers in the row) tend, in the limit, to a normal distribution function."

When the thread was created, it said that "math, ..." was primarily of interest. So I wrote. Mathematical relations of Pascal's triangle in VIKI are painted in much more detail, only it is not known what is needed.

 
Vladimir:

I looked at the numbers, compared them to the picture from the VIKI "Binomial coefficient", and it turns out they are the same:


It is "coefficients in the expansion of (1+x)^n in a power series"

"The rows in a Pascal triangle divided by 2^n (the sum of all the numbers in the row) tend, in the limit, to a normal distribution function."

When the thread was created, it said that "math, ..." was primarily of interest. So I wrote. The mathematical relationships of Pascal's triangle in WIKI are spelled out in much more detail, only it's not clear which one is needed.

If this is a question, it sounds very much like a rhetorical question. ))

Answering such a question is not easy. The properties of the triangle show up in very different "topics".

You mentioned statistics, I've already tried to get up to speed from a kinematics perspective (in the attached links).

Forum on trading, automated trading systems and strategy testing

Difference Calculus, Examples.

Aleksey Panfilov, 2018.01.10 16:34


Yes.

Directly related to Newton's Binomial.

It is true for equidistant points:

1*Y1-2*Y2+1*Y3=0- difference equation of the straight line.

1*Y1-3*Y2+3*Y3-1*Y4=0 - the difference equation of the second degree parabola.

1*Y1-4*Y2+6*Y3-4*Y4+ 1*Y5=0 - difference equation of the parabola of the third degree.

It also overlaps with the topics:

https://www.mql5.com/ru/forum/61389/page48#comment_5633264

https://www.mql5.com/ru/forum/211220/page2#comment_5632736 .

I attach, in my opinion, an interesting article in the journal "Kvant". And this is not the only article by N.B. Vasiliev on this topic, and of course it does not exhaust the whole range of manifestation of the properties of Pascal's triangle. (Let us leave aside the fact that Pascal was not the first to pay attention to this "model".)

P/S. The name of the archive is crooked, it was called: Nikolay Vasiliev. Journal Quant.doc.zip

 
Aleksey Panfilov:

If that's a question, it sounds very much like a rhetorical question. ))

Answering such a question is not easy. The properties of a triangle manifest themselves in very different "topics".

You mentioned statistics, I've already tried to get up to speed from a kinematics perspective (in the attached links).

I attach, in my opinion, an interesting article in the journal "Quant". And this is not the only article by N.B. Vasiliev on this topic, and of course it does not exhaust the whole range of manifestations of the properties of Pascal's triangle. (Let us leave aside the fact that Pascal was not the first to pay attention to this "model".)

P/S. The name of the archive is crooked, it was called: Nikolay Vasiliev. Quant journal.doc.zip

Thank you for your detailed reply. I read all additional materials. The question as such was not, rather a reaction to your suggestion from another branch https://www.mql5.com/ru/forum/221552/page194#comment_6625488 :"Is it possible, so to use both the second and n-difference, and EMA from the first to the fourth degree? It would be curious to make a general scheme of processes in similar examples."

It is not necessary to go to the generality of the scheme by gradually increasing the number of considered differences by 1, you can go straight to a very large number of them by analyzing the properties of Pascal's triangle. It was in that branch, as far as I understood, that the need arose to estimate the "reference distribution". Let it be for thousands of increments, but the "benchmark" is immediately postulated in the properties of your coefficients from Pascal's triangle as aspiring to a normal distribution. @Alexander_K2 was looking for a distribution of increments at least somewhat close to the Poisson distribution, and the Poisson distribution itself tends to be normal as the index increases. Looking from the perspective that your coefficients correspond to replacing the expression (1-x)^n by its difference analogue, then... we can also think of a general scheme of "processes in similar examples".

However, that would be out of that branch, and its author, in my opinion, is not interested in answers to the questions he himself asks. Although I personally would be curious to see the general scheme mentioned by you too.

 

P/S. Judging by the latest charts, we should check the optimization for trading time.

 

In general, the "push" on the opening time was not significant.

New chart.

The chart shows arrangement of deal closing and for deals lasting from 15 minutes to 15 hours (mainly) it is probably possible to regulate opening by time but not "directly". I do not know how to filter closing.

I do not know how to filter closing.

Files:
2018_02_28.zip  441 kb
 

I added an option to disable filtering layer in the last Expert Advisor.

And I fixed an inaccuracy, which forced to close a trade and open the opposite one, if necessary, on two different ticks / bars (when optimizing by opening points), instead of one.

  if(( line1_L0[0] > line2_L0[0] || L0_1_line_power ==0)  &&  (line1_L1[0] > line2_L1[0]  || L1_1_line_power ==0))
     {
      if(
           (
           (line1_L2[0] > line2_L2[0] || L2_1_line_power ==0) && ((New_Time[0]-3600*Start_Hour)%86400 < 3600*Period_Hour)
           )
            || Sell_opened
        )  
        {
         // есть ли в данный момент открытая позиция на покупку?
         if(Buy_opened)
           {
//            Alert("Уже есть позиция на покупку!!!");
            return;    // не добавлять к открытой позиции на покупку
           }        
         if(
             Sell_opened && ( line1_L0[0] > line2_L0[0] || L0_1_line_power ==0) &&  (line1_L1[0] > line2_L1[0]  || L1_1_line_power ==0)
              && (line1_L2[0] > line2_L2[0] || L2_1_line_power ==0) && ((New_Time[0]-3600*Start_Hour)%86400 < 3600*Period_Hour)
           )
            {      LotS = 2*Lot;      }        
            else   LotS = 1*Lot;

If the filtering by layer should be disabled, then the degree of the first line in the layer should be equal to 0. If the degree of the second line is also zero, then I suppose it will speed up the calculation, because one of the conditions of an extra indicator per cycle will not be fulfilled.

Cancellation of filtering by opening time is provided by assigning the allowed period more than 24 hours.

//=====================================================================================
input int      Start_Hour=0;
input int      Period_Hour=25;

input int     EA_Magic       = 12345;    // Magic Number slippage 
input int     EA_Slippage    = 30;       // Slippage from the current price
//=====================================================================================
//--- глобальные переменные
Files:
 

And of course you can't leave even a tester EA without correctly working TP and SL.

   if((line1_L0[0] < line2_L0[0] || L0_1_line_power ==0) &&  (line1_L1[0] < line2_L1[0] || L1_1_line_power ==0) && relay >= 0 )
     {
        relay = -1;
     
      if(
          (
          (line1_L2[0] < line2_L2[0] || L2_1_line_power ==0) && ((New_Time[0]-3600*Start_Hour)%86400 < 3600*Period_Hour)
          )
           || Buy_opened  
        )
        {
         // есть ли в данный момент открытая позиция на продажу?
         if(Sell_opened )
           {
//            Alert("Уже есть позиция на продажу!!!");
            return;    // Ждем исполнения стоп приказа //не добавлять к открытой позиции на продажу
           }
         if(
             Buy_opened  && (line1_L0[0] < line2_L0[0] || L0_1_line_power ==0) &&  (line1_L1[0] < line2_L1[0] || L1_1_line_power ==0) 
             &&  (line1_L2[0] < line2_L2[0] || L2_1_line_power ==0) && ((New_Time[0]-3600*Start_Hour)%86400 < 3600*Period_Hour)  
           )
            {      LotS = 2*Lot;      }        
            else
                   LotS = 1*Lot;

P/S.

Let me explain: TP and SL also worked before, but after closing by them, the signal to open was only the layer of the minimum period, and the middle and the oldest periods conditionally filtered by the trend. The second variant, with the switch, assumes the main signal by the smaller and the middle period, and the trend filtration only by the larger period, which is closer to the original idea.

PP/S.

I ran TP and SL optimization, it seems the first option was more useful.

Reason: