Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1269

 
Kira27:

I've tried everything you suggested, twisted and turned, but it still paints lines in one colour in MT5. And in MT4 it paints lines normally, and without delays.

I guess I have not tried everything.

Alexey Viktorov:

It is very likely that after renaming an object it is still unavailable for reference to it. You can try putting ChartRedraw after renaming. If it doesn't help, we will have to build the sequence in some other way.

ps; Another option: first repaint with the name sparam and then rename it.

For some reason, event CHARTEVENT_OBJECT_CREATE counts immediately after the rat touches the chart, not after finishing creation of object. And prices of different ends of the fuse turn out to be the same. So you have to repaint after the object is created.

And one more remark: do you paint levels or main line of the wick?

Here are three variants:

One.

bool endCreate;
string newName;
/*******************Expert initialization function*******************/
int OnInit()
 {
  ChartSetInteger(ChartID(), CHART_EVENT_OBJECT_CREATE, true);
  return(INIT_SUCCEEDED);
 }/******************************************************************/

/************************Expert tick function************************/
void OnTick()
 {
  if(endCreate)
   {
    double   Level_0= ObjectGetDouble(0, newName, OBJPROP_PRICE, 0);
    double   Level_1= ObjectGetDouble(0, newName, OBJPROP_PRICE, 1);
    if(Level_0 > Level_1)
      ObjectSetInteger(0, newName, OBJPROP_LEVELCOLOR, 1, clrDeepSkyBlue);
    else
      ObjectSetInteger(0, newName, OBJPROP_LEVELCOLOR, 1, clrYellow);
    endCreate = false;
   }
 }/******************************************************************/

/***********************OnChartEvent function************************/
void OnChartEvent(const int id,         // идентификатор события
                  const long& lparam,   // параметр события типа long
                  const double& dparam, // параметр события типа double
                  const string& sparam  // параметр события типа string
                 )
 {
  if(id == CHARTEVENT_OBJECT_CREATE)
   {
    ulong timeCreate = ObjectGetInteger(0, sparam, OBJPROP_CREATETIME); //  получим время создания объекта
    newName = "Fibo "+string(timeCreate); //  сформируем новое имя объекта
    ObjectSetString(0, sparam, OBJPROP_NAME, newName);  //  переименуем объект
    endCreate = true;
   }
 }/******************************************************************/

Second.

/*******************Expert initialization function*******************/
int OnInit()
 {
  ChartSetInteger(ChartID(), CHART_EVENT_OBJECT_CREATE, true);
  return(INIT_SUCCEEDED);
 }/******************************************************************/

/************************Expert tick function************************/
void OnTick()
 {

 }/******************************************************************/

/***********************OnChartEvent function************************/
void OnChartEvent(const int id,         // идентификатор события
                  const long& lparam,   // параметр события типа long
                  const double& dparam, // параметр события типа double
                  const string& sparam  // параметр события типа string
                 )
 {
  string newName;  
  if(id == CHARTEVENT_OBJECT_CREATE)
   {
    ulong timeCreate = ObjectGetInteger(0, sparam, OBJPROP_CREATETIME); //  получим время создания объекта
    newName = "Fibo "+string(timeCreate); //  сформируем новое имя объекта
    ObjectSetString(0, sparam, OBJPROP_NAME, newName);  //  переименуем объект
   }
  if(id == CHARTEVENT_OBJECT_DRAG)
   {
    double   Level_0= ObjectGetDouble(0, newName, OBJPROP_PRICE, 0);
    double   Level_1= ObjectGetDouble(0, newName, OBJPROP_PRICE, 1);
    if(Level_0 > Level_1)
      ObjectSetInteger(0, newName, OBJPROP_LEVELCOLOR, 1, clrDeepSkyBlue);
    else
      ObjectSetInteger(0, newName, OBJPROP_LEVELCOLOR, 1, clrYellow);
   }
 }/******************************************************************/

Three.

/*******************Expert initialization function*******************/
int OnInit()
 {
  ChartSetInteger(ChartID(), CHART_EVENT_OBJECT_CREATE, true);
  return(INIT_SUCCEEDED);
 }/******************************************************************/

/************************Expert tick function************************/
void OnTick()
 {
 }/******************************************************************/

/***********************OnChartEvent function************************/
void OnChartEvent(const int id,         // идентификатор события
                  const long& lparam,   // параметр события типа long
                  const double& dparam, // параметр события типа double
                  const string& sparam  // параметр события типа string
                 )
 {
  if(id == CHARTEVENT_OBJECT_DRAG)
   {
    ulong timeCreate = ObjectGetInteger(0, sparam, OBJPROP_CREATETIME); //  получим время создания объекта
    string newName = "Fibo "+string(timeCreate); //  сформируем новое имя объекта
    ObjectSetString(0, sparam, OBJPROP_NAME, newName);  //  переименуем объект
    double   Level_0= ObjectGetDouble(0, newName, OBJPROP_PRICE, 0);
    double   Level_1= ObjectGetDouble(0, newName, OBJPROP_PRICE, 1);
    if(Level_0 > Level_1)
      ObjectSetInteger(0, newName, OBJPROP_LEVELCOLOR, 1, clrDeepSkyBlue);
    else
      ObjectSetInteger(0, newName, OBJPROP_LEVELCOLOR, 1, clrYellow);
   ChartRedraw(); 
  }
 }/******************************************************************/


 
SanAlex:

how to organise an algorithm in one indicator to take points and transfer them to another buffer.

- To draw the trend lines. (as on the picture)

-----------------------------------------

I tried everything with gut feeling, they are drawn but in strange places.

-----------------------------------------------------------------------------------------------------

I have attached the indicator, it works, but I cannot adjust these lines.

