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

Re: A question on how to compare buying signals



PureBytes Links

Trading Reference Links

>
> You can generate all the returns/stats on one tradable within the capabilities of TS 4. What can't be done w/o some kind of macro or addon, is the optimization thru your universe of tradables.

Last weekend I put together a macro and a ELA function (called from your strategy) which writes the post-optomisation parameters for each symbol in a list of (your favourite) stocks.

This was for TS Pro so there may be some differences for TS4.  I was unable to find a way to read from a file from ELA (perhaps someone knows how) so the synchronisation is done by having the macro wait a set period.  Obviously not ideal but does work, provided: nothing else significant is running in the background and no scheduled jobs jump up in the middle of it, like backup.

You must have the the range for the parameters to be optomised already set up.  The list of symbols, in this example in file optomise.txt, must all be symbols that the system can get and make sure that no symbol appears more than once consecutively.  Either of these faults will cause the process to halt.

The optoPeriod in the script is determined by trial and error.  A compromise between always being long enough and not making the process too long.

The script language I used is called CLR Script and is a shareware utility I got from twocows.com.

I Smith


The code:

in your strategy...*************************************

inputs:
vars:
array: stratPars[3](0);   { in this example 3 parameters are optomised}

...
your strategy
...
stratPars[0] = length;
stratPars[1] = buyThresh;
stratPars[2] = sellThresh;
returned = iasOptoReport("c:\cup\", 3, stratPars);


function iasOptoReport...*****************************************

inputs: dirStr(String), nStratPars(Numeric), stratParsArray[MaxSize](NumericArray);
vars: fileStr(" "), stratParsString(" "), i(0);

if LastBarOnChart then begin

  stratParsString = " ";
  if nStratPars > 0 then Begin
   for i = 0 to nStratPars - 1 begin
     stratParsString = stratParsString + numtostr(stratParsArray[i],2) + " ";
    end;
  end;

  FILEappend(dirStr + GetSymbolName + ".rdy", "-");

  fileStr = dirStr + GetSymbolName + ".rpt";
  FileDelete(fileStr);                                      { delete all but the last opto run parameters }

  FILEappend(fileStr, GetSymbolName                              + " " +
                     numtostr(NetProfit + OpenPositionProfit,0)   + " " +
                     numtostr(PercentProfit,1)                             + " " +
                     numtostr(NumWinTrades + NumLosTrades,0)    + " " +
                     numtostr(NumWinTrades,0)                         + " " +
                     numtostr(NumLosTrades,0)                         + " " +
                     numtostr(MaxIDDrawDown,0)                    + " " +
                     numtostr(MaxConsecWinners,0)                  + " " +
                     numtostr(MaxConsecLosers,0)                    + " " +
                     stratParsString                                            +
                     numtostr(BarInterval,0)                               +
                     NewLine   ) ;
end;
iasOptoReport = 0;

CLR Script script...**************************************************

void main()
{
//  CLR Script script

  HFILE listFp, reportFp, symFp;
  string sText, symStr, readyFile, reportFile;
  string symbReport, reportLine, dir, symList;
  int status, i, optoPeriod;

  dir =        "c:\\cup\\";            // working directory
  symList =    "optomise.txt"   // list of symbols
  optoPeriod = 145000;          // optomisation time plus a bit in milli-secs
  reportFile = dir + "optoresults.txt";

  listFp = OpenFile(dir + symList, FILE_READ);
  if (listFp == NULL)
  {
 MessageBox("There was an error opening the file " + symList);
 return;
  }

  reportFp = OpenFile(reportFile, FILE_CREATE | FILE_WRITE );
  if (reportFp == NULL)
  {
 MessageBox("There was an error opening the file " + reportFile);
 return;
  }

  Pause(2000);
  if (!VerifyActiveWindowTitleSub("TradeStation"))
  {
    MessageBox("Wrong Active Window");
    return;
  }
  while (!FileEOF(listFp))               // loop through all symbols
  {
     sText = ReadFileString(listFp);      // read next symbol
     symStr = sText + "{enter}";
     readyFile = dir + sText + ".rdy";
     symbReport = dir + sText + ".rpt";

     SendKeys(symStr);                    // send next symbol to TS
     while (!FileExists(readyFile))       // wait for new symbol acknowledge
     {
       Pause(3000);
       if (i > 60)
       {
         MessageBox("Tradestation is not responding to symbol " +  sText);
         return;
       }
   }

// send keystrokes to enable optomisation

    Pause(1000);
    SendKeys("{alt}og");
    Pause(200);

    SendKeys("{tab}{tab}{enter}");
    Pause(200);

    SendKeys("{tab}{tab}{enter}");
    Pause(200);

    SendKeys("{enter}");
    Pause(200);

    SendKeys("{down}{down}{tab}{tab}{enter}");
    Pause(200);

    SendKeys("{enter}");
    Pause(200);

    SendKeys("{down}{tab}{tab}{enter}");
    Pause(200);

    SendKeys("{enter}");
    Pause(200);

    SendKeys("{enter}");
    Pause(200);

    SendKeys("{enter}");
    Pause(200);

    Pause(optoPeriod);

// get optomisation results

   symFp = OpenFile(symbReport, FILE_READ);
   if (symFp == NULL)
   {
     MessageBox("There was an error opening the file " + symbReport);
     return;
    }
   reportLine = ReadFileString(symFp);

// add them to the others

   status = WriteFileString(reportFp, reportLine + "\n");
   CloseFile(symFp);
   status = DeleteFile(readyFile);
   status = DeleteFile(symbReport);
  }

  CloseFile(listFp);
  CloseFile(reportFp);
}