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

Re: Discretionary Trade Input for Strategy Performance Report



PureBytes Links

Trading Reference Links

> I am not an Easy Language coder,  but I want to enter actual trades
> from a discretionary trading strategy and then run a Strategy
> Performance Report. 1) What is the easiest way to do this? I have
> trade entry & exit prices/trade date & time /stops... etc. 

Probably the simplest way is to create a system that buys and 
sells exactly when you did.  E.g.:

if Date = MyEntryDate1 and Time = MyEntryTime1
  then buy at MyEntryPrice1 stop;
if Date = MyExitDate1 and Time = MyExitTime1
  then exitlong at MyExitPrice1 stop;

if Date = MyEntDate2 and Time = MyEndTime2
  then sell at MyEntryPrice1 stop;
(etc -- convert to TS6/7 syntax if needed)

One trick with this:  you have to issue the order on the bar 
BEFORE it's actually filled.  And your entry/exit times probably 
won't correspond exactly to chart bar timestamps.  So you either 
have to figure the timestamp of the bar before your fill, or you 
can get a bit tricky:

         ... and Time of Next Bar crosses over MyEntTime1 ...

By using the "crosses over" operator, you'll catch the first bar 
that has a time >= your fill time, which is what you want.

> 2) Has anybody (ex. third party developers) already created a simple
> trade entry template that works with easy language? 

It would be pretty simple to take e.g. a CSV file from Excel 
(assuming you used Excel to record your trades) that contained 
the fill time/price info, and write a Perl script to spit out 
Easy Language like the above example.  I don't know of anyone 
who's already done it, though.

Oh, what the heck....   (shuffle shuffle type type)

Here.  The attached Perl script will accept CSV files containing 
trade records that look like this:

Long/Short,MyEntryDate,MyEntryTime,MyEntryPrice,Stop/Limit,MyExitDate,MyExitTime,MyExitPrice,StopLimit
L,20030401,11:35,848.8,S,20030402,12:14,882.5,L
S,20030403,13:11,878.5,L,20030404,14:12,875.7,S

...and spits out Easy Language to execute the trades at the time 
and price you specify.  It will generate either TS4/TS2k syntax 
or TS6/TS7 syntax, depending on a "$newsyntax" variable that you 
can change.  (I think I have the TS6/7 syntax correct.)

The example above works for big SP, running in EST.

See comments in the Perl script for setup instructions.  You can 
get Perl at 
http://www.perl.com/pub/a/language/info/software.html#binary, 
which will direct you to 
http://www.activestate.com/Products/Download/Download.plex?id=ActivePerl

No support implied or promised, your mileage may vary, etc etc.

Gary

=========================================================

# Convert discretionary trade record in CSV format
# to EasyLanguage code that executes the same trades.
# Expected data format:  
# L/S,EntryDate,EntryTime,EntryPrice,S/L,ExitDate,ExitTime,ExitPrice,S/L
# First field is L for long, S for short
# S/L fields are S for stop, L for limit
# Date format must be YYYYMMDD -- you can set a "custom" format in Excel
# with a format of "yyyymmdd" to get it to save it that way.
# Usage:  perl genorders.pl < orders.csv > easylang.txt
#
# ***NOTE***
# If running TS6 or later, change the next line to "$newsyntax = 1;"
$newsyntax = 0;

if ($newsyntax == 0) {
  $buy = "buy";
  $exitlong = "exitlong";
  $sell = "sell";
  $exitshort = "exitshort";
}
else {
  $buy = "buy next bar";
  $exitlong = "sell to cover next bar";
  $sell = "sell short";
  $exitshort = "buy to cover next bar";
}

while (defined($line = <STDIN>)) {
  if (index(lc($line), "entry") >= 0) {  # skip header line, if any
    }
  else {
    chomp($line);
    ($longshort, 
     $entdate, $enttime, $entprice, $entlimstop,
     $exitdate, $exittime, $exitprice, $exitlimstop) = split(/,/, $line);
    # Convert dates to tradestation format, remove :'s from time
    $entdate = $entdate - 19000000;
    $exitdate = $exitdate - 19000000;
    $enttime =~ s/://;
    $exittime =~ s/://;

    $enttype = "stop";
    $exittype = "stop";
    if (uc($entlimstop) eq "L") { $enttype = "limit"; }
    if (uc($exitlimstop) eq "L") { $exittype = "limit"; }

    if (uc($longshort) eq "L") {
      print("if Date = $entdate and Time of Next Bar crosses over $enttime\n");
      print("  then $buy at $entprice $enttype;\n");
      print("if Date = $exitdate and Time of Next Bar crosses over $exittime\n");
      print("  then $exitlong at $exitprice $exittype;\n\n");
    }
    else {
      print("if Date = $entdate and Time of Next Bar crosses over $enttime\n");
      print("  then $sell at $entprice $enttype;\n");
      print("if Date = $exitdate and Time of Next Bar crosses over $exittime\n");
      print("  then $exitshort at $exitprice $exittype;\n\n");
    }
  }
}