Weird of OnChartEvent Function

 

Maybe I am confused on this.

However, I found that OnChartEvent provide four inputs as you can see from code.

If lparam and dparam are respectivley x and y coordinate of object in chart, then how come these two are different variable types ?

Like x being long but y being double seems weired. Instead, both x and y could become long or both x and y could become double.

Is there any reason for these two variables (i.e. lparam and dparam) to be different variable type ?



void OnChartEvent(const int id, 
                  const long &lparam, 
                  const double &dparam, 
                  const string &sparam) 
  { 
//--- keypress 
   if(id==CHARTEVENT_KEYDOWN) 
     { 
      switch((int)lparam) 
        { 
         case KEY_NUMLOCK_LEFT:  Print("Pressed KEY_NUMLOCK_LEFT");   break; 
         case KEY_LEFT:          Print("Pressed KEY_LEFT");           break; 
         case KEY_NUMLOCK_UP:    Print("Pressed KEY_NUMLOCK_UP");     break; 
         case KEY_UP:            Print("Pressed KEY_UP");             break; 
         case KEY_NUMLOCK_RIGHT: Print("Pressed KEY_NUMLOCK_RIGHT");  break; 
         case KEY_RIGHT:         Print("Pressed KEY_RIGHT");          break; 
         case KEY_NUMLOCK_DOWN:  Print("Pressed KEY_NUMLOCK_DOWN");   break; 
         case KEY_DOWN:          Print("Pressed KEY_DOWN");           break; 
         case KEY_NUMPAD_5:      Print("Pressed KEY_NUMPAD_5");       break; 
         case KEY_NUMLOCK_5:     Print("Pressed KEY_NUMLOCK_5");      break; 
         default:                Print("Pressed unlisted key"); 
        } 
     } 
//--- left-clicking on a chart 
   if(id==CHARTEVENT_CLICK) 
      Print("Mouse click coordinates on a chart: x = ",lparam,"  y = ",dparam); 
//--- clicking on a graphical object 
   if(id==CHARTEVENT_OBJECT_CLICK) 
      Print("Clicking a mouse button on an object named '"+sparam+"'"); 
 
Young Ho Seo: If lparam and dparam are respectivley x and y coordinate of object in chart, then how come these two are different variable types ?

It's a generic interface: a long, a double, and a string.

For a click you need two ints (X and Y,) and a long and double can hold them just fine. Casting both to an int when passing to ChartXYToTimePrice works just fine.

If you needed to send a double via a custom event you can. Would it bother you less if the interface was int 1, int 2, unused double and a string?

Reason: