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} 
end;

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:

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

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

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;

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.

http://download.interactivebrokers.com/download/tws40_install.exe

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  127.0.0.1  as shown here.