LogoLogo
Return to StockChartsCharts & ToolsArticlesChartSchoolYour Dashboard
  • Support Center
  • Finding Your Way Around
    • Intro to StockCharts
    • Navigating the Website
    • Logging In for the First Time
    • Members Dashboard
  • data and ticker symbols
    • Data Availability
      • Markets We Cover
      • Real-Time Data
        • BATS Real-Time Data
      • Extended Hours Data
      • Data Bar Periods
      • Price Data Adjustments
      • Historical Data
        • How Do I Download Data to Excel?
        • StockCharts Historical Sector Data
    • Ticker Symbols
      • Ticker Symbol Conventions
      • How to Find a Ticker Symbol
      • Using the Index Catalog
      • Ratio and Difference Symbols
      • Pseudo-Symbols
      • User-Defined Indexes
  • Charts & Tools
    • SharpCharts
      • SharpCharts Workbench
        • Creating and Viewing SharpCharts
        • Printing and Sharing SharpCharts
        • Editing SharpCharts
          • Using the SharpCharts Interactive Date Slider
          • Charting Market Breadth Indicators
          • SharpCharts Parameter Reference
        • Saving SharpCharts
        • Additional SharpCharts Workbench Tools
          • Viewing ChartLists on the SharpCharts Workbench
          • Viewing Alerts on the SharpCharts Workbench
          • Viewing Options Data on the SharpCharts Workbench
      • ChartStyles & StyleButtons
        • Working with ChartStyles and StyleButtons
        • Using the ChartStyle Library
        • Tool-Specific ChartStyles
      • ChartNotes
        • Annotating SharpCharts with ChartNotes
        • ChartNotes Annotation Tool Reference
          • Line Tools
          • Text Annotation Tools
          • Shape Tools
          • Line Study Tools
      • ChartLists
        • Summary View
        • ChartList View
        • ChartBook View
        • Performance View
        • Correlation View
        • Edit View
        • ChartList Reports
        • ChartPacks
      • Classic SharpCharts Workbench
      • StockCharts Mobile App
    • StockChartsACP
      • Creating ACP Charts
      • Multi-Chart Layouts in StockChartsACP
      • Viewing ACP Charts
      • Printing and Sharing ACP Charts
      • Editing ACP Charts
      • Applying Chart Templates to ACP Charts
      • Annotating ACP Charts
        • StockChartsACP Line Tools
        • StockChartsACP Text Annotation Tools
        • StockChartACP Shape Tools
        • StockChartsACP Line Study Tools
      • Working with Saved ACP Charts
      • StockChartsACP Plug-Ins
        • Chaikin Power Gauge Plug-In
        • GoNoGo Charts Plug-In
        • Larry Williams Stock Trading Starter Pack Plug-In
        • MarketGauge Plug-Ins
        • Simpler Trading Moxie Indicator Plug-In
        • Trading Simplified by Dave Landry
        • Trend Investor Pro Indicator Edge
    • Other Charting Tools
      • P&F Charts
      • GalleryView
      • Seasonality Charts
      • CandleGlance Charts
      • MarketCarpets
      • Interactive PerfCharts
      • RRG Charts
      • Dynamic Yield Curve
    • Research Tools
      • Symbol Summary
      • Options Summary
        • OptionsPlay Explorer
      • OptionsPlay Strategy Center
      • Market Summary
      • Sector Summary
      • Industry Summary
      • Index Members
      • StockCharts Technical Rank (SCTR) Reports
      • Earnings Calendar
      • Cryptocurrency Summary
    • Reports and Galleries
      • The Ticker Cloud
      • Historical Chart Gallery
      • Predefined Scan Results
        • Customizing Predefined Scans
      • Predefined Technical Alerts
      • DecisionPoint Chart Gallery
      • Public ChartLists
        • Becoming a Public ChartList Author
      • SharpCharts Voyeur
  • Scanning & Alerts
    • Technical Scans
      • Scanning for Stocks: The Basics
      • Advanced Scan Workbench
      • Standard Scan Workbench
      • Working With Scan Results
    • Scan Writing Resource Center
      • Planning Scans
      • Writing Scans
      • Scanning Tutorials
        • Scan Workbench Tutorial
        • Scan Results Tutorial 1
        • Scan Results Tutorial 2
        • Writing Scans Tutorial 1
        • Writing Scans Tutorial 2
        • Creating Scan Templates Tutorial
        • Troubleshooting Scans Tutorial 1
        • Troubleshooting Scans Tutorial 2
        • Troubleshooting Scans Tutorial 3
      • Scanning Case Studies
        • Scanning for Crossovers
        • Scanning for "Near Crosses"
        • Scanning for Divergences
        • Scanning for Relative Strength
        • Scanning for Consolidation and Breakouts
        • Scanning for Selling Climaxes
        • Scanning for SCTRs
        • Scanning Ichimoku Clouds
        • Scanning for P&F Chart Patterns
        • Scanning Your ChartLists
        • Scanning for an Overlay of an Indicator
        • Writing Min/Max Scans
        • Writing Percent Change Scans
        • Scanning Over a Range of Dates
        • Writing Scans With OR Clauses
      • Troubleshooting Scans
        • Troubleshooting Equality Scans
      • Getting Help With Scans
      • Scan Syntax Reference
        • Scan Syntax: Ticker Properties
        • Scan Syntax: Price, Volume, and SCTRs
        • Scan Syntax: Technical Indicators
        • Scan Syntax: Technical Functions
        • Scan Syntax: Predefined Patterns
        • Scan Syntax: Groups
      • Advanced Scan Library
        • Sample Scans
        • Predefined Scans
        • Published Scans
        • User-Contributed Scans
        • Gord Greer's Scan Building Blocks
    • Technical Alerts
      • Technical Alert Workbench
      • Your Alerts
  • Your Account
    • Subscribing to StockCharts
    • Service Levels & Data Plans
    • Login & Passwords
    • Your Account Settings
    • Managing Your Subscription
      • Cancelling Your Account
    • StockCharts Add-Ons
      • OptionsPlay Add-On
  • Learning More
    • Market Commentary
      • Blogs
      • ChartWatchers Newsletter
      • StockCharts TV
    • Educational Resources
    • Frequently Asked Questions (FAQs)
    • Step-By-Step Instructions
      • SharpCharts How-Tos
        • SharpCharts Workbench How-Tos
          • How to Print a SharpChart
          • How to Share a SharpChart on Social Media
          • How to Email a SharpChart
          • How to Insert a SharpChart in a Document or Presentation
          • How to View Indicator and Overlay Values for Specific Days
          • How to Save a SharpChart
        • SharpChart Editing How-Tos
          • How To Use The Interactive Date Slider
          • How to Display More than One Symbol on a SharpChart
          • How to Create Overlaid Charts
          • How to Add an Overlay to an Indicator
          • How to Add a Moving Average to the Volume Bars on a Chart
        • ChartNotes How-Tos
          • How to Pin an Annotation on a SharpChart
          • How to Save a Chart from a Blog Article with the Author's Annotations
        • ChartList How-Tos
          • How to Use the ChartList Summary
          • How to Search for a Saved Chart in Your ChartLists
          • How to Share a ChartList with Another Member
        • ChartList Editing How-Tos
          • How to Create a New ChartList
          • How to Add Predefined Symbol Groups to a New ChartList
          • How to Add Predefined Groups into an Existing ChartList
          • How to Upload Symbols to a ChartList from a Spreadsheet
          • How to Rearrange Charts in a ChartList
          • How to Delete a Saved Chart from a ChartList
      • StockChartsACP How-Tos
        • Setting Period, Type And, Range
        • Chart Attributes
          • Part One
          • Part Two
        • Sharing And Printing
        • Saving Charts
          • Saving A New Chart
          • Saving An Existing Chart As New
        • Chart Templates
          • Applying Predefined Chart Templates
          • Saving A New Chart Template
        • Using ChartLists
          • Creating A New ChartList
        • Chart Layouts
          • Accessing Chart Layouts
          • Creating A New Custom Layout
        • Additional Tools
          • Accessing Research Tools
    • Troubleshooting
      • Unable to Log In
      • Website Slow or Down
        • Using OpenDNS
      • Website Functionality Issues
    • Customer Support
    • Policies & Limitations
      • Terms of Service
      • Privacy Statement
      • No Service Level Guarantees
      • Data Policies
      • Usage Limitations
      • Reprint Permission Policies
      • Billing Policies
      • Membership Policies
      • Public ChartList Policies
      • Customer Support Policies
