Calculation of the slope angle of the trend line. - page 21

 

Forum on trading, automated trading systems & strategy testing

Any questions from newbies on MQL4 and MQL5, tips and discussion on algorithms and codes

Nikolai Semko, 2020.10.26 00:34

You should not be afraid of speed. It's just a conditionality for type conversion.
As a variant of the angle definition function:

struct PointPriceTime
  {
   double            price;
   datetime          time;
                     PointPriceTime(double p, datetime t) { price=p; time=t; };
   void              Set(double p, datetime t){ price=p; time=t;};
                     PointPriceTime(PointPriceTime &p){ price=p.price; time=p.time; };
                     PointPriceTime() { price=0.0; time=0; };
  };

double Angle(PointPriceTime &p1,PointPriceTime &p2) // возвращает угол в градусах в приведенной системе координат price-price, где по оси X 
  {                                                 // расстояние между x1 и  x2  = N*_Point, где N - количество минутных баров во временном промежутке отрезка. 
   static int tf[9]= {PERIOD_M1,PERIOD_M5,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1,PERIOD_W1,PERIOD_MN1};
   int i=0;
   while(i<9 && SeriesInfoInteger(_Symbol,tf[i],SERIES_FIRSTDATE)>p1.time)
      i++;
   if(i==9)
     {
      Print("Время левой границы вне диапазона исторических данных");
      return DBL_MAX;
     }
   int bar1 = iBarShift(_Symbol,tf[i],p1.time);
   int bar2 = iBarShift(_Symbol,tf[i],p2.time);
   if(bar1==bar2)
      return 0.0;
   return atan((p2.price-p1.price)/((bar1-bar2)*PeriodSeconds(tf[i])*_Point/60))*180/M_PI;
  }

After MT5 the feeling of MT4 is just awful. The access to the history is somehow emasculated. I am not even speaking about the ticks.




 
Nikolai Semko:

And then where would that "corner" go?

 
Dmitry Fedoseev:

And then where do you put that 'angle'?

Bring it to a point a minute, watch how long and draw conclusions)

 
Valeriy Yastremskiy:

Bring to a point a minute, see how long and draw conclusions)

What's the point in a minute? Why bring in somewhere when everything is already reduced to points per bar a long time ago?

 
Dmitry Fedoseev:

And why in a minute? Why lead somewhere when everything has already been led to points per bar a long time ago?

philosophical question. If I take into account fractality at different TFs I sometimes estimate speed in bars but it is kind of interesting and comes to the same denominator. It's not very useful but it's obvious that the speed is higher on small timeframes.

For sure it has something, I do not know how to put it, a reflection of the dynamics. The structure of the movements is the same.

 
Valeriy Yastremskiy:

philosophical question. I have been trying to get the most out of it, but I've been trying to get the most out of it, and I've been trying to get the most out of it. I do not see any value, but it is obvious that the speed on small timeframes is higher.

For sure it has something, I do not know how to put it, a reflection of the dynamics, something like that. The structure of movements is the same.

You can fantasize as you like and about anything you like. You can even count how many times a truck driver went to take a piss per trip and even add this to the total distance and marvel - oh, it's become 30 metres longer.

 
Dmitry Fedoseev:

You can fantasise about anything you like. You can even count how many times a truck driver has taken a piss per trip and even add that to the total distance and marvel - oh, it's 30 metres longer.

I do NOT possess such directness of thought. I'm going the hard way. First I look at what I can measure, calculate and only then I think about what I can do with it.

Question, how easy is it to calculate to the left, from the current bar, the end of the corridor? The corridor can be in relative changes of difference of lows and highs, and the speed of lows and highs can be calculated, but it is difficult. I would like to make it simpler.

Minute with extremes.

 

Simplicity is a relative concept. Simple in what sense? Simplest in terms of implementation - just cycle through the last bars.

If simplest in terms of performance... there are a lot of questions. In this case, we should try to go from left to right, and to be on each bar only once. If it is at all possible. At least one should strive for it.

 
Dmitry Fedoseev:

Simplicity is a relative concept. Simple in what sense? Simplest in terms of implementation - just cycle through the last bars.

If simplest in terms of performance... there are a lot of questions. In this case, we should try to go from left to right, and to be on each bar only once. If it is at all possible. At least, we should strive for it.

It is clear that we should loop by bars or extrema. Extremes data is available as a bar number and price. What to put in the condition. The corridors may be of different width and slope. Of course, if it is less width, we will be in the corridor, but it is a deadlock solution. And I can't make a dynamic one. This is for the first calculation, to understand that there is a corridor for the current bar.

I don't think about performance and optimisation yet.

 
Valeriy Yastremskiy:

It is clear that it cycles through bars or extrema. Extremes data is in the form of bar number and price. What to put in the condition. The corridors may be of different width and slope. Of course, if it is less width, we will be in the corridor, but it is a deadlock solution. And I can't make a dynamic one. This is for the first calculation, to understand that there is a corridor for the current bar.

I am not thinking about performance and optimization yet.

We can calculate a linear regression for tops and bottoms. Distance between the bounds should be measured relative to the standard deviation.

You can estimate how flat the channel is by correlation of B coefficients of the upper and lower bounds. If such accuracy is required.

The slope of the channel can also be determined by the B coefficient.

...

Or, you can simply calculate the average of the difference of two neighboring fractals.

Reason: