{"id":990,"date":"2014-12-23T04:21:58","date_gmt":"2014-12-23T09:21:58","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=990"},"modified":"2015-01-06T05:12:09","modified_gmt":"2015-01-06T10:12:09","slug":"using-multiple-watchlists-as-a-filter-in-the-analysis","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2014\/12\/23\/using-multiple-watchlists-as-a-filter-in-the-analysis\/","title":{"rendered":"Using multiple watchlists as a filter in the Analysis"},"content":{"rendered":"

The Filter window<\/a><\/strong> in the Analysis screen allows us to define a filter for symbols according to category assignments, for example watchlist members (or a result of mutliple criteria search).<\/p>

The filter allows us to select one watch list for “inclusion” and one for “exclusion”. To include members of more than one watchlist, we can not simply pick them both in the Filter window – we need to combine these symbols together in another dedicated watchlist storing symbols from both lists.<\/p>

Let us say we want to run a test on members of List 1<\/strong> and List 2<\/strong>. To combine these watchlists together we need to follow the instructions below.<\/p>

  1. Click on List 1<\/strong>, then in the bottom part of the Symbols<\/strong> window mark all tickers. A multiple selection is done by clicking on first and last item in the list while holding down the Shift<\/strong> key. We may also select all symbols by clicking on any symbol and pressing Ctrl+A<\/strong> key.

    \"Select<\/p>

  2. Now click on the selection with right<\/strong> mouse button and choose Watch list->Add selected symbol(s)<\/strong>

    \"Add<\/p>

  3. Pick an empty watchlist that we will use to combine our tickers (e.g. List 5<\/strong> ) and confirm to add multiple symbols:

    \"Confirm<\/p>

  4. Repeat the above steps 1-3 with List 2<\/strong> members
  5. Now we can pick List 5<\/strong> in the Filter<\/strong> window and run the test on all the tickers

    \"Create<\/ol>

    An alternative solution to this is to filter out unwanted symbols in the code. In this case AmiBroker would need to run analysis for all tickers (so Apply to<\/strong> would need to be set to All symbols<\/strong>) and apply filtering while executing your formula. To do so you may use code like this for backtesting (filtering Buy<\/strong> signals):<\/p>Buy <\/span>= <\/span>\/* your regular trading rules here *\/<\/span>;

    <\/span>watchlistCheck <\/span>= <\/span>InWatchList<\/span>( <\/span>1 <\/span>) OR <\/span>InWatchList<\/span>( <\/span>2 <\/span>);
    <\/span>Buy <\/span>= <\/span>watchlistCheck  <\/span>AND <\/span>Buy<\/span>; <\/span>\/\/ combine watch list filter with your rule<\/code>

    or code like this in exploration (adding extra condition to Filter variable):<\/p>Filter <\/span>= <\/span>\/* your regular exploration filter here *\/<\/span>;
    <\/span>watchlistCheck <\/span>= <\/span>InWatchList<\/span>( <\/span>1 <\/span>) OR <\/span>InWatchList<\/span>( <\/span>2 <\/span>);
    <\/span>Filter <\/span>= <\/span>watchlistCheck <\/span>AND <\/span>Filter<\/span>; <\/span>\/\/ combine watch list filter with your rule<\/code>

    Please keep in mind that filtering in the code is significantly slower. Using this method AmiBroker needs to read the data for all tickers, prepare arrays, then evaluate the formula and verify the condition – so using Filter window<\/strong> and the first approach will be faster, as the filtering is done before the formula execution, saving lots of time required for data retrieval and AFL execution.<\/p>","protected":false},"excerpt":{"rendered":"

    The Filter window in the Analysis screen allows us to define a filter for symbols according to category assignments, for example watchlist members (or a result of mutliple criteria search).The filter allows us to select one watch list for “inclusion” and one for “exclusion”. To include members of more than one watchlist, we can not […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[57],"tags":[53,14,15,28,24],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/990"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=990"}],"version-history":[{"count":2,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/990\/revisions"}],"predecessor-version":[{"id":1002,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/990\/revisions\/1002"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}