Powered by GitBook
LogoLogo

ON STOCKCHARTS

  • Charts & Tools
  • Articles
  • StockCharts TV
  • ChartSchool

MEMBERS

  • Your Dashboard
  • Your ChartLists
  • Advanced Scans
  • Technical Alerts

HELP

  • Support Center
  • FAQs
  • Contact Us
  • Pricing

COMPANY

  • About Us
  • What's New
  • Careers
  • StockCharts Store

© StockCharts.com, Inc. All Rights Reserved.

On this page
  • Defining the Scan Universe with OR Clauses
  • Defining Technical Conditions with OR Clauses
  • Defining Signals with OR Clauses
  • Using OR Clauses to Scan Multiple Timeframes
  • Combining AND and OR Clauses
  • Energy and Materials Stocks in the S&P 1500
  • Recent SMA Crossover on Strong Volume
  • The Bottom Line
  • Additional Resources

Was this helpful?

Export as PDF
  1. Scanning & Alerts
  2. Scan Writing Resource Center
  3. Scanning Case Studies

Writing Scans With OR Clauses

PreviousScanning Over a Range of DatesNextTroubleshooting Scans

Last updated 1 year ago

Was this helpful?

Using OR clauses in your scans can take some time to master, but they provide an invaluable amount of flexibility to your scans.

