A function that creates a HTML file after backtesting which contains a 0

Posted on 17, June 2013

in Category SID


Description for OutputHTML SID 805

A function that creates a HTML file after backtesting which contains all orders, positions and tradehistory for the account.

A function that creates a HTML file after backtesting which contains a/sid The logic for this function:

#This function creates an HTML file, containing all orders, positions and 
#tradehistory for the account. This function should be called in the 
#End Event for the account.

#The filename of the html file
my $filename='C:/results.html';
#We try and open the file for writing. If this fails, we raise a fatal error
#The first parameter is the file handle, we use this handle when writing to the file.
my $fh;
open($fh,"> $filename") or die 'Could not open file';
#We use the print statment to write to the file.
print $fh '<html><html><head><title>Backtest Results</title></head><body>';
print $fh '<H4>Orders</H4>';
#We use HTML tables to represent the data
print $fh '<TABLE border=1><TR>';
#do the headings for the 
foreach ('Order','Symbol','Units','Stop','Label','System') {
  print $fh "<th>$_</th>";
}
print $fh '</tr>';
#we now loop round all orders
foreach my $order (AccountOrders) {
  print $fh '<tr>';
  print $fh '<td>'.$order->TypeDescription.'</td>';
  print $fh '<td>'.$order->Symbol.'</td>';
  print $fh '<td>'.$order->Units.'</td>';
  print $fh '<td>'.$order->StopPrice.'</td>';
  print $fh '<td>'.$order->Label.'</td>';
  print $fh '<td>'.$order->SystemName.'</td>';
  print $fh '</TR>';
}
print $fh '</TABLE>';

print $fh '<h4>Positions</h4>';
print $fh '<table border=1><tr>';
#do the headings
foreach ('Symbol','Units','Type','Avg Price','Bars','Open Profit','Enter Date','Value') {
  print $fh "<th>$_</th>";
}
print $fh '</tr>';
#we now loop round all positions
foreach my $position (AccPositions) {
  print $fh '<tr>';
  print $fh '<td>'.$position->Symbol.'</td>';
  print $fh '<td>'.$position->Units.'</td>';
  print $fh '<td>'.$position->TypeDescription.'</td>';
  print $fh '<td>'.$position->AvgPrice.'</td>';
  print $fh '<td>'.$position->BarsSinceEntry.'</td>';
  print $fh '<td>'.Round($position->OpenProfit,2).'</td>';
  print $fh '<td>'.FormatDateTime($position->EnterDate).'</td>';
  print $fh '<td>'.$position->Value.'</td>';
  print $fh '</TR>';
}
print $fh '</table>';

print $fh '<h4>Trade history</h4>';
print $fh '<table border=1><tr>';
#do the headings
foreach ('Symbol','System name','Units','Type','Bars','EnterPrice','EnterDate','EnterLabel','Profit','ExitDate','ExitPrice','ExitLabel') {
  print $fh "<th>$_</th>";
}
print $fh '</tr>';
foreach my $trade (AccTradeHistory) {
  print $fh '<tr>';
  print $fh '<td>'.$trade->Symbol.'</td>';
  print $fh '<td>'.$trade->SystemName.'</td>';
  print $fh '<td>'.$trade->Units.'</td>';
  print $fh '<td>'.$trade->TypeDescription.'</td>';
  print $fh '<td>'.$trade->BarsSinceEntry.'</td>';
  print $fh '<td>'.Round($trade->EnterPrice,2).'</td>';
  print $fh '<td>'.FormatDateTime($trade->EnterDate).'</td>';
  print $fh '<td>'.$trade->EnterLabel.'</td>';
  print $fh '<td>'.Round($trade->Profit,2).'</td>';
  print $fh '<td>'.FormatDateTime($trade->ExitDate).'</td>';
  print $fh '<td>'.Round($trade->ExitPrice,2).'</td>';
  print $fh '<td>'.$trade->ExitLabel.'</td>';
  print $fh '</tr>';
}
print $fh '</table>';
print $fh '</body></html>';
#close the file handle
close($fh);

0 Comments

Leave a Message