Special thanks to “George Soros” (Matt Briand) for the original example.
Note: you have to add a timestamp at the end of every signal in the following format - yyyymmddhhmm0 format (note the 0 at the end)
As Ensign ESPL is quite difficult, we have included in this documentation a more complete example than for Tradestation or Wealth-Lab using a simple moving average system. For support on ESPL langage, please contact support@ensignsoftware.com
var
i,Handle: integer;
nbr_contract : integer;
order : string;
entryprice : real;
entrystr : string;
stop : real;
begin
nbr_contract :=1; {We will trade 1 contract}
entryprice := 0;
entrystr:='';
if OpenFile('C:\trading.txt',eRewrite) then
{Open a new file named Trading.txt for Bracket Trader 3rd party autotrading}
begin
Chart('ES #F.-360'); {Open a 360 ticks ES continuous contract chart}
Template(eLoad,'TradingSys');
{We will use TradingSys chart template}
Handle := AddStudy(eAve,5,10);
{Add Simple Moving Averages 5 and 10 to the chart}
ResetTrades(2.4,0,1,3);
{Initialize the Trading system, with a commission of 2.4USD for IB}
for i:= BarBegin to BarEnd do
{Loop through the bars}
begin
{start of loop code}
if GetStudy(Handle,4,i)=1 then {4=Get crossing flag, return 1 when MA1 crosses above MA2}
begin
Trade(eBuy+eIf,i); {Generate a buy signal if there is not already a short trade}
entryprice:=Last(i)/100 + 0.25;
{We enter at the Last + 0.25 or better}
{because of ESignal future price format we divide by 100}
entrystr:=FloatToStr(entryprice);
{We convert the price in a string}
order:='cxlplace,BUY,' + IntToStr(nbr_contract) + ',LMT,' + entrystr + ',0';
writelnfile(order);
{the file is written}
end;
if GetStudy(Handle,4,i)=2 then
{4=Get crossing flag, return 2 when MA1 crosses below MA2}
begin
Trade(eSell+eIf,i);
{Generate a sell signal if there is not already a long trade}
entryprice:=Last(i)/100 - 0.25;
{We enter at the Last - 0.25 or better} {because of ESignal future price format we divide by 100}
entrystr:=FloatToStr(entryprice);
order:='cxlplace,BUY,' + IntToStr(nbr_contract) + ',LMT,' + entrystr + ',0';
writelnfile(order); {the file is written}
end;
end; {end of loop code}
Trade(eOut); {Close-out the last open trade}
TradeReport(True); {Print a Trading System Summary}
CloseFile;
end;
end;