sommaire

Program examples

The section "Creation by Programming" is dedicated to users who wish to program a market scan on their own. A detailed description of the commands available is included in the "ProScreener Programming Guide".

Even if you have never written code, we suggest you use the "Creation by Programming" window to improve market scans created with the ProScreener wizard. We are going to show you some examples of modifications that you will be able to do by yourself without being an expert programmer.

You can also have a look at the trading systems section of ProRealTime.com, where you can download a variety of code published by our programmers or by other members of our community.

Adapt your market scan to conditions on previous bars

Useful information before starting:

By adding square brackets to a term, you can access the information of a previous bar. The current bar is [0], the previous bar is [1] and so on. See the following image:

Let's create a market scan that looks for securities whose Moving Average has a positive trend, meaning an increasing value of the Moving Average indicator. The ProScreener wizard also allows us to compare the current bar with the previous bar. The code is the following:

Code
indicator1 = Average[20](close)
indicator2 = Average[20](close)
c1 = (indicator1 > indicator2[1])

SCREENER[c1] (Variation AS "% Prev bar")

We can modify our code and set more stringent conditions: we want the positive trend to be verified for the last 2 bars (or periods).

Let's duplicate the c1 line to create a second condition, named c2. Then we insert respectively [1] after indicator1 and [2] after indicator2 and include the c2 condition between the SCREENER brackets. See the code below:

Code
indicator1 = Average[20](close)
indicator2 = Average[20](close)
c1 = (indicator1 > indicator2[1])
c2 = (indicator1[1] > indicator2[2])

SCREENER[c1 AND c2] (Variation AS "% Barre prec")

Group your conditions into one ProScreener

In this section, you will see how to cumulate searching conditions with additional flexibility. For example, you may want to detect:

  • securities having a RSI > 70 and positive price trend
  • and securities having RSI < 30 and a negative price trend

When setting multiple conditions in the Assisted creation wizard, you have the choice between "Match all conditions" or "Match any of the conditions", but you cannot create one screener that searches for either 2 simultaneous bullish conditions or 2 simultaneous bearish conditions for example. This can be done with a little modification in the code.

First of all, let's create a ProScreener based on the conditions above and let's set a sorting criteria using the RSI indicator. The code is the following:

Code
indicator1 = RSI[14](close)
c1 = (indicator1 > 70.0)
c2 = (close > open)
indicator2 = RSI[14](close)
c3 = (indicator2 < 30.0)
c4 = (close < open)

criteria = RSI[14](close)

SCREENER[c1 AND c2 AND c3 AND c4] (criteria AS "RSI")

In the code c1 and c2 are the bullish conditions, c3 and c4 the bearish conditions. We can just group them in the SCREENER line, to get a market scan that searches for securities meeting 2 bullish conditions or 2 bearish conditions in the same program. See the code in below:

Code
indicator1 = RSI[14](close)
c1 = (indicator1 > 70.0)
c2 = (close > open)
indicator2 = RSI[14](close)
c3 = (indicator2 < 30.0)
c4 = (close < open)

criteria = RSI[14](close)

SCREENER[(c1 AND c2 ) OR (c3 AND c4)] (criteria AS "RSI")

The ProScreener window will display the results using the value of the RSI as the sorting criteria. By examining the RSI value, you will easily see if the security meets the bullish conditions or the bearish conditions.

Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced clients who have sufficient financial means to bear such risk. No information on this site is investment advice or a solicitation to buy or sell any financial instrument.