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

[amibroker] InWatchListName Help (was Re: InWatchList help)



PureBytes Links

Trading Reference Links

GP,

Thanks!  Bar-by-bar in the backtest is what I have in mind.

This subset of code does the job:
////////////////////
yyyy = Year();
inwl = False;
for ( bar = 0; bar < BarCount; bar++ )
{
  inwl[bar] = InWatchListName( "NDX_" + NumToStr( yyyy[bar], 1.0, 0 ) );
}
////////////////////

Whitney

--- In amibroker@xxxxxxxxxxxxxxx, "gp_sydney" <gp.investment@xxx> wrote:
>
> What exactly do you mean by "current bar"? Do you want it to be
> determined on a bar-by-bar basis during a backtest, of just on the bar
> pointer (selected bar)? What you have is correct for the latter, and
> what you're seeing is the expected result. When you pass an array to
> NumToStr, it will only use the selected bar (ie. the bar pointer bar),
> so the whole chart will show the one value depending on which bar you
> selected.
> 
> If you want it to be determined bar by bar throughout the array, then
> I think this might need a loop, as you can't create arrays of strings
> in AFL. Something like this:
> 
> currYear = 0;
> yr = Year();
> inwl = False;
> for (i = 0; i < BarCount-1; i++)
> {
>     if (yr[i] != currYear)
>     {
>         currYear = yr[i];
>         inwl[i] = InWatchListName("NDX_"+NumToStr(currYear,1.0,0));
>     }
>     else
>         inwl[i] = inwl[i-1];
> }
> 
> I haven't tried this code, but it looks like what I think you want.
> 
> A couple of other comments about your code:
> 
> >> yearstr = StrReplace( NumToStr( yyyy, fint ), ",", "" );
> 
> To remove the comma, just set the third parameter of NumToStr to False
> (or zero).
> 
> >> inwl = iif( InWatchListName( watchlistname ), 1, 0 );
> 
> This is equivalent to:
> 
> inwl = InWatchListName(watchlistname);
> 
> Regards,
> GP
> 
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "whitneybroach" <WhitneyBroach@>
> wrote:
> >
> > Here's a variation of the same idea.  The way that results are being
> > reported in the chart window and in AA is not reassuring.  I must be
> > missing something obvious.
> > 
> > I have watchlists named "NDX_2002" and "NDX_2003" etc.
> > 
> > The year of the current bar is to identify the proper watchlist.  If
> > today is 19970102, NDX_1997 is the correct watchlist to check.  If
> > today is 19961231, NDX_1996 is the correct watchlist to check.
> > 
> > Vector_Desired:  If symbol is in year-selected watchlist, a trade can
> > be taken; else no trade.  I need inwl to be Vector_Desired.
> > 
> > The plot of inwl (from code below) is either all 1's or all 0's from
> > the left of the chart window to the right, depending on where the bar
> > pointer is.
> > 
> > For example, suppose the current symbol is in NDX_1997 and not in
> > NDX_1996.  The last bar of 1996 is 19961231.  The first bar of 1997 is
> > 19970102.  When the bar pointer is on 19961231, the histogram is at
> > zero from the leftmost bar to the rightmost bar of the chart window. 
> > When I move the bar pointer one bar to the right with the
> > right-arrow key, to 19970102, the histogram displays 1 on every bar
> > visible in the chart window (not correct).
> > 
> > What am I missing?
> > 
> > /////////////////
> > fint  = 1.0;
> > yyyy = Year();
> > yearstr = StrReplace( NumToStr( yyyy, fint ), ",", "" );
> > watchlistname = "NDX_" + yearstr;
> > inwl = iif( InWatchListName( watchlistname ), 1, 0 );
> > Plot( inwl, "inwl", colorDefault, styleHistogram + styleOwnScale,
0, 2);
> > /////////////////
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "HB" <hmab@> wrote:
> > >
> > > MessageThanks Graham.  That was it !
> > > 
> > > I ended up using the following code:
> > > 
> > > //////////////////////////////
> > > 
> > > // Date conditions
> > > ZeroKH1 = IIf(today>=1000101 AND today <=1000630, 7,0);
> > > ZeroKH2 = IIf(today>=1000701 AND today <=1001231, 9,0);
> > > OneKH1 = IIf(today>=1010101 AND today <=1010630, 11,0);
> > > OneKH2 = IIf(today>=1010701 AND today <=1011231, 13,0);
> > > TwoKH1 = IIf(today>=1020101 AND today <=1020630, 15,0);
> > > TwoKH2 = IIf(today>=1020701 AND today <=1021231, 17,0);
> > > 
> > > // Watchlist membership
> > > wl7 = InWatchList(7);
> > > wl9 = InWatchList(9);
> > > wl11 = InWatchList(11);
> > > wl13 = InWatchList(13);
> > > wl15 = InWatchList(15);
> > > wl17 = InWatchList(17);
> > > 
> > > // Ticker is in right date range and is a member of the right
> watchlist
> > > rightWL = (ZeroKH1 AND wl7) OR (ZeroKH2 AND wl9) OR (OneKH1 AND
> > wl11) OR (OneKH2 AND wl13) OR (TwoKH1 AND wl15) OR (TwoKH2 AND wl17);
> > > 
> > > //////////////////////////////
> > > 
> > > I know the two sets of conditions be combined but I spell it out for
> > my own benefit/understanding.
> > > 
> > > HB
> > >   ----- Original Message ----- 
> > >   From: Graham 
> > >   To: amibroker@xxxxxxxxxxxxxxx 
> > >   Sent: Tuesday, December 16, 2003 9:32 PM
> > >   Subject: RE: [amibroker] InWatchList help
> > > 
> > > 
> > >   you could just use the watchlist numbers and have added
> > conditional statements
> > > 
> > >   cond1 = datenum()>1000101 and datenum()<1000701;
> > >   cond2 = inwatchlist(7);
> > >   cond3 = inwatchlist(9);
> > >   Buy = Buyconditions AND ( ( cond1 and cond2 ) or cond3 );//have
> > added or etc as variety
> > > 
> > >   or if you only have a single watchlist
> > > 
> > >   cond1 = datenum()>1000101 and datenum()<1000701;
> > >   Buy = Buyconditions AND InWatchList(7) and cond1; 
> > >   Cheers,
> > >   Graham
> > >   http://groups.msn.com/asxsharetrading
> > >   http://groups.msn.com/fmsaustralia 
> > > 
> > >     -----Original Message-----
> > >     From: HB [mailto:hmab@] 
> > >     Sent: Wednesday, 17 December 2003 10:13 AM
> > >     To: amibroker@xxxxxxxxxxxxxxx
> > >     Subject: Re: [amibroker] InWatchList help
> > > 
> > > 
> > >     Jayson, Graham, & Andrew,
> > > 
> > >     Thanks for your tips.
> > > 
> > >     Let me give me more details as to how I want to use this.  When
> > backtesting, I need to determine, for each bar, if this ticker is part
> > of a certain watch list.  If so, then I will accept the buy signal,
> > otherwise on.
> > > 
> > >     In my code sample, if the current bar is in the first half of
> > year 2000, then tickers need to be in watchlist 7 in order to accept
> > buy signals.  If the current bar is in the second half of year 2000,
> > then tickers need to be in watchlist 9 in order to accept buy
signals.  
> > > 
> > >     I was hoping to do something like:
> > > 
> > >     Buy = Buyconditions AND InWatchList(wlnum);
> > > 
> > >     So, in this case, is the solution to use Andrew's first code
> > snippet ?  Or is there a simpler way to do this ?
> > > 
> > >     Thanks,
> > >     HB
> > > 
> > >       ----- Original Message ----- 
> > >       From: Andrew Perrin 
> > >       To: amibroker@xxxxxxxxxxxxxxx 
> > >       Sent: Tuesday, December 16, 2003 8:34 PM
> > >       Subject: Re: [amibroker] InWatchList help
> > > 
> > > 
> > >       HB
> > >       I believe the problem is that the function InWatchlist( ) does
> > not accept an array as arguments.  A solution is to specify array
> > elements.
> > > 
> > >      
> > ///////////////////////////////////////////////////////////////////// 
> > >       // returns 1 if Ticker in Given watchlist on specified date //
> > >      
> > //////////////////////////////////////////////////////////////////// 
> > >       StartBar = LastValue( ValueWhen( Status("firstbarinrange"),
> > BarIndex() ) );
> > >       FinishBar = LastValue( ValueWhen( Status("lastbarinrange"),
> > BarIndex() ) ); 
> > >       today = DateNum();
> > >       i = StartBar;
> > >       while (i <= FinishBar)
> > >       {
> > >       ZeroKH1[i] = IIf(today[i]>=1000101 AND today[i] <=1000630,
7,0);
> > >       ZeroKH2[i] = IIf(today[i] >=1000701 AND today[i] <=1001231,
> 9,0);
> > >       wlnum[i] = ZeroKH1[i] + ZeroKH2[i];
> > >       inWL[i] = InWatchList(wlnum[i]);
> > >       i = i + 1;
> > >       }
> > >       Filter = 1;
> > >       AddColumn(InWL,"inWL",1.0);
> > > 
> > >       This will work,  it will however compare ticker to watchlist
> > num 1 outside of the dates specified and will give a true result if
> > Watchlist 1 does contain ticker.
> > >       Another solution that may overcome this is to use nested IIf
> > statements.
> > > 
> > >      
> > ///////////////////////////////////////////////////////////////////// 
> > >       // returns 1 if Ticker in Given watchlist on specified date //
> > >      
> > //////////////////////////////////////////////////////////////////// 
> > >       StartBar = LastValue( ValueWhen( Status("firstbarinrange"),
> > BarIndex() ) );
> > >       FinishBar = LastValue( ValueWhen( Status("lastbarinrange"),
> > BarIndex() ) ); 
> > >       today = DateNum();
> > >       WL1 = 1; // first period watchlist 
> > >       WL2 = 2; // second period watchlist
> > >       WLempty = 56; // specify an empty watchlist
> > >       i = StartBar;
> > >       while (i <= FinishBar)
> > >       {
> > >           wlnum[i] =     IIf(today[i] >=1000101 AND today[i]
> > <=1000630, WL1,
> > >                               IIf(today[i] >=1000701 AND today[i]
> > <=1001231, WL2, WLempty));
> > >           inWL[i] = InWatchList(wlnum[i]);
> > >           i = i + 1;
> > >       }
> > >       Filter = 1;
> > >       AddColumn(InWL,"inWL",1.0);
> > > 
> > >       If you are doing something more complex in this area, perhaps
> > the following AFL might help.  Watchlist were set up to reflect the
> > composition of certain indexes at 6 mth intervals. Tickers were
> > selected that were part of the index at the start of each six month
> > period.
> > > 
> > >       Hope this helps, watch those line returns,
> > > 
> > >       Andrew
> > > 
> > > 
> > >      
> >
>
////////////////////////////////////////////////////////////////////////////////////////////////
> > >       // ASX300/ASX200 returns 1 if Ticker in ASX300/ASX200 in given
> > month. (Range 2000 on). //
> > >      
> >
>
////////////////////////////////////////////////////////////////////////////////////////////////
> > >       StartBar = LastValue( ValueWhen( Status("firstbarinrange"),
> > BarIndex() ) );
> > >       FinishBar = LastValue( ValueWhen( Status("lastbarinrange"),
> > BarIndex() ) ); 
> > >       Yr = Year();
> > >       Mth = Month();
> > >       Ticker = Name();
> > >       i = StartBar;
> > >       while (i <= FinishBar)
> > >       {
> > >       WatchlistNum[i] =     IIf(Yr[i] ==2000, IIf(Mth[i] <7, 30,31),
> > >                                       IIf(Yr[i] ==2001, IIf(Mth[i]
> > <7, 32,33),
> > >                                       IIf(Yr[i] ==2002, IIf(Mth[i]
> > <7, 34,35),
> > >                                       IIf(Yr[i] ==2003, IIf(Mth[i]
> > <7, 36,37),39))));
> > >           InASX300[i] = InWatchList( WatchlistNum[i] );
> > >       WatchlistNum[i] =     IIf(Yr[i] ==2000, IIf(Mth[i] <7, 40,41),
> > >                                       IIf(Yr[i] ==2001, IIf(Mth[i]
> > <7, 42,43),
> > >                                       IIf(Yr[i] ==2002, IIf(Mth[i]
> > <7, 44,45),
> > >                                       IIf(Yr[i] ==2003, IIf(Mth[i]
> > <7, 46,47),49))));
> > >           InASX200[i] = InWatchList( WatchlistNum[i] );
> > >       i = i + 1;
> > >       }
> > >       Filter = InASX300;
> > >       AddColumn(InASX300,"in ASX300");
> > >       AddColumn(InASX200,"on ASX200");
> > > 
> > > 
> > >       ----- Original Message ----- 
> > >         From: HB 
> > >         To: amibroker@xxxxxxxxxxxxxxx 
> > >         Sent: Wednesday, December 17, 2003 6:21 AM
> > >         Subject: [amibroker] InWatchList help
> > > 
> > > 
> > >         Hello,
> > > 
> > >         I'm getting an error with the last line of following code. 
> > Something about a bad argument.  Can someone please help.
> > > 
> > >         //////////////////////////////////////
> > > 
> > >         today = DateNum();
> > > 
> > >         ZeroKH1 = IIf(today>=1000101 AND today <=1000630, 7,0);
> > >         ZeroKH2 = IIf(today>=1000701 AND today <=1001231, 9,0);
> > > 
> > >         wlnum = ZeroKH1 + ZeroKH2;
> > > 
> > >         Filter = 1;
> > > 
> > >         AddColumn(InWatchList(wlnum),"inWL",1.0);
> > > 
> > >         //////////////////////////////////////
> > > 
> > >         Thanks,
> > >         HB
> > > 
> > > 
> > >         Send BUG REPORTS to bugs@
> > >         Send SUGGESTIONS to suggest@
> > >         -----------------------------------------
> > >         Post AmiQuote-related messages ONLY to:
> > amiquote@xxxxxxxxxxxxxxx 
> > >         (Web page: http://groups.yahoo.com/group/amiquote/messages/)
> > >         --------------------------------------------
> > >         Check group FAQ at:
> > http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
> > > 
> > > 
> > > 
> > > 
> > >
> ------------------------------------------------------------------------
> > >         Yahoo! Groups Links
> > > 
> > >           a.. To visit your group on the web, go to:
> > >           http://groups.yahoo.com/group/amibroker/
> > >             
> > >           b.. To unsubscribe from this group, send an email to:
> > >           amibroker-unsubscribe@xxxxxxxxxxxxxxx
> > >             
> > >           c.. Your use of Yahoo! Groups is subject to the Yahoo!
> > Terms of Service. 
> > > 
> > > 
> > > 
> > > 
> > >       Send BUG REPORTS to bugs@
> > >       Send SUGGESTIONS to suggest@
> > >       -----------------------------------------
> > >       Post AmiQuote-related messages ONLY to:
> amiquote@xxxxxxxxxxxxxxx 
> > >       (Web page: http://groups.yahoo.com/group/amiquote/messages/)
> > >       --------------------------------------------
> > >       Check group FAQ at:
> > http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
> > > 
> > > 
> > > 
> > >
> >
>
--------------------------------------------------------------------------
> > >       Yahoo! Groups Links
> > > 
> > >         a.. To visit your group on the web, go to:
> > >         http://groups.yahoo.com/group/amibroker/
> > >           
> > >         b.. To unsubscribe from this group, send an email to:
> > >         amibroker-unsubscribe@xxxxxxxxxxxxxxx
> > >           
> > >         c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms
> > of Service. 
> > > 
> > > 
> > > 
> > > 
> > >     Send BUG REPORTS to bugs@
> > >     Send SUGGESTIONS to suggest@
> > >     -----------------------------------------
> > >     Post AmiQuote-related messages ONLY to:
amiquote@xxxxxxxxxxxxxxx 
> > >     (Web page: http://groups.yahoo.com/group/amiquote/messages/)
> > >     --------------------------------------------
> > >     Check group FAQ at:
> > http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
> > > 
> > > 
> > > 
> > >
> >
>
----------------------------------------------------------------------------
> > >     Yahoo! Groups Links
> > > 
> > >       a.. To visit your group on the web, go to:
> > >       http://groups.yahoo.com/group/amibroker/
> > >         
> > >       b.. To unsubscribe from this group, send an email to:
> > >       amibroker-unsubscribe@xxxxxxxxxxxxxxx
> > >         
> > >       c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms
> > of Service. 
> > > 
> > > 
> > > 
> > > 
> > >   Send BUG REPORTS to bugs@
> > >   Send SUGGESTIONS to suggest@
> > >   -----------------------------------------
> > >   Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
> > >   (Web page: http://groups.yahoo.com/group/amiquote/messages/)
> > >   --------------------------------------------
> > >   Check group FAQ at:
> > http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
> > > 
> > > 
> > > 
> > >
> >
>
------------------------------------------------------------------------------
> > >   Yahoo! Groups Links
> > > 
> > >     a.. To visit your group on the web, go to:
> > >     http://groups.yahoo.com/group/amibroker/
> > >       
> > >     b.. To unsubscribe from this group, send an email to:
> > >     amibroker-unsubscribe@xxxxxxxxxxxxxxx
> > >       
> > >     c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> > Service.
> > >
> >
>



------------------------------------

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 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
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> 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/