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
  • Adding Comments to Your Scan
  • Adding the Golden Cross Clauses to the Scan
  • Using Crossover Clauses
  • Using Arithmetic Functions in Scans
  • Finishing Up the Scan
  • Learn More

Was this helpful?

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

Writing Scans Tutorial 2

PreviousWriting Scans Tutorial 1NextCreating Scan Templates Tutorial

Last updated 1 year ago

Was this helpful?

This tutorial will walk you step-by-step through writing a Golden Cross scan to run from the Advanced Scan Workbench. In the , we created a scan using fairly simple clauses. In this tutorial, we will build on that knowledge and learn some more complex scan syntax.

Our scanning tutorials assume only a basic knowledge of common technical indicators and chart patterns. This tutorial may build on skills learned in prior scanning tutorials (links are provided where appropriate).

By the end of this tutorial, you will be able to write a scan using more complex scan syntax, including crossover clauses and arithmetic functions, as well as be able to add explanatory comments to your scan clauses. Once you've mastered these skills, be sure to check out our to learn about and practice other aspects of scanning.

Here's a Tip: Open this page in another tab (or print it) so you can refer to it as you follow along.

Adding Comments to Your Scan

Step 1: Open the Advanced Scan Workbench and add the following scan clauses in the Scan Editor Box:

[type is stock] and [sma(20,volume) > 40000]
AND [country is US]
AND [close > 10]

These clauses are similar to the universe-defining clauses created in the . If you need to brush up on your scan syntax, we recommend starting with that tutorial before completing this one.

Step 2: Click the “Check Syntax” button to make sure everything has been typed in correctly, then click “Run Scan”.

If you are not familiar with the process for running a scan in the Advanced Scan Workbench, we recommend accessing our , which will help you build and run the scan listed above.

Step 3: Check out the scan results in the new browser window (or new tab in your current browser window) that opens up. This scan is expected to get the max of 2000 results. We will need to narrow it down further later in the tutorial.

Before we do that, let's look at adding some comments to the scan. The scan engine does not read these informational notes; they are to help you remember what each clause does when you look at the scan later.

Comments should have two forward slashes at the beginning of the line. Any text on that line after those forward slashes will be ignored by the scan engine.

Step 4: Try adding a comment before each of the three lines of scan criteria we have in our scan right now, explaining what that line does. Once this is completed, your scan may look something like this:

// Stocks that traded at least 40K shares daily this last month
[type is stock] and [sma(20,volume) > 40000]
// US stocks only
AND [country is US]
// Current close must be above $10
AND [close > 10]

These are straightforward clauses, so maybe the comments are not strictly necessary for some of them, but it is a good habit to have. You'll thank yourself when you're trying to decipher a complex scan several months after you wrote it.

Step 5: Click the “Check Syntax” button, then click “Run Scan” to confirm that the comments you added have not changed the results you get.

Adding the Golden Cross Clauses to the Scan

A Golden Cross is a signal given when a shorter-term moving average (MA) moves above a longer-term moving average - typically the 50-day MA moving above the 200-day MA. How can we scan for this signal? If the 50-day MA has crossed above the 200-day MA today, that means today's 50-day MA value is greater than the 200-day MA value. It also means that yesterday's 50-day MA value was less than yesterday's 200-day MA, since the crossover hadn't happened yet.

We can add two clauses that scan for these two situations.

Step 6: Click inside the Scan Editor Box and add the following text at the end of the scan:

// Golden Cross - 50-day SMA crosses above 200-day SMA
and [today's SMA(50,close) > today's SMA(200,close)]
and [yesterday's SMA(50,close) <= yesterday's SMA(200,close)]

Let's take a closer look at these clauses. First, notice that we have added “today's” or “yesterday's” to the beginning of some of the scan expressions. This tells the scan engine to look at the value for that expression on that particular day. If you don't specify a date modifier, the scan engine will assume you want today's value.

Here we are using the SMA (simple moving average) indicator, which has two parameters. The first shows the number of periods to use in calculating the moving average. The second indicates what data you want to calculate the moving average of. By default, the close is used, but you can calculate moving averages of the open, the volume or even another indicator.

