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

 
barabashkakvn:
If you know the time and dates of your points, you only need to callbool TrendCreate()

Thanks for the advice. It turned out to be easier than that.

I did it this way:

#property strict
#property script_show_inputs

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
  long   chart_ID=0;        // ID графика
  string name="TrendLine";  // имя линии
  int    sub_window=0;      // номер подокна
//--- сбросим значение ошибки
   ResetLastError();
//--- создадим трендовую линию по заданным координатам
   if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,Time[41],1.0656,Time[65],1.0494))
     {
      Print(__FUNCTION__,
            ": не удалось создать линию тренда! Код ошибки = ",GetLastError());
      return;
     }
   
  }
//+------------------------------------------------------------------+

P.S. One thing I can't understand is why the numbers in the example are chosen like that:

InpDate1=35;        
InpPrice1=60;        
InpDate2=65;        
InpPrice2=40; 

From them the trend line goes somewhere in the middle of the range.

 
Now the next problem to solve is how to continue the line to the right and get the value of the line in the EA?
 
forexman77:

...

From them, the trend line is put somewhere in the middle of the range.

So, it is just a script the main task of which is to demonstrate how to create and work with OBJ_TREND object. The figures were taken for clarity.
 
forexman77:
Now the next problem to solve is how to continue the line to the right and get the value of the line in the EA?

The script code has it all:

//+------------------------------------------------------------------+
//| Создает линию тренда по заданным координатам                     |
//+------------------------------------------------------------------+
bool TrendCreate(const long            chart_ID=0,        // ID графика
.
.
.
//--- включим (true) или отключим (false) режим продолжения отображения линии влево
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_LEFT,ray_left);
//--- включим (true) или отключим (false) режим продолжения отображения линии вправо
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);
.
.
.
 
barabashkakvn:

The script code has it all:

1.When called from the tester trades are opened. If I run optimization there are zeros everywhere. When I launch any optimization run, the deals are there. What to do?

2. How can I make a line be saved if a deal has occurred (on each deal), and if not, it is deleted?

  long   chart_ID=0;        // ID графика
  string name="TrendLine";  // имя линии
  int    sub_window=0;      // номер подокна
  ObjectDelete(chart_ID,name);
//--- сбросим значение ошибки
   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]);

   if (IPMIN!=0){ double uroven= ObjectGetValueByTime(chart_ID,name,Time[1],sub_window);}
   
}
Print("uroven=",uroven);
if (Time[0] > b && Close[1] < uroven){Opn_B=true;}
 
You need to control the trades yourself. But for each trade to have its own line, you need to give each line a unique name when you create it.
 
barabashkakvn:
You need to control the trades yourself. But for each trade to have its own line, you need to give each line a unique name when you create it.
How? Can you give an example?
 
forexman77:
How? Can I give you an example?
Help who has examples, please.
 

Graphic objects during testing

During visualization testing, the Expert Advisor interacts with the real chart. In normal testing, without visualization, the Expert Advisor operates with a "virtual" chart that is not rendered; in this case, some subtleties are possible. Graphical objects are not supported when the tester is in optimisation mode.

Two days to study, and it turns out it's impossible to perform optimization.

I wonder if I create an indicator. Will I be able to get the line value in my Expert Advisor through it?

Who has to say what? Perhaps, who has already studied this question?

 
forexman77:

...

I wonder if I could make an indicator? Would I be able to get the value of the line in the EA through it?

...

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

But anyway, it is easier to solve everything using the indicator. Calculations are performed in the indicator and their results are displayed through indicator buffers.

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