I cannot do it. Maybe someone can direct me to the articles about binding points of the trend line.

-- I cannot draw them, it is not clear at what points.

EURUSDH4

---------------------------------------------------------

something like that, maybe?

//--- найдем максимальное и минимальное значение графика
   double max_price=ChartGetDouble(0,CHART_PRICE_MAX);
   double min_price=ChartGetDouble(0,CHART_PRICE_MIN);
//--- определим шаг изменения цены и заполним массив
   double step=(max_price-min_price)/accuracy;
   for(int i=0;i<accuracy;i++)
      price[i]=min_price+i*step;
//--- определим точки для рисования линии
   int d1=InpDate1*(bars-1)/100;
   int p1=InpPrice1*(accuracy-1)/100;
//--- количество видимых баров в окне графика
   int bars=(int)ChartGetInteger(0,CHART_VISIBLE_BARS);
//--- размер массива price
   int accuracy=1000;
//--- массивы для хранения значений дат и цен, которые будут использованы
//--- для установки и изменения координат точек привязки линии
   datetime date[];
   double   price[];
//--- выделение памяти
   ArrayResize(date,bars);
   ArrayResize(price,accuracy);
//--- заполним массив дат
   ResetLastError();
   if(CopyTime(Symbol(),Period(),0,bars,date)==-1)
     {
      Print("Не удалось скопировать значения времени! Код ошибки = ",GetLastError());
      return;
     }
//--- заполним массив цен
//--- найдем максимальное и минимальное значение графика
   double max_price=ChartGetDouble(0,CHART_PRICE_MAX);
   double min_price=ChartGetDouble(0,CHART_PRICE_MIN);
//--- определим шаг изменения цены и заполним массив
   double step=(max_price-min_price)/accuracy;
   for(int i=0;i<accuracy;i++)
      price[i]=min_price+i*step;
//--- определим точки для рисования линии
   int d1=InpDate1*(bars-1)/100;
   int d2=InpDate2*(bars-1)/100;
   int p1=InpPrice1*(accuracy-1)/100;
   int p2=InpPrice2*(accuracy-1)/100;
//--- создадим линию тренда
   if(!TrendCreate(0,InpName,0,date[d1],price[p1],date[d2],price[p2],InpColor,InpStyle,
      InpWidth,InpBack,InpSelection,InpRayLeft,InpRayRight,InpHidden,InpZOrder))
     {
      return;
     }



-------------------

am i on the right track ???

Files:
2.mq5  82 kb
 
SanAlex:

Maybe someone can direct me to articles about trendline points.

-- all I can do now is draw them, it's not clear at which points.

---------------------------------------------------------

something like that, maybe?

-------------------

am i on the right track ???

The trend lines are drawn at 2 points, it's either the price data or the data of another indicator, the example of drawing by fractals, which, by the way, is familiar to you)

https://www.mql5.com/ru/code/29210

Line through two fractals
Line through two fractals
  • www.mql5.com
cm BASKET Советник управляющий счетом. Показывает какие пары инструментов сейчас торгуются на данном счете. Показывает прибыль полученную по каждой паре за определенное время. Помогает переключаться между множества открытых окон... Virtual Trailing Stop 2
 
VVT:

Trend lines are drawn at 2 points, this is either price data or data from another indicator, an example of drawing by fractals, which, by the way, is familiar to you)

https://www.mql5.com/ru/code/29210

I wanted to do it with one indicator, but it didn't work.

- I had to do it with two indicators.

That's what I did.

GBPUSDM30 GOTOV

---------------------------

I forgot to say thank you! - Thank you!!!

 
SanAlex:

I wanted to do it in one Indicator, but it didn't work, but I've done it in this one, which you suggested.

- so I had to do it with two Indicators.

That's how it worked.

---------------------------

I forgot to say thank you! - Thank you!!!

Well combine them, you can create many different objects in one indicator)

 
Alexey Viktorov:

Apparently I haven't tried everything.

For some reason, the CHARTEVENT_OBJECT_CREATE event counts immediately after the rat touches the chart, not after the end of object creation. And prices of different ends of the fuse turn out to be the same. So, we have to repaint after the object has been created.


How have you determined this? Logically?

And another remark: do you paint levels or the main line of the fib?


I tried repainting trend lines in different variants))))

Here are three variants:

One.

Second.

The Third.


Thank you very much for those!!! I may learn to think logically, based on your examples))))

How long have you been in trading? I've been doing it for 12 years now)))

 
Kira27:

Thank you very much for the options!!! I'll use your examples and learn to think logically))))

I mean, how long have you been trading? I've been doing it for 12 years now.)

I'm not always so "kind". I'm not always so "kind", only during attacks... So there's not much to learn from my examples. I'm in trading almost as long.

 
Alexey Viktorov:

I'm not always so "kind". Only during attacks... So there's not much to learn from my examples. I'm about the same in trading.

I don't know, I'm learning the methods and techniques of programming better by examples. I wish MQL5 had such a tutorial like MQL4 where the robot is explained step by step using included files.

 
Alexey Viktorov:

I am in trading for almost as long.

So you already know the essence of market fluctuations? It seems to me that I have already learned)))) I just need to ask it, because I can work with it for a certain time, and then I snap and create a mess)))))) But now I understand any asset)))) I especially like the S&P, it is technical and dynamic))

 
VVT:

Well, combine them, you can create many different objects in one indicator)

I wanted to do it that way. I've been trying to do it for a week now, but it just wouldn't work.

- It seems to be better in the second indicator - you cannot see past points and the lines themselves, there are only those points and levels that are used to determine entries into the market.

----------------

these two indicators are one (this is my draft - I didn't change the names of 4 indicators in it)