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 [email protected], "gmorlosky" <gmorlo...@...> 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 [email protected], "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();
> >
>


Reply via email to