Advertisement
Guest User

chartxytotimeprice

a guest
Feb 15th, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. // please run on build610
  2.  
  3. #property strict
  4.  
  5. int OnInit()
  6. {
  7.     ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, true);
  8.     // enable tracking of mouse events
  9.     ChartRedraw();
  10.  
  11.     return 0;
  12. }
  13.  
  14. void OnDeinit(const int reason)
  15. {
  16.     if (reason == REASON_REMOVE || reason == REASON_RECOMPILE) {
  17.         ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, false);
  18.         ChartRedraw();
  19.     }
  20. }
  21.  
  22. void OnChartEvent(const int id,
  23.                   const long &lparam,    // x
  24.                   const double &dparam,  // y
  25.                   const string &sparam)  // mouse_up, mouse_down (MOUSE_MOVE
  26. {
  27.     int      x      = (int)lparam;
  28.     int      y      = (int)dparam;
  29.     int      window = WRONG_VALUE;
  30.     datetime time   = NULL;
  31.     double   price  = 0.0;
  32.  
  33.     if (id == CHARTEVENT_MOUSE_MOVE) {
  34.         ObjectSetInteger(0, "0", OBJPROP_CORNER, CORNER_LEFT_LOWER);
  35.         if (ChartXYToTimePrice(0, x, y + 1, window, time, price)) {
  36.             Comment("x: ", x, "\n",  // 最小値が 3 なのは,チャートの枠内だけに
  37.                     "y: ", y, "\n",  // 注目してる関数だから
  38.                     "time: ", time, "\n",
  39.                     "price: ", DoubleToString(price, _Digits));
  40.         }
  41.  
  42.         return;
  43.     }
  44.  
  45.     ChartRedraw();
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement