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 );

Dollar Delta Marker

Q:  I was testing the dollar delta feature in Ensign 10 on some commodities that are not priced with decimals – specifically soybeans. When I use the dollar delta feature on bean contracts it does not display the dollar amount clearly.

A:  The answer is right. Just need to know how to interpret it.  Dollar Delta will show the price change points multiplied by the leverage to give the change in dollars.

In this example, the 2 end points of the line are 10 cents apart, and at $50 per cent, the answer is $500.

The scale format for these grains is 8ths, meaning the last digit of the price is the fraction cent. So the last digit of 2 is 2/8th, and 4 is 4/8ths. The answer from the delta dollar is in the same price format, meaning the last digit is the fractional part. 5000 is 500 and 0/8ths, ie $500.00

Chart Scanner on Bollinger Bands

Q:  I want the scanner to tell me which symbols on the quote list has price above/below the first band in a 20 day BB study (above +1 Std , below -1 Std).

A:  This example will walk you through the steps.

1)  Create a quote page of symbols to scan.   In this example the vendor’s symbol list is used, but a custom list could have been used.  Here is the vendor list and quote page.

2) Open a daily chart for each symbol to verify the chart is complete. Refreshed the chart if needed. Charts can then be closed.

3) On one chart, put on a Bollinger band and configure it for a 20 Average and 1 multiplier. Now add a DYO configured this way to test for Close exceeding either upper or lower bands.

Variable [8] has the upper band value, [9] has the lower band value, and [3] is the flag that is True when close exceeds either band.  These 2 studies are then saved as a template named BollingerTest.

4) Open Setup | Chart Scanner, and configure the form like this.

Name this setup Bollinger and use the Save button to remember these settings after filling in the form. That way it can be retrieved.

The box to use the Vendor quote page for eSignal is checked. Load each chart with the BollingerTest template. Chart time frame is Daily.

The Criteria for adding to the report is when Variable [3] is True.  [3] was set by the DYO.

The report will have 4 columns with labels Symbol, Close, Upper, Lower. The format is caption = value.  [$S] is the token for showing the chart symbol. [$C] is the token for the Close price.  [8] and [9] are variables populated by the DYO for the upper and lower Bollinger bands.

5)  Now, click the Run Scanner button and get a report of results like this.

Of the symbols on the quote list, 7 triggered the criteria. AAPL Close is 587.45 which exceeded the Upper Bollinger band.   Here is the AAPL chart as confirmation.

The price has moved a few cents from when the scan was run and the chart image captured for this example.

IB Gateway Feed

Ensign 10 and Ensign Windows can receive the Interactive Broker feed through the IB Gateway or through the IB Trader Workstation.   The advantage of the IB Gateway is it does not have the overhead of showing a quote page or trade platform.   Also, the IB Gateway is not required to be shut down each day whereas TWS does shut down.

Get the IB Gateway from the IB web site using this link.  It installs with the TWS.

Gateway can be found in the Start menu, All Programs | Interactive Brokers folder.  Drag the Gateway icon to the desktop so there is a desktop link named IB Gateway.

For Ensign Windows, run Gateway and manually connect.   Ensign Windows will find Gateway running and connect to it to receive the feed from Interactive Brokers.

For Ensign 10, check the box Use IB Gateway instead of TWS found on the Setup | Feeds form.  Ensign 10 can run IB Gateway and accomplish the login process.

 IB Gateway uses the same Username and Password as is used by TWS.   Note in the above example that the Reconnect time has been blanked out which is appropriate since Gateway remains running and does not need to be rerun by Ensign each day.

To log in to IB Gateway the 1st time, you need to change the bullet selection to IB API.  Then enter your Username and Password.

You must change the port setting that Gateway listens on for Ensign to connect to it.   In Gateway, click menu Configure | Settings | API | Settings and change the port to 7496.  And create the entry in Trusted IP Addresses for  as shown here.

Study Values in Sections

Q:  How can I have a DYO display study values at the bottom of the chart?  Basically what I want to do is instead of having the show values window appear on the left side of the chart I would like the values to be displayed in the DYO field sections of their respective DYO’s to save screen real estate.

A:   This DYO will show current study values in sections at the bottom of the chart. These are current values that will update tick by tick. They are not study values aligned for where the mouse is.

A – Read a study value and show the label with a blue background and white font. The label has |1| to indicate the location is the 1st section.

B – Read another study value and show with a brown background. The label has |2| to locate the text in the 2nd section.   [B.2] is the value from Row B formatted to show 2 decimals.

A DYO like this can show values in 7 different sections that exist at the bottom of a chart. Use the section tags |1| through |7|.

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}

Where Files are Saved

Q:  There needs to be a better explanation about how to save charts, save layouts, and using the backup folder.

A:  Although the answer and examples will use Ensign 10 folders and paths, the information is applicable to Ensign Windows.

Charts:  When a chart is opened from the charts form or from a quote page, the process reads the chart’s property file (if one exits), loads the chart’s data file and brings the bars on the chart current by extracting from database files, and then dresses the chart with study and draw tool objects.   If a chart is being opened for the first time, it will not have a property file, and so the default C:/Ensign10/Inifile/Chart.ini file is read.  Chart property files are located in the C:/Ensign10/Property folder using the chart symbol in the filename.

Studies and Draw Tools that belong to the chart are located in the C:/Ensign10/Study folder and use the chart symbol in the filename.

Layouts:  When a layout is opened, the layout script contains information about which forms to open, where to position them, and how to dress the charts with studies and tools.  The layout file possesses the chart properties, and the chart objects.  Thus, a chart opened by a layout does not read from the C:/Ensign10/Property folder nor from the C:/Ensign10/Study folder.   Layout files are located in the C:/Ensign10/Layout folder with a sub-folder for each of the eight layout form tabs.

The layout file is saved when you use the Save or Save As buttons on the layout form.  You should resave layouts using different names when you are evolving your layout content so that you have an earlier version of the layout if you experience a difficulty.

The pop-up menu for Save Layout (hot key CTRL+W) executes the same code as the Save button on the Layout form.

Templates:  Templates are a collection of studies and draw tool objects that are stored as a file so the collection can be applied to a chart.  Template files are located in the C:/Ensign10/Templates folder with a sub-folder for each of the eight template form tabs. 

Template files are saved when you use the Save or Save As buttons on the template form.  You should resave templates using different names when you are evolving your template content so that you have an earlier version of the template if you experience a difficulty and want to return to an earlier version.

Backups:  You are encouraged to have the Setup | System option checked to Backup Templates on Exit.  This backup feature will backup several important folders, including layouts.  Upon program exit, important files will be copied to the folder C:/Ensign10/AutoBackup which has sub-folders for each day of the week.  Thus, there could be a useful image of your files from Monday if they need to be restored on Wednesday.

Another backup and restore feature is found on the Setup | System | Maintenance form.  Perform task #14 to create an extensive backup to folder C:/Ensign10Backup.  And performing task #15 would restore this backup from the same folder.  This manual backup image is more extensive and is independent of the backup made on program exit.

The backups are accomplished by copying files.  Thus any file could be restored by using Windows Explorer to copy the file from the backup location to its appropriate folder under the C:/Ensign10 folder.

Undelete:  The chart objects form has an Undelete button which when clicked will restore the last deleted chart object.   The undelete is accomplished by reloading a template of the chart objects that was saved in a C:/Ensign10/Backup folder prior to the deletion.   Though this was intended for use by Ensign 10 behind the scene, this folder might have a useful copy of how a chart was dressed with studies and draw tools if a template file is accidentally deleted or corrupted in the C:/Ensign10/Templates folder.

Personal Backups:  Trading is a serious endeavor, and should be treated as such.  You should make your own backups to devices which are separate from the computer’s hard disk.   I recommend a free program called EZBackitup and use it on a daily basis to back up important files and folders to an external hard disk or to jump drives.  It is easy to create a backup script by dragging files or folders from a navigation tree to the backup list.  Jump drives are inexpensive, so I backup to a different one each day of the week.

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.

Tick Count in a Bar’s Range

Q:  I am wanting to know the number of ticks per bar. The total count from the high to the low. (Bonds are 1/32 so they are tricky).

A:  Ensign has a value called Tick Count for each bar, but I do not think that is what you seek since you mentioned 1/32nds. The Tick Count is the number of trade ticks received for the bar. I think you are wanting to count the number of price intervals in a bar’s range. For example, if the bar’s High is 109-040 and the bar’s Low is 109-020 the answer is 4 on a ZB bond chart because the difference is 4/64ths.  ZB trades in half 32nds.

This DYO example will make the calculation and show the price count above each bar.

The BAR marker selection will post the expression result as an integer value.  The Marker Location selection used was the Above High 5 location.