Creating custom indicators

A technical indicator is used to provide a distinctive perspective of market activity that may be unavailable by simply viewing price charts. Each indicator is essentially its own program that tells the computer what data to use, which calculations to apply and how to display the results. While there are hundreds of readily available technical indicators, such as moving averages and stochastics, some traders may wish to design their own indicators to perform specific functions or spot unique conditions in the market.

Many of today’s trading platforms enable users to program their own custom indicators using some sort of proprietary language (such as TradeStation’s EasyLanguage or NinjaTrader’s NinjaScript) that interprets the concept for the computer. A list of commands is written in a specific syntax (known as the code), and after the code is entered into the trading platform, it is compiled or verified by the computer. Then it can be displayed as an indicator on a chart.

Here, we introduce a step-by-step process for building a custom indicator, using as an example the Volumizer indicator, designed to evaluate the relationship between average price and average volume. The graphic in “Go with the flow” (right) provides an overview of the development process that we will use.

Define the concept

The idea for a custom indicator can come from fields outside of trading; for example, a trader may wish to apply an idea from mathematics, statistics or simply the result of observation. A trader might notice a specific price or volume tendency, or an intermarket relationship and decide to investigate further. This is critical: It is important to have a specific goal in mind before attempting to develop an indicator, and traders must be able to verbally (and eventually mathematically) express what it is that they want the indicator to do.

For our example, we use a daily price chart of the SPDR S&P 500 exchange-traded fund, with volume inserted as a sub-chart. From observation, there appear to be trading opportunities as price and volume diverge and converge (see “Behind the moves,” below). Further, it seems that there are often changes in the average volume preceding strong market trends.

Because we are looking at price and volume on two completely different scales, however, it is almost impossible to measure this type of movement in this context objectively. If we were simply to superimpose volume on an existing price chart, the relationship between price and volume would be distorted by the scaling of the chart. In other words, more data (a wider chart) would provide a much different relationship between average price and volume than a chart with less data (a narrower chart). This would render this type of trading analysis useless because it would be subjective and, thus, difficult to reproduce for the purpose of making consistent trading decisions in the future.

This is where a custom indicator can help confirm (or negate) the hypothesis that divergence and convergence between average price and average volume may be an early indicator of strong price trends. Our next step is to combine these two data sets into a single indicator to visualize the analysis and help determine if it has merit as a trading indicator.

Express yourself

A large part of developing successful indicators is being clear, specific and objective about the concepts. For example, it is not sufficient to simply state “when the market is in an uptrend…” You must define what exactly it is that constitutes an uptrend. Examples of specific definitions might be “three consecutive higher highs,” “a nine-period moving average crossing above a 30-period moving average” or “ADX is over 20.”

Going back to our example of combining average price and average volume, we now must define every aspect of the concept and create a method of expressing this relationship objectively. First, we define the average price and volume as 40-day averages (see “Objectively speaking,” below).

Average Price = Average closing price over the past 40 days

Average Volume = Average volume over the past 40 days

Because price and volume have many different values and scales, we attempt to express one in terms of the other. In this case, we create a formula to express volume relative to price so both can be viewed simultaneously. One way to accomplish this is to look back and determine a range for both price and volume, and then build a formula that normalizes average volume to fit into the average price scale. We look back over a fairly significant amount of time (200 days) to create the range values:

Price range = (Highest average price of the past 200 days) – (Lowest average price of the past 200 days)

Volume range = (Highest average volume of the past 200 days) – (Lowest average volume of the past 200 days)

We then build a formula that normalizes volume:

Relative average volume = ((Average volume) – (Lowest average volume of past 200 days) / (Volume range * Price range)) + Lowest average price of last 200 days

Now that this relationship has been defined, we can continue the process of converting the concept into a custom indicator that can be applied to a price chart.

Chart it

