ESPL: Print Message on a Chart

This article shows various ways to print a message on a chart using ESPL.

1) The following sample code will print bar values on a chart.

var
  bar_1, bar_2: integer;
begin
  if ESPL = 1 then begin
    bar_1 := 5;
    bar_2 := 10;
    FindWindow(eChart);
    TextOut(20,20,IntToStr(bar_1));
    TextOut(30,20,IntToStr(bar_2));
  end;
end;

2) The following sample code uses ADDNOTE to place a note on a chart.

begin
  if ESPL = 1 then begin
    FindWindow(eChart);  // Find the chart with focus
    AddNote( 'Buy the Market', 4, -10, -10, 0 );
  end;
end;

3) The following example, adds a note to a chart, then changes the Note text after 5 seconds.  Keep track of the HANDLE of the note, in order to change it later.  The ESPL documentation for SetStudy shows that the NOTE text is stored in SELECT value 30.

var
  iNoteHandle:integer;
begin
  if ESPL = 1 then begin
    FindWindow(eChart);  // Find the chart with focus
    iNoteHandle := AddNote( 'Buy the Market', 4, -10, -10, 0 );
    Pause(5);
    Beep;
    SetStudy(iNoteHandle,30,'Sell the Market');
    ChartRefresh(True);
  end;
end;