Notice also that, for the first time, we are comparing an indicator to another indicator in our scan clauses. Up to this point, we've been comparing to a static number or text, but scan clauses can be used to compare all kinds of different values.

Note: You can also add a simple moving average clause to your scan by choosing “SMA” from the “Technical Indicators” menu in the Scan Components area of the workbench and clicking “Add.” This inserts a sample scan clause for limiting results based on the 50-day simple moving average (SMA) of volume. You may need to change the parameters used for this default clause manually.

Step 7: Click the “Check Syntax” button to ensure everything has been typed in correctly, then click “Run Scan.” Note how the number of results changed when you added these two clauses.

Using Crossover Clauses

In technical analysis, one line crossing another is often a meaningful signal. Our initial Golden Cross criteria contained two clauses to find this crossover event, but there is a shortcut - the “Crosses Above” operator (signified by the “x”), which will do this in only one clause.

Step 8: Remove the two Golden Cross clauses added in Step 6. Replace them with the following text:

and [today's sma(50,close) x today's sma(200,close)]

This crossover clause checks to see if the 50-day SMA has crossed above the 200-day SMA today. This single clause says the exact same thing as the previous two clauses: today the 50-day SMA is above the 200-day SMA, yesterday it was not. Since crossover signals are so widely used in technical analysis, the Crosses Above operator is a great shortcut to scan for this type of signal.

Step 9: Click the “Check Syntax” button to ensure all of the scan clauses are correct, then click “Run Scan”. Notice that the number of results has not changed, since the Crosses Above clause checks for the exact same criteria as the two separate clauses.

Using Arithmetic Functions in Scans

We've built our basic Golden Cross scan, but we can add a couple more clauses to fine-tune our results. For example, we may only care about a Golden Cross if it occurs with strong volume. Since volume varies so much from stock to stock, it's not practical to scan for a specific number of shares (e.g. [volume > 25000000]). We could just check whether volume is greater than the previous day (e.g. [today's volume > yesterday's volume]), but, with arithmetic functions, we can be much more specific about the magnitude of the volume increase.

Step 10: Click in the Scan Editor Box and add the following text at the end of the scan:

// Volume up 50% from yesterday
and [volume > yesterday's volume * 1.5]

This clause says that today's volume is greater than yesterday's volume multiplied by 1.5. In other words, today's volume is at least 50% more than yesterday's volume. Now we are being much more precise about how strong the volume increase needs to be.

Step 11: Click the “Check Syntax” button again, then click “Run Scan” and check out the results.

Finishing Up the Scan

Since we're only interested in stocks where the price is rising, we need to add one last clause to our scan.

Step 12: Click in the Scan Editor Box and add the following text to the end of the scan:

// Price is going up!
and [close > yesterday's close]

This is a simple clause, but can make all the difference in our scan, weeding out stocks that are dropping in price and of no interest to us.

Step 13: Click the “Check Syntax” button, then click “Run Scan” one last time to see if this clause changed the results.

In the example above, adding this clause did not change the results; all the stocks returned by the previous version of the scan were already going up in price.

The final version of your scan should read like this:

// Stocks that traded at least 40K shares daily this last month
[type is stock] and [sma(20,volume) > 40000]

// US stocks only
AND [country is US]

// Current close must be above $10
AND [close > 10]

// Golden Cross - 50-day SMA crosses above 200-day SMA
and [today's sma(50,close) x today's sma(200,close)]

// Volume up 50% from yesterday
and [volume > yesterday's volume * 1.5]

// Price is going up!
and [close > yesterday's close]

Notice that those comments make it easy to see, at a glance, what each clause does.

Step 14: Once you are happy with your scan, be sure to save it, so you can easily run it again at a later date.

Learn More

For more information on scanning for crossovers, check out our .

If you are not familiar with the process for saving your scan in the Advanced Scan Workbench, we recommend accessing our , which will walk you step by step through saving your scan.

Now that you've learned some more advanced techniques for writing scans, check out our to learn more about how to fix your scan when it is not returning the results you expect.

For more in-depth information on writing scans, please check out our in the Support Center.

previous tutorial
other scanning tutorials
first tutorial on writing scans
tutorial on this topic
Support Center article on that topic
first Writing Scans Tutorial
Troubleshooting Scans Tutorial
Writing Scans article