How do I learn to create graphical objects? MQL4. - page 3

 
Integer:

If the indicator creates graphical objects and then gets their parameters, no.

But it is still easier to solve everything through the use of an indicator. Calculations are performed in the indicator and their results are displayed via indicator buffers.

There is one more alternative. Create global variables with parameters of the line instead of lines, but in this case, the function GetValueByShift() will not work, you must write its analog.

I see. But how to draw a trend line in an indicator without any graphic drawing?

Two bar indexes are known, they should be connected with a line and drawn to the right.

 
forexman77:

I see. But how can I draw a trend line in the indicator without any graphical drawings?

Two bar indexes are known, they should be connected by a line and drawn to the right.

I had such an indicator in my code base. I do not have it now.

We should use calculations. Knowing coordinates of two points we can simply calculate coordinates of the third one.

 
Integer:

I used to have such an indicator in my codebase. Now it's gone, gone.

You have to use calculations to do everything. Knowing the coordinates of two points, you can simply calculate the coordinates of the third.

Where to find a formula for this calculation?

In general, it looks a bit nouveau. The terminal has all sorts of channels, fibos and other geometric indices, but they are useless in the tester.

 
forexman77:

Where can I find the formula for this calculation?

In general, it's kind of nouveau riche. There are a lot of channels, Fibos and other geometric indices in the terminal, but they are useless in the tester.

double y3(double x1,double y1,double x2,double y2,double x3){
   return(y1+(x3-x1)*(y2-y1)/(x2-x1));
}

x1, x2 - bar numbers. y1, y2 - price values. x3 - number of bar for which the calculation is conducted.

 
Integer:

x1, x2 - bar numbers. y1, y2 - price values. x3 - number of bar for which the calculation is performed.

Ok. Thank you. I will keep digging.
 
Integer:

x1, x2 - bar numbers. y1, y2 - price values. x3 - number of bar for which the calculation is performed.

Made indicator based on the calculations, readings are the same as for the indicator on the graphical objects.

Optimization is going on. The only problem is that trades are not opened correctly.

When I apply the indicator to the chart the line is flat at first, but then it becomes as it should be and stays like that when I place it on a new tick.

 
forexman77:

Made an indicator based on the calculations, the readings are the same as the indicator on the graphical objects.

Optimisation is going on. The only problem is that trades are not opened correctly.

When I apply the indicator to the chart the line is flat at first, and then with a new tick it becomes as it should be and stays like that.

Try to test it in visual mode. Using print, look for the difference.
 
Integer:
Try to test in visual mode. Using print, comment, look for the difference.

The visual mode will not help. I was able to make the indicator show only the current pattern.

The indicator itself prints the value of the first index (MQL4), the first print comes out with an incorrect value, and the others are correct on new ticks.

If you don't mind looking at the code, I sent it to you in your personal message.

 

Anyway, I transferred all the trendline calculations to the EA. It seems to be correct.

I cannot make an indicator, that would show on the whole range of the line. I do not have enough experience.

I actually need an indicator to visually see that trades are opened correctly.

I have decided to use graphical objects for visualization.

The problem is the error 4200 (the object already exists).

I tried to give a new name to the object each time. Same error.

Is it possible to call multiple objects? If so, how can I trim unnecessary parts of the ray?

         long   chart_ID=0;        // ID графика
         string name=TimeToStr(Time[0]);
         int    sub_window=0;      // номер подокна
         //--- сбросим значение ошибки
         ResetLastError();
         //--- создадим трендовую линию по заданным координатам
         if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,Time[minbar],Low[minbar],Time[IPMIN],Low[IPMIN]))
           {
            Print(__FUNCTION__,
                  ": не удалось создать линию тренда! Код ошибки = ",GetLastError());
            return(0);
           }
         ObjectSet("TrendLine",OBJPROP_TIME1,Time[minbar]);
         ObjectSet("TrendLine",OBJPROP_PRICE1,Low[minbar]);
         ObjectSet("TrendLine",OBJPROP_TIME2,Time[IPMIN]);
         ObjectSet("TrendLine",OBJPROP_PRICE2,Low[IPMIN]);

 
forexman77:

Anyway, I transferred all the trendline calculations to the EA. It seems to be correct.

I cannot make an indicator, that would show on the whole range of the line. I do not have enough experience.

I actually need an indicator to visually see that trades are opened correctly.

I have decided to use graphical objects for visualization.

The problem is the error 4200 (the object already exists).

I tried to give a new name to the object each time. Same error.

Is it possible to call multiple objects? If so, how can I trim unnecessary parts of a ray?

Before creation, you can check if the object exists, function ObjectFind(). You don't have to do anything, it exists and it's OK, it's not a bad error.

A set of objects. You can add the bar time to the object name, it will have a unique name.

Trim the beam. Property ObjectSet(Name,OBJPROP_RAY,false);

Reason: