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

[amibroker] Re: Reading data from external text or csv file



PureBytes Links

Trading Reference Links

Graham,

I have developed a script that would open and read in certain ascii 
datas from files which resides on my C: drive.  I am not sure if 
this is what you want.  One problem is if you have a lot of datas 
then this method will be slow because it's not native code.

/**** Reading in MIDAS launch dates from \wmp30 directory  *********/

<%
var ForReading = 1,ForWriting = 2, ForAppending = 8;
var fileSystemObj, tickerString, currentLine;
var wmp30Dir, currentFileName;

S1_JSDate=S2_JSDate=S3_JSDate=R5_JSDate=R4_JSDate=R3_JSDate=R2_JSDate
=R1_JSDate=TB_JSDate=TB_JSCenter=Start_JSDate="0";

tickerString = AFL("currentTicker"); // reading in ticker symbol 
from AB
if ( tickerString.match(/\^DJI/i) ) tickerString = "!DJ30";
if ( tickerString.match(/\^IXIC/i) ) tickerString = "!COMP";
//tickerString = tickerString.replace (/\^/,"!"); // yahoo uses "^", 
QuotePlus uses "!"
winMidasDir = "C:\\wmp30\\";
midasDataFile = winMidasDir + tickerString + ".DAT";
fileSystemObj = new ActiveXObject("Scripting.FileSystemObject"); // 
creating an object type ActiveX

if (fileSystemObj.FileExists(midasDataFile)) {
  dataFilePtr = fileSystemObj.OpenTextFile (midasDataFile, 
ForReading); 
  for ( i = 0; i < 11; i++ ) {
    currentLine = dataFilePtr.ReadLine();
    if ( currentLine.match (/[1-9]/) ) { 
      currentLine = currentLine.replace (/\s*/g,""); // removing 
leading space.

      switch ( currentLine.length ) {
      case 3:
	Day = currentLine.substr (1,2); // extract day only
	Month = "0" + currentLine.substr (0,1);
	Year = "100";
	break;
      case 4:
	Day = currentLine.substr (2,2); // extract day only
	Month = currentLine.substr (0,2);
	Year = "100";
	break;
      case 5:
	Day = currentLine.substr (3,2); // extract day only
	Month = currentLine.substr (1,2);
	Year = "10" + currentLine.substr (0,1);
	break;
      }

      if ( currentLine.length < 6 ) {
	ABdate = Year + Month + Day;
      }
      else
	ABdate = currentLine;

      switch ( i ) {
      case 0:
	Start_JSDate  = ABdate;
	break;
      case 1:
	S1_JSDate = ABdate;
	break;
      case 2:
	S2_JSDate = ABdate;
	break;
      case 3:
	S3_JSDate = ABdate;
	break;
      case 4:
	R5_JSDate = ABdate;
	break;
      case 5:
	R4_JSDate = ABdate;
	break;
      case 6:
	R3_JSDate = ABdate;
	break;
      case 7:
	R2_JSDate = ABdate;
	break;
      case 8:
	R1_JSDate = ABdate;
	break;
      case 9:
	TB_JSDate = ABdate;
	break;
      case 10:
	TB_JSCenter = ABdate;
	break;
      } // end of switch.
    } // end of if
  }

  dataFilePtr.Close(); // close Midas.dat
} // end if.

/***** Passing Jscript result back to AB variables *****/

AFL.Var("S1_Date") = parseInt(S1_JSDate,10); // some unclear offset
AFL.Var("S2_Date") = parseInt(S2_JSDate,10);
AFL.Var("S3_Date") = parseInt(S3_JSDate,10);
AFL.Var("R5_Date") = parseInt(R5_JSDate,10);
AFL.Var("R4_Date") = parseInt(R4_JSDate,10);
AFL.Var("R3_Date") = parseInt(R3_JSDate,10);
AFL.Var("R2_Date") = parseInt(R2_JSDate,10);
AFL.Var("R1_Date") = parseInt(R1_JSDate,10);
AFL.Var("TB_Date") = parseInt(TB_JSDate,10);
AFL.Var("TB_Center") = parseInt(TB_JSCenter,10);
AFL.Var("ticker") = tickerString;

%>




--- In amibroker@xxxxxxxxxxxxxxx, "Graham" <gkavanagh@xxxx> wrote:
> I am wanting to use data from a text file (or can be set in csv 
format)
> directly during running an AFL scan. This file would include such
> information such as fundamental data.
> I hope someone can help me with a method to do this.
> I note GETEXTRADATA from the help files, but this appears only to 
use
> QuotesPlus and TC2000.
> 
> 
> 
> Cheers,
> Graham
> http://groups.msn.com/ASXShareTrading
> http://groups.msn.com/FMSAustralia


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Make Money Online Auctions! Make $500.00 or We Will Give You Thirty Dollars for Trying!
http://us.click.yahoo.com/yMx78A/fNtFAA/AG3JAA/GHeqlB/TM
---------------------------------------------------------------------~->

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 

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