// export of <TICKER>,<YYYY-MM-DD>,<hh:mm:ss>,<ROC> to CSV file
// trash, Jan 2014
// Usage:
// 1. open AFL in Analysis,
// 2. choose Apply to:
// 3. choose Range
// 4. choose Periodicity in backtest settings
// 5. click Explore
// 6. be happy and smile
destination = "C:\\#ABExport\\"; // choose export folder
fmkdir( destination ); // creates export folder
bir = Status( "BarInRange" );
lbr = Status( "LastBarInRange" );
ss = Second();
mm = Minute();
Hh = Hour();
dd = Day();
mth = Month();
yr = Year();
nm = Name();
_ROC = Nz( ROC( C, 1 ) );
Filter = lbr;
SetOption( "NoDefaultColumns", True );
AddTextColumn( nm, "Ticker", 1, colorWhite, colorDarkGrey, 90 );
AddTextColumn( "Export finished", "Status", 1, colorWhite, colorDarkGreen, 90 );
if ( Status( "action" ) == actionExplore )
{
filename = destination + nm + ".csv";
fh = fopen( filename, "r" );
if ( NOT fh )
{
_TRACE( "file does not exist" );
fw = fopen( filename, "w" );
if ( fw )
{
fputs( "<Ticker>,<YYYY-MM-DD>,<hh:mm:ss>,<ROC>\n", fw );
for ( i = 0; i < BarCount; i++ )
{
if ( bir[i] )
{
// <TICKER>,<YYYY-MM-DD>,<hh:mm:ss>,<ROC>
fputs( nm + ",", fw );
dnex = StrFormat( "%02.0f-%02.0f-%02.0f,", yr[i], mth[i], dd[i] );
fputs( dnex, fw );
tnex = StrFormat( "%02.0f:%02.0f:%02.0f,", hh[i], mm[i], ss[i] );
fputs( tnex, fw );
priceex = StrFormat( "%g\n", _ROC[i] );
fputs( priceex, fw );
}
}
fclose( fw );
}
}
else
{
_TRACE( "file exists" );
fclose( fh );
fw = fopen( filename, "a" );
if ( fw )
{
for ( i = 0; i < BarCount; i++ )
{
if ( bir[i] )
{
// <TICKER>,<YYYY-MM-DD>,<hh:mm:ss>,<ROC>
fputs( nm + ",", fw );
dnex = StrFormat( "%02.0f-%02.0f-%02.0f,", yr[i], mth[i], dd[i] );
fputs( dnex, fw );
tnex = StrFormat( "%02.0f:%02.0f:%02.0f,", hh[i], mm[i], ss[i] );
fputs( tnex, fw );
priceex = StrFormat( "%g\n", _ROC[i] );
fputs( priceex, fw );
}
}
fclose( fw );
}
}
}