An Enigma in Silver

FCharts Formula FAQ


This page contains some example formulae to help you understand the Freecharts programming language. They are not supposed to be examples which you can trade with, and you should NOT use them for anything but education.

First, a declaration. I am not a licensed advisor, so:
1) Information presented by this program is not suitable to be used as investment advice.
2) You should seek professional advice before making any investment decisions relying on the information provided.

Most programs let you enter a formula which works on the past few days. Freecharts doesn't work like that. Freecharts examines all the prices for the current chart and uses your formulae to place green markers wherever condition (1) is met, and red markers wherever condition (2) is met. Once it places a green marker it cannot place another one until it has placed a red, and vice versa. What does this do for you? Well, for a start you can see at a glance whether your formulae are any good - do they capture the bulk of the up-trends? If not, you can add or tweak your variables and get another, instant look at the chart using the new formula. It's hard to explain clearly without lots of graphics, so the best bet is to set the program up with some data and enter some of the formulae below to see what happens. Start with the really simple formulae, then increase the complexity.

OK, on with the show. Any programmer will tell you that before you start coding, you should write your aims out in plain English. Programming is just converting this plain English into words and symbols a computer can understand. All the examples on this page will have a sentence in English, followed by the same thing using Freecharts keywords.

English: Closing price rises above long-term moving average (MA3)
FreeCharts: Close > MA3

English: Closing price three days ago was higher than the close two days ago, and yesterday's close was lower than today's, and today's is higher than it was three days ago. (In other words, the price went down and then up)
FreeCharts: Close[3] > Close[2] and Previous Close < Close and Close > Close[3]

English: Close has risen three days in a row, and volume has risen two days in a row and is now double or more than what it was 5 days ago.
FreeCharts: M_PriceRises >=3 and M_VolumeRises >=2 and Volume >= Volume[5] * 2

(You can also look for linear increases and decreases using 'Increasing X, N' and 'Decreasing X, N', where X is a variable or formula, and N is the number of bars it should check for the increase or decrease over. This can also be shortened to INC and DEC.)

English: Price fell for 3 days, then rose by 2% or more.
FreeCharts: Previous M_PriceFalls >=3 and Close > Previous Close * 1.02

English: MACD line crosses or is above the MACD signal line, volume has increased for two days in a row and RSI is under 30 and rising.
Freecharts: MACDLine > MACDSignal and M_VolumeRises >= 2 and RSI < 30 and RSI > Previous RSI

English: Closing price falls below the medium-term moving average.
FreeCharts: Close < MA2

English: Close is the lowest for the previous 21 days.
FreeCharts: Close = lowest_close[21]

English: Close is higher than the highest open for the past 21 days, and it happened on the last day in the database.
FreeCharts: Close >= highest_open[21] and LastDayOnly = true

English: Close is the lowest for the past 9 days, and it happened AFTER the 21st of March, 2001.
FreeCharts: Close = lowest_close[9] and date > 21/3/2001 Important Note: You should use the appropriate date format for your Windows date settings. E.g. Use 3/21/2001 if your computer is using US dates.

English: Close is lower than open and volume increases 45%.
FreeCharts: Close < Open and Volume > Previous Volume * 1.4

English: 7-period EMA of volume is higher than the 21-period EMA of volume, and the 7-period ema of volume has increased for three bars running.

FCharts: v1: ema volume, 7 ; v1 > ema volume, 21 and inc v1, 3

(v1: declares variable #1, which can then be reused again in the formula. You can declare variables v1 to v100, assigning any formula or value to them. After declaration you can use the value of the variable in your formula. A semi-colon separates each variable declaration from the next, and from the formula.)

English: Previous high is in or below the lower 5% of today's range. In other words, less than today's low plus 5% of today's range. It's like a gap with a very tiny overlap.

Freecharts: previous high <= (low + ((high - low) * .05))

English: Scan for stocks with a long-term upwards trend. What we're going to do is take several data points 20 price bars apart. We'll need to set EMA3 to 150 periods to cut out short-term fluctuations.

Freecharts: ema3 > ema3[20] and ema3[20] > ema3[40] and ema3[40] > ema3[60] and ema3[60] > ema3[80] and ema3[80] > ema3[100]

English: Scanning for a crossover (any kind)

Freecharts: There are two ways to do it. The first is to put half the required formula into condition 1 and the other half into condition 2:

(I'm using Macd1 and Macd2 in this example. You can use any indicator you like - ema1 vs ema3, stochastics ... anything.)

Cond 1) Macd1 > Macd2
Cond 2) Macd1 < Macd2

Doing it this way, stocks which have crossed over (in an upwards direction) on the last price bar will be in the (1) list, and stocks which crossed upwards recently will be in Ex-(1). Stocks which have crossed down on the last price bar will be in the (2) list, and stocks which crossed down recently (but not on the last bar) in Ex-(2).

The second way is to specifically pinpoint the crossover in your first condition:

Cond 1) Macd1 > Macd2 and previous Macd1 < previous Macd2
Cond 2) Anything you want as an exit condition

If you just want to find crossovers on the latest price in the database, tick the option in the scanner to only scan the last price bar and you won't need to supply a condition 2.

In the Pro version you can combine an IF statement and a user defined indicator to keep hold of a value until another comes along:

UDI1) If day = 'FRI', MAHIST, UDI1[1]

In other words, if the current price bar occurs on a Friday, update the value of UDI1 with the current value for MAHIST. Otherwise, set the current value of UDI1 to the previous value of UDI1 (which is UDI1[1])

Then you can use UDI1 in other formulae as if it were equivalent to the MAHIST value on the most recent Friday. Instead of MAHIST you can use any other formula or variable, which makes this a very powerful piece of code.