Most scan clauses are joined together with the AND operator, which means that a stock has to meet the criteria in ALL the scan clauses. Clauses joined with the OR operator work differently, together forming a list of possible criteria for your scan; a stock only has to meet one of the criteria on that list to be accepted. For more detailed information on how OR clauses work, check out the OR Clause section of our article in the Support Center.

OR clause lists are very handy when there are multiple variations on a scan criteria that you want to test for all at once. For example, you may be interested in stocks that trade on the NYSE or the NASDAQ exchange. An OR clause allows you to scan for both exchanges at once, rather than having to run two separate scans for the NYSE and NASDAQ.

Below, we cover several different kinds of OR clause lists that you can use in your scans.

Defining the Scan Universe with OR Clauses

A classic example of defining your scan universe with OR clauses is the S&P 1500. You can find stocks in the S&P 1500 by scanning for stocks that are in the S&P 500 OR in the S&P 400 OR in the S&P 600:

[type = stock]
AND [
  [group is SP500] 
  OR [group is SP400]
  OR [group is SP600]
]

Note the use of an additional set of brackets around the entire OR clause list. It isn't always clear to the Scan Engine which clauses are part of your list, so it's important to put an additional set of square brackets around the list. This tells the Scan Engine how to process your scan correctly. For more details on why these brackets are so important, check out the OR Clause section of our article in the Support Center.

OR clauses aren't just for determining index membership; they can also be used to define your universe as a list of exchanges, industries, or even ChartLists.

Defining Technical Conditions with OR Clauses

Once you've defined the universe for your scan, the next step is to define the technical conditions that your scan results must meet. This is another place you can take advantage of OR clauses.

In this example, we're looking for a stock that is in an uptrend. We've specified two different ways to test for an uptrend in this scan: one is checking that the 20-day SMA is above the 50-day SMA, the other is looking for the Uptrend candlestick pattern:

[type = stock]
AND [ 
  [today's sma(20,close) > today's sma(50,close)] 
  OR [Uptrend is true]
]

OR clauses can be used with any kind of technical condition criteria. You can see in the example above that we used both technical indicators and candlestick patterns in a single OR clause list.

Defining Signals with OR Clauses

