Seer logo - advanced backtesting for stock, futures and forex trading systems using using technical analysis indicators, charts, money management and position sizing
SID NameDescriptionRating
584 Backtest_NewsleThis example trading system allows the backtesting of newsletter "buy" and "sell" signals. The signals are stored in a comma separated variable (CSV) file that can be edited in a text editor or in a spreadsheet.Not Approved

Notes for this Trading Account:

This example trading system allows the backtesting of newsletter "buy" and "sell" signals. The signals are stored in a comma separated variable (CSV) file that can be edited in a text editor or in a spreadsheet.

The file is loaded in the account begin event with the signals loaded into global hash references. During backtesting these hashes are tested to see if a signal is valid for "today" and appropriate action taken. This example supports multiple symbols, and is suitable for full portfolio backtesting. Symbols and actions can appear in any order in the file.

See the account begin event for more details on the file format and for an example file.

Rules for this Trading Account:

Begin event logic:

#The file format for the newsletter file should be:
#Signal(Buy or Sell,Symbol,Date (in the format of YYYYMMDD)
#for example:

##An example file 
#Buy,MSFT,20051004
#Sell,MSFT,20051027
#Buy,BA,20051130
#Sell,BA,20051230
#Buy,GM,20050815
#Sell,GM,20051010

#To use this file, the leading '#' should be removed. Note
#that you can use '#' - the line will be ignored when it's
#the first character.


#The path to the newsletter file
my $filepath="C:/newsletter.csv";
open(FILE,"< $filepath") || die("can't open $filepath: $! .See instructions in the Account Begin Event");
#load the file into an array
my @lines=<FILE>;
close(FILE);

#A reference to a hash structure

$buy={}; 
$sell={}; 

foreach my $line (@lines) {
  #ignore the line if the first character is a '#'
  next if substr($line,0,1) eq '#';
  #split the line
  my ($action,$symbol,$date)=split(',',$line);
  #We need to convert the date into a valid Seer date, then validate the date just to be sure
  $date*=10000000;
  die "invalid date $date in line $line" unless ValidateDateTime($date);
  #we now populate the buy/sell hash with the symbol and the date, setting the entry to true
  if ($action eq 'Buy') {
    $buy->{$symbol}{$date}=1;
  }
  elsif ($action eq 'Sell') {
    $sell->{$symbol}{$date}=1;
  }
  else {
    die "unknown action $action in line $line";
  }
}

Notes for this Trading System:

Rules for this Trading System:

Bar event logic:

#fetch the current symbol and the datetime
#we will use these items to test the buy/sell hashes for signals
my $symbol = Symbol;
my $date   = Now(DateTime);

unless (Position) {
  #Buy logic
  if ($buy->{$symbol}{$date}) {
    Output "we have a buy signal for $symbol on $date";
    BuyOpen;
  }
}
else {
  #Sell logic
  if ($sell->{$symbol}{$date}) {
    Output "we have a buy signal for $symbol on $date";
    SellOpen;
  }
}

© 2010 seer trading systems ltd
feedback FAQ legal privacy