Once the concept behind a trading indicator has been defined, traders must decide how the indicator should appear. Indicators can take on many different forms and it’s up to the trader to determine which method is most visually effective for displaying the concept. Indicators can appear on a price chart in many different ways:

  • As a separate study below a price chart (think Stochastic or CCI)
  • Lines overlaid on top of price (such as moving averages or Bollinger bands)
  • Dots or arrows projected over price bars
  • Differently colored price bars
  • Text, lines or other annotations added to a price chart

The goal of an effective indicator is to highlight the condition or conditions defining the trading concept or calculation. A good trading indicator will provide the trader with a clear and unique visual representation of trading activity that may not have been evident from a price chart alone. Traders should be careful, however, not to add too many indicators to a chart. This can become confusing or detract from the most important part of a chart: The price.

The Volumizer indicator comprises two components: The 40-day average price and the 40-day relative average volume. We overlay both on the same price chart. Because we are looking for differences between price and volume, we highlight the area between the average price and relative average volume. To accomplish this, we color the area blue to reflect instances where average price crosses above the relative average volume, and red when average price crosses below relative average volume. This way, it should be easy to recognize the ideal conditions in an attempt to substantiate the concepts of the indicator.

Writing the code

Most system trading platforms use their own proprietary programming language, and traders either can write the code for the indicator themselves or work with a qualified programmer. The code is simply a list of instructions that must be written in an exact format. Each horizontal line of code, referred to as a statement, gives the computer a different command; these statements form the building blocks of the program.

While the actual programming falls outside the scope of this article—and, in any case, will vary depending on what system you employ— generally it is helpful to use a structured approach to programming that breaks the code down into three sections:

  • The declaration (or program header): Assigns values to the variables of the program, including user-definable input variables
  • The calculation block: The math behind the indicator
  • The plotting instructions: Tell the program which calculations to plot and how they are to be displayed

Traders who decide to work with a programmer can save (sometimes significant) time and money by providing the programmer with exact specifications for the project. Programmers generally frown upon subjective or vague instructions, and instead require objective rules to code an indicator efficiently and accurately.

In addition to the indicator’s function, it is important to specify how it should look. Any specific variables for which traders would like to be able to change values, such as lookback period or price type (open, high, low, close), should be included in the project specs as well.

In the Volumizer example, the length of the averages and the number of bars used in the range calculation can be adjusted by the user. This way, traders can experiment with different settings without the need to reprogram the entire indicator.

We have written the Volumizer using TradeStation EasyLanguage (see “Volumizer indicator code,” next page). The concept, however, easily could be applied to other charting platforms that allow the programming of custom indicators. “Charting volume” (below) shows the completed indicator:

  • The blue line is the average price
  • The red line (on the main chart) is relative average volume
  • The areas highlighted in blue indicate that average price is above relative average volume
  • The areas highlighted in red show that relative average volume is above average price

Get testy

The next step in the development process is to test the indicator by monitoring it in a live market. The purpose of testing is three-fold:

  • To make sure the indicator does what you expected it to do
  • To determine if the indicator’s appearance is what you intended
  • To establish if the concept is valid

Once an indicator has been developed, it may not be a big stretch to incorporate it as part of a trading strategy that can be tested and eventually traded using some level of automation, if desired. By utilizing the indicator in a strategy, a trader quickly can determine if the trading concept has any merit.

As the flow chart indicates, if testing reveals that the indicator does not perform as expected for any reason, it needs more work. This might entail minor revisions, such as tweaking one line of code, or the trading concept may need to be revised to develop a more useful trading tool.

Once the development is complete and the indicator has proved to be useful, it is ready to be used in the markets. It is up to each trader to decide how to apply an indicator to the markets that he or she trades. It is important not to confuse technical indicators with strategies. Indicators provide a visual representation of some type of market condition. Strategies, on the other hand, are objective sets of rules that specify the exact conditions for trade entries and exits. While strategies can be based on multiple trade filters and triggers, including indicators, it is the strategy—and not the indicator—that determines when a trade is made.

Custom indicators can be important additions to any trader’s toolbox because they allow traders to identify specific market conditions rather than being limited to a trading platform’s standard selection of indicators.

 

About the Author

Jean Folger is the co-founder of and system researcher with PowerZone Trading, LLC.