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

[amibroker] Re: Code needed - fopen fget - use csv file as input ?



PureBytes Links

Trading Reference Links

One slight edit. In the following line I needed to change the "," to "\n", else a ,1 is equal to ,10 or ,100. working Great

    return StrFind( ids, "," + id + "\n," );


amibroker@xxxxxxxxxxxxxxx, "gmorlosky" <gmorlosky@xxx> wrote:
>
> Hi Mike;
> I figured it out, THANKS to all your help. The creation of the ids file has a format that includes an end of line on each line and it is counted as a position, SO if I expect token 4 it is actually finding 13 as the position, when I reset the StrFind code to not include the last ",", because that found nothing. Therfore I coded the filter for > 0 (meaning the number was found), then it works
> 
> return StrFind( ids, "," + id /* + "," */ ); // removed last comma
> ,0 // 0,1,2
> ,1 // 3,4,5
> ,2 // 6,7,8
> ,3 // 9,10,11
> ,4 // 12,13
> 
> I then tested against the following and it worked great.
> ,0
> ,2
> ,20
> ,200
> 
> Below is the working code:
> 
> _SECTION_BEGIN("ReadingCSV Function");
> Title = "ReadingCSV Function";
> IndID = 0;
> IID = 0;
> ids = "";
> function IncludeIndustry( id )
> {
>     local ids;
>     local fh;
>     ids = ",";
>     fh = fopen( "C:\\AmiBroker CSV\\ABTest.csv", "r" );
>     if ( fh )
> {
>     while ( !feof( fh ) )
>     {
>         ids += fgets( fh );
>         ids += ",";
>     }
>     fclose( fh );
>         printf( ids );
> }
> //    return StrFind( "," + id + "," , ids); // original code
>     return StrFind( ids, "," + id /* + "," */ );
> }
> //Filter = IncludeIndustry( IndustryID() ); // original code
> IID = IndustryID();
> RID = IncludeIndustry( IndustryID() );
> Match = IIf(RID > 0,1,0);
> Filter = Match;
> Check = IndustryID() == RID;
> Buy = Close >= 0;
> Sell = Close == 0;
> AddColumn ( Buy,"Buy" );
> AddColumn ( Sell,"Sell" );
> AddColumn ( Close,"Close" );
> AddTextColumn( FullName(),"FullName" );
> AddColumn( IndustryID(), "IndId" );
> AddColumn( Check, "Check" );
> _TRACE ("IID: "+ IID  +"  RID: "+ RID +"  IDS: "+ IDS+"  Match: "+ Match);
> _SECTION_END();
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "gmorlosky" <gmorlosky@> wrote:
> >
> > I started using _TRACE and find that the only number that comes back from "IndustryID() == IncludeIndustry( IndustryID() )" is 0, therefore IndustryID == 0 works, but all others fail.
> > Wondering if the problem is with the format of the created IDs file or the read of the IDs file ???
> > 
> > Any thoughts
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "gmorlosky" <gmorlosky@> wrote:
> > >
> > > Here is the latest code, but it still is displaying in an Explore only IndustryID() == 0.
> > > I did make 2 changes to the code:
> > > 1) flipped the StrFind parameters
> > > 2) expanded the Filter to include IndustryID() ==
> > > 3) Commentary display of printf(ID) looks like this:
> > > 
> > >  ,,0
> > >  ,1
> > >  ,2
> > >  ,3
> > >  ,4
> > >  ,5
> > >  ,6
> > >  ,7
> > >  ,8
> > >  ,9
> > >  ,10
> > >  ,,
> > > 
> > > 
> > > 
> > > _SECTION_BEGIN("ReadingCSV Function");
> > > Title = "ReadingCSV Function";
> > > id = 0;
> > > function IncludeIndustry( id )
> > > {
> > >     local ids;
> > >     local fh;
> > > 
> > >     ids = ",";
> > >     fh = fopen( "C:\\AmiBroker CSV\\ABTest.csv", "r" );
> > > 
> > >     if ( fh )
> > > {
> > >     while ( !feof( fh ) )
> > >     {
> > >         ids += fgets( fh );
> > >         ids += ",";
> > >         printf( ids );
> > >     }
> > >     fclose( fh );
> > > }
> > > //    return StrFind( "," + id + "," , ids); // original code
> > >     return StrFind( ids, "," + id + "," );
> > > }
> > > 
> > > //Filter = IncludeIndustry( IndustryID() ); // original code
> > > Filter = IndustryID() == IncludeIndustry( IndustryID() );
> > > 
> > > Buy = Close >= 0;
> > > Sell = Close == 0;
> > > AddColumn ( Buy,"Buy" );
> > > AddColumn ( Sell,"Sell" );
> > > AddColumn ( Close,"Close" );
> > > AddTextColumn( FullName(),"FullName" );
> > > AddColumn( id, "Id" );
> > > _SECTION_END();
> > >
> >
>




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

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

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> 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/