ESPL: AlertEvent( eSave )

Q:  Is there a way to differentiate between the 3 different events that fire the AlertEvent(eSave) processing?

The 3 possible events are:

a) the user closes the chart.
b) the Timeframe button is used to change the chart but the chart form is the same.
c) the data for the chart is refreshed.

In the first two cases, I want to perform my CloseChart processing, i.e. save the chart data to file and close the MainForm instance.   In the second case, a new MainForm instance will be created by the subsequent eLoad event.

In the third case, it is possible that new bars have been added before the barend. In this case, the appropriate action is to reinitialize so that processing begins from the start but I don’t want to save the data to file and close the instance.

A:   Ensign 10 ESPL splits out all the places the AlertEvent(eSave) is called and identifies the procedure in the IT variable’s string.   The possible places for saving chart datafile are many. The IT text will have the time, then Save and a word for the procedure, and then the symbol. You can use

if pos('Save Close',IT)>0 then begin 
  {this is case a) for chart close} 

Other choices for xxx in ‘Save xxx’ are:   Roll, Build, Objects, Open, Close, Rebuild, Template, Property, Timer, Load, Refresh, ESPL 1, ESPL 2, ESPL 3, Update, and Time.

The 3 events you asked about would be: 

a) Save Close
b) Save Time
c) Save Refresh

Of course, put in some logging of the IT value to the output window and verify the content of IT for the various actions you take and the program exercises and skip those that do not affect your system design.   

Example test code:

  if ESPL=0 then AlertEvent(eSave, 600);
  if ESPL=600 then writeln( IT );

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.

  bar_1, bar_2: integer;
  if ESPL = 1 then begin
    bar_1 := 5;
    bar_2 := 10;

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

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

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.

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

Import Ticker Symbols

Q:  How can I transfer a list of ticker symbols to Ensign 10.

A:  If you want a list of ticker symbols to be a list your data feed follows, save the ASCII file with the name Symbol1.dat in the /Feeds/vendor folder. Here is the example for the eSignal vendor and its folder is ES under /Feeds. 

Then the program will watch this list of symbols and populate the ESignal quote page with live updates.

If you want a custom quote page, then the ascii text file with the symbols is like this example.  The folder is Quofile and the text file has a .dat suffix. The list of symbols have a single character prefix for the vendor, and they are in the same list order as the Feeds on Setup Feeds. The list starts with A for FXCM vendor and B for Interactive Broker vendor feed, etc.

A Spreadsheet cannot import your ticker list. However you could use ESPL to read your file and then poke the cells on the spread sheet with the strings of your ticker list.

Code example would be something like this.

  sList.LoadFromFile(sPath + 'yourfilename.dat');
  for row := 1 to pred(sList.count) do
    SetCell(2, row, sList[row], clWhite); {1st param is column}

ESPL: ToolBar and ToolButton

The Ensign 10 ESPL IDE has received significant additions..

  1. Added TStringGrid component
  2. Added TToolBar component
  3. Added TToolButton component
  4. Added TPaintBox component
  5. Added StrUtils library
  6. Exposed 5 Ensign 10 TImageLists named:
    imgList16, imgList24, imgList32, imgMarker, and imgLine

This example shows a form using TToolBar, TToolButton and imgMarker.

At design time, a TToolBar object was added to the form and aligned for alTop. Then four TToolButtons were added to to the ToolBar.

At run time, the imgMarker list of images from Ensign 10 is assigned to the ToolBar images property, and the ImageIndex properties assigned for the ToolButtons.  See the ESPL documentation for the Marker indexes in the Appendix.

Of course, a TImageList can be added to the form, and one’s own images can be added to the component.  At design time, the TToolBar images property can be set to the TImageList on the form, and the ToolButton imageindex property set.

The click event for each of the toolbuttons can be written to perform a desired action.

ESPL: 2-Dimensional Arrays

Q:  How do I declare a 2-dimensional dynamic array in ESPL?   A dynamic array is one where I don’t know the bounds at compile time.  It grows dynamically as new array elements are added.

A:  ESPL supports a variety of arrays, each with different characteristics.  Let me summarize the choices.

  • Multi-diminsional arrays are declared with the [ ] construct at compile time.  See the ESPL manual, topic ‘Arrays’ on page 29.
  • TArrays are single dimensional and semi-automatic in their dimension.
  • Variant arrays can be dimensioned and redimensioned, but they also are single dimensional.
  • TLists and TStringLists are single dimension.  They dynamically grow as elements are added.
  • The TStringGrid object is 2-dimensional with RowCount and ColCount properties.  And these properties can be set at run time.   The values are written and read in the string grid cells.   See this example.

ESPL: Study Rising Falling Flag

The following ESPL example will plot GREEN circles when the Study Average is rising, and RED circles when the Study Average is falling.   This chart has an Ergodic study and the ESPL study applied.


The GetStudy statement references for 1st line, 2nd line, 3rd line, and 4th line refer to the various Lines that can be plotted by a Study.

  • The 1st line is the main study line.
  • The 2nd line is most often the Average of the main study line.
  • Sometimes there isn’t a 3rd line for a study….sometimes there is.
  • The 4th line is most often the Spread line values.

The example below is testing the GetStudy 15 value…. (Is the 2nd line Rising?)

   Classes, Graphics, Controls, Forms, Dialogs;
procedure CheckErg;
   i, iHandle:integer;
   iHandle := FindStudy(eERG); 
   for i := BarBegin to BarEnd do 
      if GetStudy(iHandle,15,i) then 
   if ESPL=100 then CheckErg;

Click ESPL button 100 to apply and run the ESPL study on the chart.

ESPL: Andrews Pitchfork Parameters

Q:  I’d like to retrieve, using GetStudy() I presume, parameters related to an Andrew’s Pitchfork which is already drawn on a Chart.  I have no problem getting the handle of the Fork, but I can’t figure out what parameter numbers to use.  I see there is supposed to be a block of parameters for Line Colors, from 300 to 310.  Is that where I’d get the line colors?

In what format would that color be returned?  I did get a large integer returned from parameter 300.  Another item I want to retrieve is the Fork Variation.  That is a string in a combo box with the choices, Standard, Schiff and Modified Schiff, as I recall.  Also, if possible I’d like to get the tab selected for the drawing of the object, if that is available. 
A:  Yes, 300 through 310 are the selection parameters to use to get the line colors.   Here is my test script for your review.
The example writes the values returned by GetStudy for 300 to 315.  300 returned the cyan color, and so did 301 in the example.  The color Red is easy to spot as that has a color value of 255, and is returned by 303 and 305, etc.   The colors are integers and contain the RGB bytes, with Red being the low order byte.  Hence, the value 255 is just the color Red at its maximum brightness.
The fork variations selection value is 209.  GetStudy(handle,209);    First selection of Andrews would return 0.  Schiff would return 1.
The TAB selected will be returned using selection 956.   GetStudy(handle,956);    956 will work for all studies and tools to return the tab and the values will be 0 through 14.
Q: Thanks.  I am totally satisfied with what you’ve provided.  Is there an easy way to get the name of the Tab rather than just the number?
A:  Yes, use 957 as the selection value to work with the tab’s text name.  Example: 

   handle := FindStudy(eAndrews);
   writeln( GetStudy(handle, 956) ) ;            // write the current tab number
   writeln( GetStudy(handle, 957) );             // write out the tab’s text name
   SetStudy( handle, 957, ‘NewName’ );      // change the current tab’s text name

ESPL: Creating ESPL DLLs

The Delphi used in this article is Embarcadero Delphi 2010.  Any compiler and language can be used to make a DLL as long as the output is in flat “C”-type format (eg. No Objects, Classes or Strings, being passed as parameters or returned).

Step 1:  Make the DLL in Delphi

Click File | New | Other | Dynamic Link Library

This is the code for a DLL named ESPL_DLL.

library ESPL_DLL;

{$R *.res}

function ESPL_Sum(AValue1: real; AValue2: real): real; stdcall;
  result := AValue1 + AValue2;

function ESPL_Max(AValue1: real; AValue2: real): real; stdcall;
  if (AValue1 >= AValue2) then
    result := AValue1
    result := AValue2;



Step 2:  Make the ESPL Form

Here is the form in Ensign 10’s ESPL IDE, with 2 buttons and a memo component.

Step 3:  Add the source code

{$FORM TfrmMain, Main.sfm}

uses  Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;


function ESPL_Sum(AValue1: real; AValue2: real): real; stdcall; external ‘ESPL_DLL.dll’;

function ESPL_Max(AValue1: real; AValue2: real): real; stdcall; external ‘ESPL_DLL.dll’;

procedure btnSumClick(Sender: TObject);
var rValue: real;
rValue := ESPL_Sum(3.5, 7.2);

procedure btnMaxClick(Sender: TObject);
var rValue: real;
  rValue := ESPL_Max(8.7, 10.1);

procedure frmMainShow(Sender: TObject);


Step 4:  Run the program script

  1. Click the ESPL Run button
  2. Click the Sum button
  3. Click the Max button

ESPL: Security Name on Chart

Q:  I would like to see the security name at the top left of the chart.  I know it shows in the title, but that is too small.  Can this be done and automated to show in a bigger format?

A:  This ESPL script will add the security name to the chart which has focus.  Click the ESPL button #9 to add a note object containing the security name.   Here is the ESPL script which automates the process.

  if ESPL = 9 then begin
    FindWindow( eChart);
    sSymbol := GetVariable( eSymbol );
    Find( eIQFeed, sSymbol );
    sName := GetData( eName );
    AddNote( sName, 4, -10, -10, 0 );

The FindWindow will locate the chart which has focus.
GetVariable will read the chart’s symbol.
Find will locate the quote record for the symbol.
GetData will read the security name such as is provided by IQFeed.
AddNote will create an object to be owned by the chart.

The 1st parameter is the text string to show.
The 2nd parameter is the tab number used for  properties. Go set up tab 4 to have Pinned unchecked, and select the color and font size for the note.
The 3rd parameter is the horizontal location.  A negative number represents the pixel position on the chart from the left edge. This starts the note at pixel 10.
The 4th parameter is the vertical location.  A negative number represents the vertical pixel position on the chart from the top edge. The example puts the note down 10 pixels.
The 5th parameter is the window location, and 0 selects the chart.

ESPL: Sum Volume for a Swing

Q:  How can I determine the volume for a swing, or the volume between two bars on the chart?

A:  I will illustrate 3 ways in my answer.  The first way is to use the Pesavento Patterns study and change the Marker to the VOL selection, which will sum the volume for a swing.  This tool is automatic in picking the swing points.

The 2nd suggestion is to put on a Draw Line with the same VOL marker and the total volume in the bars spanned by the draw line will be printed at the end of the line.  See an example of the draw line’s volume in the next image.

The 3rd suggestion is to use the ESPL programming language, and sum the volume in a loop between two index locations on the chart.  The example will use two index points from the Pesavento Patterns study.  Any two index points could be used.

Line 12 finds the chart.  Line 13 finds the Pesavento Patterns study.  Lines 14 and 15 find the two indexes for the prior swing.   Line 16 writes the total volume to the output window.

The total volume is summed by the Function SumVolume which loops through the bars between the two indexes passed as parameters and adds each bar’s volume to the total.