- get current X position of mouse pointer

(AmiBroker 4.80)

SYNTAX GetCursorXPosition( mode = 0 )
FUNCTION Retrieves current mouse pointer X co-ordinate (i.e. datetime of bar under the mouse pointer). The functions now (v5.10 and up) by default return NULL (empty value) if mouse is OUTSIDE the current window


  • mode = -1 - (old compatibility mode) - x - value gives X-coordinate in DateTime format. y - value gives PRICE. Values are reported no matter where is the mouse (i.e. may refer to window different than current if mouse is outside current window).
  • mode = 0 - (default) x - value gives X-coordinate in DateTime format. y - value gives PRICE. Returns NULL if mouse is outside current window
  • mode = 1 - x, y - are mouse coordinates expressed in screen PIXELS. Returns NULL if mouse is outside current window

Values returned are equal to those visible in the status bar, and these functions require status bar to be visible. Returned values represent cursor position at the formula execution time (or few milliseconds before it) and accurracy is subject to pixel resolution of the screen (first cursor position is read in screen pixels (integer) and then converted to actual value therefore for example when screen resolution is 1024x768 maximum obtainable resolution in X direction is 0.1% and in Y direction 0.13%), also X values are snap to datetime of nearest data bar.

It only makes sense to use these functions in indicator/interpretation code.

Using them in AA window may yield random values.GetCursorXPosition() function returns X position in DateTime format (the same as used by DateTime() function). You can convert it to string using DateTimeToStr() function.GetCursorYPosition() returns Y position (as displayed in Y axis of the chart).

EXAMPLE ToolTip = "X=" + DateTimeToStr( GetCursorXPosition() ) +
"nY=" + GetCursorYPosition();
SEE ALSO GetCursorYPosition() function , GetCursorMouseButtons() function


The GetCursorXPosition function is used in the following formulas in AFL on-line library:

More information:

See updated/extended version on-line.