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

RE: [amibroker] Re: TJ: plotting the same indicator in different charting windows



PureBytes Links

Trading Reference Links

kw,

Back in January Nigel and Dingo put together a "PlayBack" (for lack of a
better word) utility for me which looks like it may be what you need.  Below
is the code.  You might also check archives for messages with "Playback" in
the subject line.  Note that you should have all symbols you're trading in a
Watchlist that you use in AA.  You can have other symbols, but the CSV file
is read for each symbol in the Watchlist, so it's best not to have too many
unnecessary symbols in that WL...

...Don Upton

////////////////////////////////////////////////////////////////////////////
/////////////
// Inspired by a request for a 'playback' feature from Don Upton,
//
// initial code by Nigel Rowe,
// with contributions by Ruddy Turnstone Trading, LLC  (dingo)
//
//
// Input file is comma seperated text.
// Fields are:
//      0.      Symbol        -- without quotes
//      1.        Long Or Short -- L or S, without quotes
//      2.      Number of shares
//      3.        Entry date    -- in mm/dd/yyyy format.  ie xmas day 2003
is 12/25/2003
//      4.      Entry price
//      5.      Exit date     -- mm/dd/yyyy  format, or blank for no exit
//      6.      Exit Price


function DateToDateNum(sMMDDYYYY) // date in format mm/dd/yyyy
{

/*-------------------------------------------------------------
  This function will accept a string in the MM/DD/YYY format
  and convert it into Amibroker's datenum.

  nDateNum = 10000 * (year - 1900) + 100 * month + day

  It assumes that mm dd and yyyy are reasonable. It does check
  for the presence of 2 "/" characters and if not there
  will return a 0.
- -------------------------------------------------------------*/
      local nDateNum, sWrk, nPosn, nYr, nMth, nDay;

      nDateNum = 0;
          sWrk = sMMDDYYYY;
          nPosn = StrFind(sWrk, "/");
          if (nPosn > 0) {
             nMth = StrToNum(StrLeft(sWrk, nPosn-1));
              sWrk = StrRight(sWrk, StrLen(sWrk) - nPosn);
              nPosn = StrFind(sWrk, "/");
              if (nPosn > 0) {
                        nDay = StrToNum(StrLeft(sWrk, nPosn-1));
                        sWrk = StrRight(sWrk, StrLen(sWrk) - nPosn);
                        nYr = StrToNum(sWrk);
                        nDateNum = 10000 * (nYr - 1900) + (100 * nMth) +
nDay;
            }
      }
          return nDateNum;
}



function DateToBar(dn)
{
      return LastValue(ValueWhen(DateNum()==dn, BarIndex()));
}




function playback(filename)
{
      local f, Line, sym;
      local LorS, numShrs;
      local entryDate, entryPrice, exitDate, exitPrice;
      local bar;

      global Buy, Sell, BuyPrice, SellPrice;
      global Short, Cover, ShortPrice, CoverPrice;
      global PositionSize;

      f = fopen(filename, "r");
      while( f && (! feof(f))) {
            Line = fgets(f);
            sym = StrExtract(Line, 0);
            if( sym == Name() ) {
                  LorS = StrExtract(Line, 1);
                  numShrs = StrToNum(StrExtract(Line,2));
                  entryDate = DateToDateNum(StrExtract(Line,3));
                  entryPrice = StrToNum(StrExtract(Line,4));
                  exitDate = DateToDateNum(StrExtract(Line,5));
                  exitPrice = StrToNum(StrExtract(Line,6));

                  bar = DateToBar(entryDate);

                  // The extra (entryPrice/2) is to avoid rounding errors.
                  PositionSize[bar] = (numShrs*entryPrice) + (entryPrice/2);

                  if (LorS == "L") {
                        Buy[bar] = True;
                        BuyPrice[bar] = entryPrice;
                              if( exitdate ) {
                                     bar = DateToBar(exitdate);
                                     Sell[bar] = True;
                                     SellPrice[bar] = exitPrice;
                              }
                  } else {
                                 Short[bar] = True;
                          ShortPrice[bar] = entryPrice;
                          if( exitDate ) {
                                    bar = DateToBar(exitDate);
                                     Cover[bar] = True;
                                     CoverPrice[bar] = exitPrice;
                          }
                    }
                }
      }
      if(f) fclose(f);
}


SetFormulaName("Playback from file");

// Enforce required settings
SetOption("InitialEquity", 10000000);
SetOption("MaxOpenPositions", 10000);
SetOption("MinShares", 1);
SetOption("AllowPositionShrinking", False);
SetOption("FuturesMode", False);
SetTradeDelays(0,0,0,0);
ApplyStop(stopTypeLoss,        stopModeDisable, 0, 0);
ApplyStop(stopTypeTrailing,stopModeDisable, 0, 0);
ApplyStop(stopTypeProfit,        stopModeDisable, 0, 0);
ApplyStop(stopTypeNBar,    stopModeDisable, 0, 0);


// NB!! you will have to manually set Positions and Periodicity !!!!!
//
//The following SetOption are NOT valid, mentioned here for completeness
//SetOption("Positions", "Long and Short");
//Setoption("Periodicity", "Daily");

Buy = False;
Sell = False;
BuyPrice = Close;
SellPrice = Close;
Short = False;
Cover = False;
ShortPrice = Close;
CoverPrice = Close;
PositionSize = 0;

// and the next line does all the work!
playback("playback.txt");

////////////////////////////////////////////////////////////////////////////
/////////////

-----Original Message-----
From: kw_odonian [mailto:kw_odonian@xxxxxxxxx]
Sent: Wednesday, May 19, 2004 7:44 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] How to use signals from another system with AB?


Hi AB programmers,

If I have a CSV list of trades (ticker, entry date, exit date,
long/short) data from another system or advisor that I want to throw
against my Amibroker data to find stats like,

MAE,
MFE,
exit efficiency,
and just testing different exits,

What's the best way to do so?

And does anyone use Python via the COM to tap AB data?  Thanks,

kw




Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Links









Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
     amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/