[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: advancing issues



PureBytes Links

Trading Reference Links

>  I have the data but there seems to be an error in the file that is
> causing the data to plot incorrectly.  For instance it plots starting
> at 10:30 and only plots the close.  

Data starting at 10:30 sounds like a setup problem in the 
settings for the ASCII file.  (Format Symbol, Settings, Universe 
button.)

Only plotting the close sounds like errors in the file -- most 
likely repeated lines.  TS handles repeated lines (e.g. two lines 
with a 10:05 timestampe) very ungracefully.

Here's a Perl script that checks data files for this kind of 
problem.

Gary

===

# Check standard TS-format data for duplicate or out-of-order lines.
# Expected data format:  MM/DD/YYYY,time,(etc)
# Handles 1-digit MM & DD, 2-digit YYYY, and :'s in time
# Usage:  perl datatest.pl < inputfile

$errors = 0;
$lastdatenum = 0;
$lasttime = 0;
$linenum = 0;

while (defined($line = <STDIN>)) {
  $linenum++;
  if (index(lc($line), "date") >= 0) {  # skip header line, if any
    }
  else {
    ($date, $time, $extra) = split(/,/, $line);
    # Convert $date to YYYYMMDD format
    $date =~ m;^(\d*)/(\d*)/(\d*)$; or die;
    $mm = $1; $dd = $2; $yy = $3;
    if ($yy < 1900) { $yy = ($yy < 20 ? '20'.$yy : '19'.$yy); }
    $datenum = sprintf("%4d%02d%02d", $yy, $mm, $dd);
    $time =~ s/://;                     # remove : from time
    if ($datenum < $lastdatenum) {
      print "Date out of order in line $linenum: \n  $lastline  $line";
      $errors++;
      }
    if (($datenum == $lastdatenum) && ($time == $lasttime)) {
      print "Repeated time in line $linenum:\n  $lastline  $line";
      $errors++;
      }
    if (($datenum == $lastdatenum) && ($time < $lasttime)) {
      print "Time out of order in line $linenum:\n  $lastline  $line";
      $errors++;
      }
    }
    $lastline = $line;
    $lastdatenum = $datenum;
    $lasttime = $time;
  }

if ($errors == 0) { print "No errors found!\n"; }