amibroker

Home ▸ Knowledge Base

Getting X, Y co-ordinates of Study()

The following code sample shows how to get date/time (X co-ordinate) and value (Y co-ordinate) of starting and ending point of manually drawn study.

In order to use this sample you need to follow these steps:

  1. open Formula Editor,
  2. paste code below,
  3. press “Apply Indicator”,
  4. draw a trend line on this newly inserted chart pane,
  5. double-click on the trend line to bring up properties dialog
  6. select “SU” as study ID and press OK
Plot( C, "Price", colorBlack, styleCandle );

trendline = Study("SU", GetChartID() );

StartX = LastValue( ValueWhen( ExRem( trendline, 0 ), DateTime() ) );
EndX = LastValue( ValueWhen( trendline, DateTime() ) );
StartY = LastValue( ValueWhen( ExRem( trendline, 0 ), trendline ) );
EndY = LastValue( ValueWhen( trendline, trendline ) );

if( 
StartX == 0 )
  
Title = "No trend line drawn - please draw it and use 'SU' as study ID";
else
  
Title = "{{NAME}} {{DATE}}n"+
  
"Start at X = " + WriteVal( StartX, formatDateTime ) + ", Y = " + StartY +
  
"nEnd at X = " + WriteVal( EndX, formatDateTime ) + ", Y = " + EndY

Comments are closed.