1

I want to get coordinates of begin and end of a trendline(or other type of lines) that user draw on a chart.

I use OnChartEvent callback function. This function called when user do some changes on chart, like draw a trendline. When user draw a line, this callback called with value of id CHARTEVENT_OBJECT_CREATE, but other fields like lparam and dparam is zero and I don't know how to get coordinates of line when line created.

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
  switch(id)
  {
    case CHARTEVENT_OBJECT_CREATE :
      Print("Object Created, lparam: ", lparam, " dparam: ", dparam, " sparam: ", sparam);
      break;
  }
}

when I draw a line in result I see:

2019.08.02 12:48:38.480 example (EURUSD,H1) Object Created, lparam: 0 dparam: 0.0 sparam: H1 Trendline 33638

But I need to get x,y of line in my robot.

Mehrdad
  • 11
  • 3
  • 1
    The parameter you need is the name of the object, which is `sparam`. Now you can call `ObjectGetInteger(0,name,OBJPROP_TIME,1 or 2)` for time and `ObjectGetDouble(0,name,OBJPROP_PRICE,1 or 2)` for price where `name` is the name of the object (your `sparam`) and 1 or 2 is the id of the point (1 is start and 2 is end). – Daniel Kniaz Aug 02 '19 at 15:01
  • @DanielKniaz Thanks! It works for trendline, but why it doesn't work for vertical or horizontal line? for these type of lines all return value of these functions is zero. – Mehrdad Aug 02 '19 at 16:56
  • 1
    For vertical line, there is no price so `ObjectGetDouble()` will return 0 and for the horizontal line `ObjectGetInteger()` for time, will return 0, because it has no time co-ordinate on chart. Try the proper function with 0 as the co-ordinate(not 1 or 2) – TheLastStark Aug 02 '19 at 23:30
  • Thanks @TheLastStark, please write your answer and DanielKniaz at answer section. – Mehrdad Aug 03 '19 at 19:21

0 Answers0