Good scans typically have at least one signal criterion, but often there are multiple technical signals that would meet your requirements. Take the following example:

[type = stock] 
AND [
  [MACD Line(12,26,9) x 0] 
  OR [ROC(14) x 0] 
  OR [CMF(20) x 0]
]

In this example, we are searching to find stocks where either the MACD, ROC or CMF have crossed above zero. All three of these oscillator crossovers indicate a change from negative to positive momentum, so if a stock has any one of these crossovers, it indicates a bullish move. It is not necessary for all three crossovers to happen for the stock at the same time; as long as at least one crossover happens, the stock is returned as part of the scan results.

Using OR Clauses to Scan Multiple Timeframes

Sometimes it is useful to scan for a specific signal that happened “recently” but not necessarily today. OR clauses come to the rescue here too, allowing you to scan for a signal that occurred today, or yesterday, or the day before, etc.

[type = stock]
AND [ 
  [Plus DI(14) x Minus DI(14)] 
  OR [1 day ago Plus DI(14) x 1 day ago Minus DI(14)]
]

This scan looks for Plus DI crossing over Minus DI either today or yesterday. While this approach is not really suited to scanning over a long period of time, it's a useful technique when looking for signals that happened sometime in the last few days.

Combining AND and OR Clauses

The examples given above are fairly simple, grouping together two or three single clauses with OR operators, but OR clause scans can be made more complex by combining AND clauses and OR clauses in different ways. Let's look at a couple of examples.

Energy and Materials Stocks in the S&P 1500

In this first example, we're looking for S&P 1500 stocks that are in the Energy or Materials sectors:

[type = stock]
AND [
  [group is SP500] 
  OR [group is SP400]
  OR [group is SP600]
]
AND [
  [group is EnergySector]
  OR [group is MaterialsSector]
]

This scan contains two different OR clause lists: one for confirming membership in the S&P 1500 and one for limiting to Energy and Materials stocks. An AND operator connecting the two OR clause lists tells us that at least one criteria from each list needs to be met. Brackets are crucial here as they help the Scan Engine understand which clauses are part of which OR clause list.

Recent SMA Crossover on Strong Volume

In our second example, we want each of the items on our OR clause list to be two-part criteria. Specifically, we want to scan for stocks with an SMA crossover AND a large volume increase today OR for stocks with an SMA crossover AND a large volume increase yesterday.

[type = stock]
AND [
  [
    [today's close x sma(10,close)] 
    AND [today's volume > yesterday's volume *1.25]
  ]
  OR
  [
    [yesterday's close x yesterday's sma(10,close)] 
    AND [yesterday's volume > 2 days ago volume *1.25]
  ]
]

To accomplish this, we will nest AND clauses inside of our OR clause list. Again, brackets help the Scan Engine understand which clauses are grouped together. Notice that, in addition to the brackets around the entire OR clause list, we have extra brackets around the “AND clause list” inside each OR clause.

The Scan Engine works its way from the inside brackets to the outside brackets. First, it finds symbols that had an SMA crossover on strong volume today (our first AND clause list). Then, it finds symbols that had an SMA crossover on strong volume yesterday (our second AND clause list). Once these innermost brackets have been processed, the Scan Engine moves on to the next level of brackets, processing our OR clause list and determining which symbols are in either the first set OR the second set of symbols.

The Bottom Line

OR clauses allow you to broaden the scope of a single scan, defining more than one possible criteria that will return results. They can be used to list multiple criteria options for ticker properties (to define the universe of your scan), technical conditions, signals and even multiple timeframes.

The most important thing to remember when using OR clauses is to include extra square brackets to group clauses together. This helps the Scan Engine understand what you are looking for so that it returns the correct scan results.

Additional Resources

Articles

Tutorials

Check out scan for a great example of a properly bracketed scan that combines multiple levels of AND and OR clauses.

Writing Scans
Troubleshooting Scans
Troubleshooting Scans Tutorial 2
Writing Scans
Troubleshooting Scans
Michael Daumer's Momentum Buy Signal