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

Re: [amibroker] Re: Backtesting Market Timing Signals



PureBytes Links

Trading Reference Links

Hi Bill,

ValueWhen function returns an array, which is assigned to Index. So Index is 
an array rather than a single number. I haven't read through all your code, 
but the typical solution for this problem is to use the LastValue function 
to return only the last value of the array as a number, for example:

Index = LastValue( ValueWhen( DateNum() == numdate, BarIndex(), 1 ));

Steve

----- Original Message ----- 
From: "bilbo0211" <bilbod@xxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Tuesday, March 08, 2005 4:29 PM
Subject: [amibroker] Re: Backtesting Market Timing Signals


>
>
> Hi Herman,
>
> Thanks for posting the code. It helped me write my program more
> succinctly.
>
> However, I am still getting the same error.
>
> I discovered I can write debugging info to a file so now I can debug
> the code.
>
> Here is the problem:
> ---
> Index = ValueWhen( DateNum() == numdate, BarIndex(), 1 );
>
> Buy[Index];
> ----------^
>
> Error 6.
> Array subscript has to be a number
> ---
>
> The debugging value for Index is 201. If I write:
>
> Buy[201]=1;
>
> There is no error but
>
> Buy[Index];
>
> gives the above error. I don't understand why or how to fix it?
>
> New program listed below.
>
> Bill
>
> ---
> function Date_To_Num( mm_dd_yyyy )
> {
>  mm_ = StrToNum( StrLeft( mm_dd_yyyy,2 ) );
>  dd_ = StrToNum( StrMid( mm_dd_yyyy,3,2 ) );
>  yy_ = StrToNum( StrMid( mm_dd_yyyy,6,4 ) );
>  Date_Num = ( 10000 * ( yy_ - 1900 ) ) + ( 100 * mm_ ) + dd_;
>  RESULT = Date_Num;
>  return RESULT;
> }
>
> function getSignalString(fh)
> {
>  if( ! feof( fh ) )
>    result = fgets( fh );
>  else
>    result = "none";
>  return result;
> }
>
> filename = "d:\\my programs\\amibroker\\fssignals";
> fh = fopen( filename, "r" );
> signalString = getSignalString(fh);
> sig=StrExtract( signalString,0 );
> txtdate = StrExtract( signalString,1 );
> numdate = Date_To_Num( txtdate );
> Index = ValueWhen( DateNum() == numdate, BarIndex(), 1 );
> Buy=Sell=0;
>
> while ( signalString != "none" )
> {
>  if ( sig == "B" )
>    Buy[Index] = 1;
>  else
>  {
>    if ( sig == "S" )
>      Sell[Index] = 1;
>    else
>      printf("error in %s", filename);
>  }
>  signalString = getSignalString(fh);
>  sig=StrExtract( signalString,0 );
>  txtdate = StrExtract( signalString,1 );
>  numdate = Date_To_Num( txtdate );
>  Index = ValueWhen( DateNum() == numdate, BarIndex(), 1 );
> }
> fclose(fh);
>
> Plot(Buy,"BUY",5,2);
> Plot(Short,"short",4,2);
>
> Title = BuySignal+"\n"+SellSignal;
> ---
>
>
>
>
>
>
> 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
>
>
>
>
>
>
>
> 




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Has someone you know been affected by illness or disease?
Network for Good is THE place to support health awareness efforts!
http://us.click.yahoo.com/Rcy2bD/UOnJAA/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/