PureBytes Links
Trading Reference Links
|
Graham, thanks for the suggestion to use "append". The code works
fine now (it's at the bottom of this post).
Rakesh, I looked at your code. It works ok. Here are a few comments.
1) I didn't know that you needed separate files for each symbol. When
I used MetaStock years ago the MS Import/Export Utility required all
symbols grouped together into one ASCii file for import.
2) Check/correct the following in the "comments" section:
"Select the time frame period you want to save as using the AA
Settings".
This doesn't work on my end. All available data is imported
regardless of the date range selected.
3) You wouldn't have to worry about whether the directory already
exists or not on your hard drive if the first three lines of your
code were as follows:
folder = "d:\\amibroker\\US_STOCKS_ASCII";
fmkdir( folder ); /*this automatically creates the directory*/
fh = fopen( folder + "\\" + Name() + ".txt", "w");
4) What's the reason behind the choice of the last two lines of the
code?
Buy = 0; // this works ok alone
Buy =C> 0; // this works ok alone
Filter=Buy; // what is this for?
5) In case you needed it one day here is the code that exports the
data from all symbols together to one ASCii file (T,mdyyyy,OHLCV).
The only catch is that you would have to delete that file before
running the procedure (or clear any old data already in the file). I
didn't have time to try to automate it at this point.
/***************
Export Eod Data In Metastock Format: TD_mmddyyyy_OHLCV
1) Execution: AA - ApplyTo (set "filters") - Date Range (doesn't
work) - Scan
2) The code exports the data to C:\Test\MS_Eod.csv
3) If the directory doesn't exist it will be created automatically
***************/
folder = "C:\\Test";
fmkdir( folder );
fh = fopen( folder + "\\" + "MS_Eod.txt", "a");
if (fh)
{
t = Name();
p = "D";
y = Year();
m = Month();
d = Day();
for( i = 0; i < BarCount; i++ )
{
fputs( t + "," , fh );
fputs( p + "," , fh );
ds = StrFormat("%02.0f/%02.0f/%02.0f,", m[i], d[i], y[i] );
fputs( ds, fh );
qs = StrFormat("%.4f, %.4f, %.4f, %.4f, %.0f\n", O[i], H[i], L[i],
C[i], V[i] );
fputs( qs, fh );
}
fclose( fh );
}
Buy = 0;
/**********************/
--- In amibroker@xxxxxxxxxxxxxxx, Rakesh Sahgal <rakeshsahgal@xxxx>
wrote:
> Lesmond,
>
> Code below works.I checked it from export to
> conversion IN MS DLoader.
>
> Thanks once again Graham for sharing your work.
>
>
> Regards
>
>
> Rakesh
> /*
> Export intraday and EOD data to TXT files
> One file for each stock
> In the first line insert the directory you want to
> save them to, make sure the
> directory exists
> Select your charts to export with the "Apply to"
> filter in AA window
> Select the timeframe period you want to save as using
> the AA "Settings"
> Press Scan button
> by Graham Kavanagh 05 Feb 2004
> */
>
>
>
>
> fh = fopen(
> "d:\\amibroker\\US_STOCKS_ASCII\\"+Name()+".txt",
> "w");
> if( fh )
> {
> t = Name();
> p = "D";
> y = Year();
> m = Month();
> d = Day();
>
> for( i = 0; i < BarCount; i++ )
> {
> fputs( t + "," , fh );
> fputs(p + "," , fh );
>
> ds = StrFormat("%02.0f/%02.0f/%02.0f,",
> m[ i ], d[ i ], y[ i ]);
> fputs( ds, fh );
>
>
> qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n",
> O[ i ],H[ i ],L[ i ],C[ i ],V[ i
> ] );
> fputs( qs, fh );
> }
>
> fclose( fh );
> }
>
> Buy =C> 0;
>
> Filter=Buy;
>
>
> --- Graham <kavemanperth@xxxx> wrote:
>
> > move the IF into the loop rather than before it
> >
> >
> > On 4/21/05, Lesmond V <ebsn247@xxxx> wrote:
> > >
> > >
> > > Here is another version of Graham's code. It will
> > export the data
> > > to:
> > >
> > > C:\MS_Data\MS_Eod.csv
> > >
> > > in the following format:
> > >
> > >
> >
> Ticker,P,Date,Open,High,Low,Close,Volume,OpenInterest
> > > $SPX,D,2005/04/18,1142.8700, 1148.9200, 1139.8000,
> > 1145.9800, 0, 0
> > > $SPX,D,2005/04/19,1148.7000, 1154.6700, 1148.3000,
> > 1152.7800, 0, 0
> > > $SPX,D,2005/04/20,1153.7200, 1155.5000, 1136.1500,
> > 1137.5000, 0, 0
> > >
> > > To run the code:
> > >
> > > go to AA - ApplyTo:set Filters - Range:disregard -
> > Scan
> > >
> > > Problem:
> > >
> > > If you set the "filter" to let's say a watch list,
> > only the last
> > > symbol from the WL will be exported (with Scan
> > button) and only the
> > > first symbol with Explore button. The same applies
> > to Graham's code
> > > from the previous post. Any ideas how to resolve
> > this are
> > > appreciated.
> > >
> > > /***************
> > > Export Eod Data To Metastock
> > > Based on Graham Kavanagh's code:
> > >
> >
> http://www.amibroker.com/library/detail.php?id=327&hilite=fputs
> > >
> > > 1) Execution: AA - ApplyTo:set Filters -
> > Range:disregard - Scan
> > > 2) There is no option to set the date range (AA
> > "Range" is not linked
> > > to this formula)
> > > 3) The code exports data of the current ticker to
> > > C:\MS_Data\MS_Eod.csv
> > > 4) If the directory doesn't exist it will be
> > created automatically
> > > ***************/
> > >
> > > folder = "C:\\MS_Data";
> > > fmkdir( folder );
> > >
> > > fh = fopen( folder + "\\" + "MS_Eod.csv", "w");
> > > if (fh)
> > > {
> > > fputs(
> >
> "Ticker,P,Date,Open,High,Low,Close,Volume,OpenInterest\n",
> > > fh );
> > > t = Name();
> > > p = "D";
> > > y = Year();
> > > m = Month();
> > > d = Day();
> > > for( i = 0; i < BarCount; i++ )
> > > {
> > > fputs( t + "," , fh );
> > > fputs( p + "," , fh );
> > > ds = StrFormat("%02.0f/%02.0f/%02.0f,", y[i],
> > m[i], d[i] );
> > > fputs( ds, fh );
> > > qs = StrFormat("%.4f, %.4f, %.4f, %.4f, %.0f,
> > %.0f\n", O[i],
> > > H[i], L[i], C[i], V[i], OI[i] );
> > > fputs( qs, fh );
> > > }
> > > fclose( fh );
> > > }
> > > Buy = 0;
> > >
> > > /***************/
> > >
> > > Lesmond
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, Graham
> > <kavemanperth@xxxx> wrote:
> > > > I can only suggest you add in an extra column
> > and have it add the
> > > > letter you want
> > > >
> > > > You could always write an exploration and export
> > the results from
> > > AA window
> > > >
> > > > I have assumed this is what you are loking for
> > > > Here is sample of altered code to add in a D or
> > X for daily or other
> > > >
> > > > x = "C:\\IDData"+ WriteVal(Now(3),1);
> > > >
> > > > fmkdir( x );
> > > >
> > > > Buy=V>0;
> > > >
> > > > if( Interval()==inDaily ) {dt = "D";}
> > > > else{ dt = "X" ;}
> > > >
> > > >
> > > > fh = fopen( x + "\\" +Name()+".txt", "w");
> > > > if( fh )
> > > > {
> > > > fputs(
> >
> "Ticker,Timeframe,Date,Time,Open,High,Low,Close,Volume
> > > \n", fh );
> > > > y = Year();
> > > > m = Month();
> > > > d = Day();
> > > > r = Hour();
> > > > e = Minute();
> > > > n = Second();
> > > >
> > > > for( i = 0; i < BarCount; i++ )
> > > > {
> > > > if( Buy[i] )
> > > > {
> > > > fputs( Name() + "," , fh );
> > > > ds = StrFormat("%02.0f-%02.0f-%02.0f,",
> > > > y[ i ], m[ i ], d[ i ] );
> > > > fputs( ds, fh );
> > > > fputs( dt + "," , fh );
> > > >
> > > > ts = StrFormat("%02.0f:%02.0f:%02.0f,",
> > > > r[ i ],e[ i ],n[ i ] );
> > > > fputs( ts, fh );
> > > >
> > > > qs =
> > StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n",
> > > > O[ i ],H[ i ],L[ i ],C[ i
> > ],V[ i ] );
> > > > fputs( qs, fh );
> > > > }
> > > > }
> > > > fclose( fh );
> > > > }
> > > >
> > > >
> > > >
> > > > On 4/21/05, Rakesh Sahgal <rakeshsahgal@xxxx>
> > wrote:
> > > > >
> > > > > Hi Graham
> > > > >
> > > > > I want to use the code you shared with the
> > group to
> > > > > export data to MS Format for use in MS.
> > > > >
> > > > > To be able to convert the data I need to
> > indicate the
> > > > > periodicity of the data in each line of data
> > in the
> > > > > file. The periodicity will be indicated by the
> > letter
> > > > > "D" indicating daily data inserted between the
> > ticker
> > > > > and date fields. Can you please guide me
> > through this?
> > > > >
> > > > > TIA
> > > > >
> > > > > Regards
> > > > >
> > > > > Rakesh
------------------------ Yahoo! Groups Sponsor --------------------~-->
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~->
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For other support material please check also:
http://www.amibroker.com/support.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/
|