Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 26

 
atztek:

Indicator buffers, as in the future the solution will not only be used for straight lines, but also for moving average and other types of lines.


Maybe you can specify what you want to end up with
 
Hello! If you can show me how to measure the slope of the trend and display the value of the slope
 
I want to measure the slope of the middle and display like -35 degrees
 
igor2013:
I want to measure the slope of the middle and display like -35 degrees

What is -35° on the graph? What if the scale changes?
 
Vinin:

Maybe you should specify what you want to end up with

In the example above, the line is drawn using the indicator buffer along the whole length of the history.
It should be limited only to the last 20 bars. I.e., when a new bar appears, the line is extended to the right and shortened to the left, so that its length is always equal to 20 bars.
 

I don't fully understand what I'm writing in the code, but I keep seeing the same number on the screen, although when I move the cursor to the line, I see the degrees change.

ObjectDelete("TremdLineAverage");
ObjectCreate("TremdLineAverage", OBJ_TRENDBYANGLE,0,0,0,0,0,0); // ------------------------- trendline 2 coordinates
ObjectSet ("TremdLineAverage", OBJPROP_WIDTH, HirinaUgolAverage); // ---------------------------------------- Width
ObjectSet ("TremdLineAverage", OBJPROP_COLOR, colUgolAverage); // --------------------------------------------- Color
ObjectSet ("TremdLineAverage", OBJPROP_TIME1 ,Time[1]); // ------------------------------- 1 time coordinate
ObjectSet ("TremdLineAverage", OBJPROP_TIME2 ,Time[0]); // ------------------------------- 1 time coordinate
ObjectSet ("TremdLineAverage", OBJPROP_PRICE1,UgolAverage1_1); // ----------------------------- 1 price coordinate
ObjectSet ("TremdLineAverage", OBJPROP_PRICE2,UgolAverage1_0); // ----------------------------- 2 price coordinate
ObjectSet ("TremdLineAverage", OBJPROP_RAY, 15); Ugol=15;

 
Up is 15 and down is -15.
 
ObjectDelete("TremdLineAverage");
ObjectCreate("TremdLineAverage", OBJ_TRENDBYANGLE,0,0,0,0,0,0); // ------------------------- trendline 2 coordinates
ObjectSet ("TremdLineAverage", OBJPROP_WIDTH, HirinaUgolAverage); // ---------------------------------------- Width
ObjectSet ("TremdLineAverage", OBJPROP_COLOR, colUgolAverage); // --------------------------------------------- Color
ObjectSet ("TremdLineAverage", OBJPROP_TIME1 ,Time[1]); // ------------------------------- 1 time coordinate
ObjectSet ("TremdLineAverage", OBJPROP_TIME2 ,Time[0]); // ------------------------------- 1 time coordinate
ObjectSet ("TremdLineAverage", OBJPROP_PRICE1,UgolAverage1_1); // ----------------------------- 1 price coordinate
ObjectSet ("TremdLineAverage", OBJPROP_PRICE2,UgolAverage1_0); // ----------------------------- 2 price coordinate
ObjectSet ("TremdLineAverage", OBJPROP_ANGLE, 15); Ugol=15;
 
Thank you.
 
igor2013:
Thank you for your feedback.

A ready-made function, try it out.

The SetTLineByAngle() function.

This function sets the OBJ_TRENDBYANGLE object by the slope angle in the current chart.
cl - Color of the TRENDBYANGLE object. Required parameter.
nm - Object name. When the default value is passed - "", the open time of the current bar is used as the name.
t1 - First coordinate of object setting time. Default value - 0 - open time of the tenth bar.
p1 - First coordinate of object setting price. Default value - 0 - minimum of the tenth bar.
t2 - Second coordinate of object setting time. Default value - 0 - open time of the current bar.
p2 - Second coordinate of object setting price. This parameter is a kind of switch. Its non-zero value equates this function to SetTLine(), i.e. a trend line will be drawn using the time/price coordinate pair, while the value of the slope angle of the trend line will be ignored. Default value - 0 - trend line construction by slope angle.
an - Slope angle in degrees. Default value - 0 - Horizontal line.
ry - Flag of the BOW property. The default value is False.
st - Line style. Valid values are STYLE_SOLID (default), STYLE_DASH, STYLE_DOT, STYLE_DASHDOT.
wd - Line width. Default value is 1.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Установка объекта OBJ_TRENDBYANGLE трендовая линия по углу     |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cl - цвет линии                                                         |
//|    nm - наименование               (  ""  - время открытия текущего бара)  |
//|    t1 - время открытия бара        (  0   - Time[10]                       |
//|    p1 - ценовой уровень            (  0   - Low[10])                       |
//|    t2 - время открытия бара        (  0   - время открытия текущего бара)  |
//|    p2 - ценовой уровень            (  0   - по углу)                       |
//|    an - угол                       (  0   - по умолчанию)                  |
//|    ry - луч                        (False - не луч)                        |
//|    st - стиль линии                (  0   - простая линия)                 |
//|    wd - ширина линии               (  1   - по умолчанию)                  |
//+----------------------------------------------------------------------------+
void SetTLineByAngle(color cl, string nm="",
              datetime t1=0, double p1=0, datetime t2=0, double p2=0,
              double an=0, bool ry=False, int st=0, int wd=1) {
  if (nm=="") nm=DoubleToStr(Time[0], 0);
  if (t1<=0) t1=Time[10];
  if (p1<=0) p1=Low[10];
  if (t2<=0) t2=Time[0];
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_TRENDBYANGLE, 0, 0,0);
  ObjectSet(nm, OBJPROP_TIME1 , t1);
  ObjectSet(nm, OBJPROP_PRICE1, p1);
  ObjectSet(nm, OBJPROP_TIME2 , t2);
  if (p2>0) ObjectSet(nm, OBJPROP_PRICE2, p2);
  else ObjectSet(nm, OBJPROP_ANGLE, an);
  ObjectSet(nm, OBJPROP_COLOR, cl);
  ObjectSet(nm, OBJPROP_RAY  , ry);
  ObjectSet(nm, OBJPROP_STYLE, st);
  ObjectSet(nm, OBJPROP_WIDTH, wd);
}
Reason: