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

[amibroker] Re: Possible File I/O bug.



PureBytes Links

Trading Reference Links

Hi Tomasz,

Your sample code works and the problem does indeed seem to be with the 
IF statement but there is nothing wrong with the logic.

To demonstrate, 2 pieces if code are below. The only difference 
between them is that I comment/uncomment certain lines that have 
nothing to do with the IF statement's logic, only the file functions.

The 1st piece of code gives an empty file and the 2nd works as 
expected. I don't understand why they are different?

Using AB 4.70.5.

Bill
---
Buy=0;
Sell=0;
indexesL = "dji,ixic,ndx,rut,spx,vay,vlic" ;
indexesU = "DJI,IXIC,NDX,RUT,SPX,VAY,VLIC" ;

filename = "d:\\tmp\\amibroker\\cycles\\test.dat" ;
fh = fopen( filename, "w") ;
for (j=0; j<7; j++)
{
  idx = StrExtract( indexesL , j ) ;
  if ( Name() == "^"+StrExtract( indexesU , j ) )
  {
	idx = StrExtract( indexesL , j ) ;
	s = StrFormat( ", %f\n", j) ;
//	if (j==0)
//      fh = fopen( filename, "w") ;
//    else
//     fh = fopen( filename, "a") ;
    if(fh)
    {
      fputs(Name() + ", " + idx + s, fh ) ;
//      fclose(fh) ;
    }
  }
}
fclose(fh) ;
---
Buy=0;
Sell=0;
indexesL = "dji,ixic,ndx,rut,spx,vay,vlic" ;
indexesU = "DJI,IXIC,NDX,RUT,SPX,VAY,VLIC" ;

filename = "d:\\tmp\\amibroker\\cycles\\test.dat" ;
//fh = fopen( filename, "w") ;
for (j=0; j<7; j++)
{
  idx = StrExtract( indexesL , j ) ;
  if ( Name() == "^"+StrExtract( indexesU , j ) )
  {
	idx = StrExtract( indexesL , j ) ;
	s = StrFormat( ", %f\n", j) ;
	if (j==0)
      fh = fopen( filename, "w") ;
    else
     fh = fopen( filename, "a") ;
    if(fh)
    {
      fputs(Name() + ", " + idx + s, fh ) ;
      fclose(fh) ;
    }
  }
}
//fclose(fh) ;
--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <amibroker@xxxx> 
wrote:
> Hello,
> 
> Both should work. The problem is elsewhere (most probably condition 
if Name() == StrExtract is never met)
> because this sample:
> 
> Buy=0; 
> Sell=0; 
> filename = "highest_tr.dat" ; 
> fh = fopen( filename, "w") ; 
> for (j=0; j<7; j++) 
> { 
>     if(fh) 
>     { 
>       fputs("Test\n", fh ) ; 
>     } 
> } 
> fclose(fh) ; 
> 
> 
> works fine.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message ----- 
> From: "bilbo0211" <bilbod@xxxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Tuesday, June 28, 2005 2:14 AM
> Subject: [amibroker] Possible File I/O bug.
> 
> 
> >I am having a problem with file I/O. I don't know if it is a bug or 
I 
> > am doing something I am not supposed to do.
> > 
> > If I open a file and write to it multiple times in a loop, there 
is no 
> > error but the file is always empty. If I use the same code except 
open 
> > and close the file each time I write to it in the loop, the file 
> > contains the correct data.
> > 
> > What follows are 2 pieces of code that demonstrates the problem. 
1st 
> > is the one that gives the empty file, them the one that gives the 
> > correct data.
> > 
> > Bill
> > ---
> > Buy=0;
> > Sell=0;
> > indexesL = "dji,ixic,ndx,rut,spx,vay,vlic" ;
> > indexesU = "DJI,IXIC,NDX,RUT,SPX,VAY,VLIC" ;
> > 
> > filename = "d:\\tmp\\amibroker\\cycles\\highest_tr.dat" ;
> > fh = fopen( filename, "w") ;
> > for (j=0; j<7; j++)
> > {
> >  idx = StrExtract( indexesL , j ) ;
> >  if ( Name() == "^"+StrExtract( indexesU , j ) )
> >  {
> >    idx = StrExtract( indexesL , j ) ;
> >    s = StrFormat( ",%f\n", LastValue(Highest( ATR( 1 ) ) ) ) ;
> >    if(fh)
> >    {
> >      fputs(idx + s, fh ) ;
> >    }
> >  }
> > }
> > fclose(fh) ;
> > ---
> > Buy=0;
> > Sell=0;
> > indexesL = "dji,ixic,ndx,rut,spx,vay,vlic" ;
> > indexesU = "DJI,IXIC,NDX,RUT,SPX,VAY,VLIC" ;
> > 
> > filename = "d:\\tmp\\amibroker\\cycles\\highest_tr.dat" ;
> > 
> > for (j=0; j<7; j++)
> > {
> >  idx = StrExtract( indexesL , j ) ;
> >  if ( Name() == "^"+StrExtract( indexesU , j ) )
> >  {
> >    idx = StrExtract( indexesL , j ) ;
> >    s = StrFormat( ",%f\n", LastValue(Highest( ATR( 1 ) ) ) ) ;
> >    if (j==0)
> >      fh = fopen( filename, "w") ;
> >    else
> >      fh = fopen( filename, "a") ;
> >    if(fh)
> >    {
> >      fputs(idx + s, fh ) ;
> >      fclose(fh) ;
> >    }
> >  }
> > }
> > ---
> > 
> > 
> > 
> > 
> > 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
> > 
> > 
> > 
> > 
> > 
> > 
> >




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/