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

[amibroker] Re: Backtesting Market Timing Signals



PureBytes Links

Trading Reference Links


Hi Steve,

That's probably the reason I was getting the error. I changed the code
to what is below and it now works OK.

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 );
DateNumber = DateNum();
FirstBar = LastValue( ValueWhen( Status( "firstbarinrange"
),BarIndex() ) );
Buy=Short=0;

for ( i=FirstBar; i<BarCount; i++ )
{
  s1=StrFormat( "%1.0f",numdate );
  s2=StrFormat( "%1.0f",DateNumber[i] );
  cond = numdate == DateNumber[i];
  if ( sig=="B" AND cond )
    Buy[i] = 1;
  if ( sig=="S" AND cond )
    Short[i] = 1;
  if ( Buy[i] OR Short[i] )
  {
    signalString = getSignalString( fh );
    if ( signalString !="none" )
    {
      sig=StrExtract( signalString,0 );
      txtdate = StrExtract( signalString,1 );
      numdate = Date_To_Num( txtdate );
    }
  }
}
fclose( fh );
Sell=Short;
Cover=Buy;
---

--- In amibroker@xxxxxxxxxxxxxxx, "Steve Dugas" <sjdugas@xxxx> wrote:
> 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@xxxx>
> 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 --------------------~--> 
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/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/