PureBytes Links
Trading Reference Links
|
Title: Re: [amibroker] Re: Looping or optimizing a set of non sequential numbers?
I had to write some code to try for myself, it work fine in an indicator:
if ( ParamTrigger( "Test Write File", "WRITE" ) )
{
_TRACE("!CLEAR!");
fh = fopen( "c:\\TestExtractFile03.txt", "w" );
if ( fh )
{
for ( n = 1; n <= 5000; n++ )
{
fputs( NumToStr( n, 1.0 )+"\n", fh );
_TRACE("Write File: "+n);
}
fclose( fh );
}
else PopupWindow("Could bnot open file for writing","File error",3);
}
if ( ParamTrigger( "Test Read File", "READ" ) )
{
_TRACE("!CLEAR!");
fh = fopen( "c:\\TestExtractFile03.txt", "r" );
if ( fh )
{
_TRACE( "File Open" );
Count = 0;
while ( !feof( fh ) )
{
Num1 = StrToNum(fgets( fh ));
StaticVarSet( "Var" + NumToStr(Num1,1.0), Num1 );
num2 = StaticVarGet( "Var" + NumToStr(Num1,1.0) );
_TRACE( "ReadFile:"+num1+", ReadStaticVar: " + num2 );
}
fclose( fh );
}
else PopupWindow("Could not open file for reading","File error",3);
}
if ( ParamTrigger( "Test Read Statics", "READ STATIC" ) )
{
_TRACE("!CLEAR!");
for ( n = 1; n <= 5000; n++ )
{
num = StaticVarGet( "Var" + NumToStr( n, 1.0 ) );
_TRACE( "ReadStaticVar: " + num );
}
}
Tuesday, November 25, 2008, 1:20:59 PM, you wrote:
>
|
Actually...hold on. I posted two versions of the code (one with arrays, and one with static variables) and *both* versions do not capture all the numbers in the text file.
As mentioned, the following version only sees less than 3,000 numbers even though the text file contains 5000. And it uses dynamically named static variables. What is wrong with this code?
Count = 0;
if(Status("ActionEx") == actionExOptimizeSetup)
{
count = 0;
fh = fopen("c:\\TestExtractFile03.txt", "r");
if (fh)
{
while(!feof(fh))
{
StaticVarSet("Row"+NumToStr(Count,1.0,0), StrToNum(fgets(fh)) );
StaticVarSet("Count", Count);
Count++;
}
fclose( fh );
} else
{
printf("ERROR: file can not be found (does not exist)");
}
}
b = Optimize("b", 9, 1, Count, 1);
Count = StaticVarGet("Count");
for(a = 0; a < Count; a++)
{
Row = StaticVarGet("Row"+NumToStr(a,1.0,0));
printf("Row: %g\n", Row );
}
Buy = a == 12; // random buy/sell conditions for test purposes
Sell = a == 2;
--- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@xxx> wrote:
>
> Ah! That must be it. I was confused why I was sometimes seeing
> subscript out of range errors based on barcount, even though I was not
> actually referencing any bars. I didn't realize that even non-bar
> based arrays are also limited to barcount. Kinda weird that such would
> be the case, but guess it's one of the quirks.
>
|
__._,_.___
**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
*********************
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
*********************************
__,_._,___
|