Pro Indicator
Pro Indicator
personalized technical indicators, trading systems and market scanning programs for
the ProRealTime platform.
Follow ProRealTime Programming on Google+ for updates about ProRealTime programming languages.
V 4.1.1 20160502
TABLE OF CONTENTS
Introduction to ProBuilder__________________________________________1
Chapter I: Fundamentals___________________________________________2
Using ProBuilder...........................................................................................................2
Indicator creation quick tutorial......................................................................................................2
Programming window keyboard shortcuts....................................................................................5
Mathematical Functions..............................................................................................23
Common unary and binary Functions.........................................................................................23
Common mathematical operators...............................................................................................23
Charting comparison functions....................................................................................................23
Summation functions...................................................................................................................24
Statistical functions......................................................................................................................24
Logical operators.........................................................................................................24
ProBuilder instructions................................................................................................24
RETURN......................................................................................................................................25
REM or //......................................................................................................................................25
CustomClose...............................................................................................................................25
CALL............................................................................................................................................26
AS................................................................................................................................................26
COLOURED................................................................................................................................26
Drawing instructions....................................................................................................28
Glossary________________________________________________________39
Warning: ProRealTime does not provide investment advisory services. This document is not in any
case personal or financial advice nor a solicitation to buy or sell any financial instrument. The
example codes shown in this manual are for learning purposes only. You are free to determine all
criteria for your own trading. Past performance is not indicative of futrure results. Any trading
system may expose you to a risk of loss greater than your initial investment.
Introduction to ProBuilder
Introduction to ProBuilder
ProBuilder is ProrealTime's programming language. It allows you to create personalized technical indicators,
trading strategies (ProBacktest) or screening programs (ProScreener). A specific manual exists for
ProBacktest and ProScreener due to some specifics of each of these modules.
ProBuilder is a BASIC-type programming language, very easy to handle and exhaustive in terms of available
possibilities.
You will be able to create your own programs using the quotes from any tool provided by ProRealTime.
Some basic available elements include:
Opening of each bar: Open
Closing of each bar: Close
Highest price of each bar: High
Lowest price of each bar: Low
Volume of each bar: Volume
Bars or candlesticks are the common charting representations of real time quotes. Of course, ProRealTime
offers you the possibility of personalizing the style of the chart. You can use Renko, Kagi, Haikin-Ashi and
many other styles.
ProBuilder evaluates the data of each price bar starting with the oldest one to the most recent one, and then
executes the formula developed in the language in order to determine the value of the indicators on the
current bar.
The indicators coded in ProBuilder can be displayed either in the price chart or in an individual one.
In this document, you will learn, step by step, how to use the available commands necessary to program in
this language thanks to a clear theoretical overview and concrete examples.
In the end of the manual, you will find a Glossary which will give you an overall view of all the ProBuilder
commands, pre-existing indicators and other functions completing what you would have learned after reading
the previous parts.
Users more confident in their programming skills can skip directly to chapter II or just refer to the Glossary to
quickly find the information they want.
For those who are less confident, we recommend watching our video video tutorial entitled "Programming
simple and dynamic indicators" and reading the whole manual.
We wish you success and hope you will enjoy the manual!
V 4.1.1 20160502
www.prorealtime.com
1 / 47
Chapter I: Fundamentals
Chapter I: Fundamentals
Using ProBuilder
Indicator creation quick tutorial
The programming zone of an indicator is available by clicking the button "Indicator/Backtest" which can be
found in the upper right corner of each chart of the ProRealTime platform.
The indicators management window will be displayed. You will then be able to:
Display a pre-existing indicator
Create a personalized indicator, which can be used afterwards on any security
If you choose the second possibility, click on "New indicator" to access the programming window.
At that time, you will be able to choose between:
Programming directly an indicator in the text zone designed for writing code or
Using the help function by clicking on "Insert Function". This will open a new window in which you can
find all the functions available. This library is separated in 7 categories, to give you constant assistance
while programming.
V 4.1.1 20160502
www.prorealtime.com
2 / 47
Chapter I: Fundamentals
Lets take for example the first specific ProBuilder element: the "RETURN" function (available in the
"Keywords" category (see the image below).
V 4.1.1 20160502
www.prorealtime.com
3 / 47
Chapter I: Fundamentals
Select the word "RETURN" and click on "Add". The command will be added to the programming zone.
Suppose we want to create an indicator displaying the Volume. If you have already inserted the function
"RETURN", then you just need to click one more time on "Insert function". Next, click on "Constants" in the
"Categories" section, then in the right side of the window, in the section named "Functions", click on
"Volume". Finally, click on "Add". Don't forget to add a space in between each command as shown below.
Before clicking on "Validate program", you need to enter the name of your indicator. Here, we named it
"Volume DAX". To finish, click on "Validate program" and you will see your indicator displayed below the
price chart.
V 4.1.1 20160502
www.prorealtime.com
4 / 47
Chapter I: Fundamentals
V 4.1.1 20160502
www.prorealtime.com
5 / 47
Chapter I: Fundamentals
Volume
As you can see, we must read from right to left: Volume is affected to X.
If you want to write it under ProBuilder, you just need to replace the arrow with an equal sign:
X = Volume
The same = symbol is used:
For the affectation of a variable (like the previous example)
As the mathematical comparison operator (1+ 1= 2 is equivalent to 2 = 1 + 1).
V 4.1.1 20160502
www.prorealtime.com
6 / 47
Chapter I: Fundamentals
Financial constants
Before coding your personal indicators, you must examine the elements you need to write your code such as
the opening price, the closing price, etc.
These are the "fundamentals" of technical analysis and the main things to know for coding indicators.
You will then be able to combine them in order to draw out some information provided by financial markets.
We can group them together in 5 categories:
INCREASING CANDLESTICK
If you want to use the information of previous bars rather than the current bar, you just need to add between
square brackets the number of bars that you want to go back into the past.
Lets take for example the closing price constant:
Value of the closing price of the current bar:
Close
Close[1]
Value of the closing price preceding the nth bar preceding the current one:
Close [n]
This rule is valid for any constant. For example, the opening price of the 2nd bar preceding the current can
be expressed as: Open[2].
The reported value will depend on the displayed timeframe of the chart.
V 4.1.1 20160502
www.prorealtime.com
7 / 47
Chapter I: Fundamentals
The constants adapted to the timeframe of the chart use square brackets while the daily price
constants use brackets.
Close[3]
Dclose(3)
Temporal constants
Time is often a neglected component of technical analysis. However traders know very well the importance
of some time periods in the day or dates in the year. It is possible in your programs to take into account time
and date and improve the efficiency of your indicators. The Temporal constants are described hereafter:
Date: indicates the date of the close of each bar in the format YearMonthDay (YYYYMMDD)
Temporal constants are considered by ProBuilder as whole numbers. The Date constant, for example, must
be used as one number made up of 8 figures.
Lets write down the program:
RETURN Date
Suppose today is July 4th, 2020. The program above will return the result 20200704.
The date can be read in the following way:
20200704 = 2020 years 07 months and 04 days.
Note that MM can never be greater than 12 and JJ can never be greater than 31.
V 4.1.1 20160502
www.prorealtime.com
8 / 47
Chapter I: Fundamentals
Time: indicates the hour of the closing price of each bar in the format HourMinuteSecond (HHMMSS)
Example:
RETURN Time
This indicator shows us the closing time of each bar in the format HHMMSS:
It is also possible to use Time and Date in the same indicator to do analysis or display results at a precise
moment. In the following example, we want to limit our indicator to the date of October 1st at precisely 9am
and 1 second:
a = (Date = 20081001)
b = (Time = 090001)
RETURN (a AND b)
V 4.1.1 20160502
www.prorealtime.com
9 / 47
Chapter I: Fundamentals
If you want to set up your indicators with counters (number of days passed, number of bars passed etc),
you can use the Days, BarIndex and IntradayBarIndex constants.
Days: Counter of days since 1900
This constant is quite useful when you want to know the number of days that have passed. It is particularly
relevant when you work with an (x) tick or (x) volume view.
The following example shows you the number of days passed since 1900.
RETURN Days
www.prorealtime.com
10 / 47
Chapter I: Fundamentals
BarIndex: Counter of bars since the beginning of the displayed historical data
The counter starts from left to right and counts each bar, including the current bar. The first bar loaded is
considered bar number 0. Most of the time, BarIndex is used with the IF instruction presented later in the
manual.
IntradayBarIndex: Counter of intraday bars
The counter displays the number of bars since the beginning of the day and then resets to zero at the
beginning of every new day. The first bar of the counter is considered bar number 0.
Lets compare the two counter constants with two separated indicators:
RETURN BarIndex
and
RETURN IntradayBarIndex
We can clearly see the difference between them: IntradayBarIndex reset itself to zero at the beginning of
every new day.
V 4.1.1 20160502
www.prorealtime.com
11 / 47
Chapter I: Fundamentals
Average[20](Close)
The values can be modified. For example, we can replace the 20 bars defined by default with any number of
bars (ex: Average[10], Average[15], Average[30], , Average[n]). In the same way, we can replace "Close"
with "Open" or RSI (Relative strength index). This would give us for example:
Average[20](RSI[5])
V 4.1.1 20160502
www.prorealtime.com
12 / 47
Chapter I: Fundamentals
Program calculating the weighted moving average over 20 bars applied to the typical price
mm = WeightedAverage[20](TypicalPrice)
RETURN mm
Program calculating the Wilder average over 100 candlesticks applied to the Volume
mm = WilderAverage[100](Volume)
RETURN mm
Program calculating the MACD (histogram) applied to the closing price. The MACD is built with the difference
between the 12-period exponential moving average (EMA) minus the 26-period EMA. Then, we make a
smoothing with an exponential moving average over 9 periods and applied to the MACD line to get the
Signal line. Finally, the MACD is the difference between the MACD line and the Signal line.
// Calculation of the MACD line
MACDLine = ExponentialAverage[12](Close) - ExponentialAverage[26](Close)
// Calculation of the MACD Signal line
MACDSignalLine = ExponentialAverage[9](MACDLine)
// Calculation of the difference between the MACD line and its Signal
MACDHistogramme = MACDLine - MACDSignalLine
RETURN MACDHistogramme
Variables
When you code an indicator, you may want to introduce variables. The variables option in the upper-right
corner of the window allows you to attribute a default value to an undefined variable and manipulate it in the
"settings" window of the indicator without modifying the code of your program.
Lets calculate a simple moving average on 20 periods:
RETURN Average[20](Close)
V 4.1.1 20160502
www.prorealtime.com
13 / 47
Chapter I: Fundamentals
In order to modify the number of periods for the calculation directly from the indicator "Settings" interface,
replace 20 with the variable "n":
RETURN Average[n](Close)
Then, click on "Add" in "Variables" and another window named "Variable definition" will be displayed. Fill it in
as follows:
Click on the "OK" button. Then, in the "Settings" window (in this case "Settings MyMovingAverage") you will
see a new parameter which will allow you to modify the number of periods in the calculation of the moving
average:
Of course, it is possible to do the same with many variables giving you the possibility to manipulate multiple
parameters at the same time for the same indicator.
V 4.1.1 20160502
www.prorealtime.com
14 / 47
RETURN must always be followed with the storage variable containing the result in order to
display the result on the chart (in the last example we use the variable "Result").
One condition, two results (IF THEN ELSE ENDIF)
We can also define a different result if the condition is not true. Let us go back to the previous example: if the
price is greater than the moving average on 20 periods, then display 1, else, displays -1.
IF Close > Average[20](Close) THEN
Result = 1
ELSE
Result = -1
ENDIF
RETURN Result
NB: We have created a binary indicator. For more information, see the section on binary and ternary
indicators later in this manual.
Sequential IF conditions
You can create sub-conditions after the validation of the main condition, meaning conditions which must be
validated one after another. For that, you need to build a sequence of IF structures, one included in the other.
You should be careful to insert in the code as many ENDIF as IF. Example:
Double conditions on moving averages:
IF (Average[12](Close) - Average[20](Close) > 0) THEN
IF ExponentialAverage[12](Close) - ExponentialAverage[20](Close) > 0 THEN
Result = 1
ELSE
Result = -1
ENDIF
ENDIF
RETURN Result
V 4.1.1 20160502
www.prorealtime.com
15 / 47
You can also replace ELSIF with ELSE IF but your program will take longer to write. Of course, you will have
to end the loop with as many instance of ENDIF as IF. If you want to make multiple conditions in your
program, we advise you to use ELSIF rather than ELSE IF for this reason.
Example: detection of bearish and bullish engulfing lines using the Elsif instruction
This indicator displays 1 if a bullish engulfing line is detected, -1 if a bearish engulfing line is detected, and 0
if neither of them is detected.
// Detection of a bullish engulfing line
Condition1 = Close[1] < Open[1]
Condition2 = Open < Close[1]
Condition3 = Close > Open[1]
Condition4 = Open < Close
www.prorealtime.com
16 / 47
Example: BarIndex
In the chapter I of our manual, we presented BarIndex as a counter of bars loaded. BarIndex is often used
with IF. For example, if we want to know if the number of bars in your chart exceeds 23 bars, then we will
write:
IF BarIndex <= 23 THEN
a = 0
ELSIF BarIndex > 23 THEN
a = 1
ENDIF
RETURN a
V 4.1.1 20160502
www.prorealtime.com
17 / 47
Lets see step by step how the program does the calculation:
Mathematically, we want to calculate the average of the moving averages calculated on 11, 12 and 13 periods.
Variable will then get successively the values 11, 12 and 13 (FOR always works with whole numbers only).
Result = 0
When Period = 11: The new Result = the 11 - period moving average + the previous value of result (0).
The counter receives its next value
When Period = 12: The new Result = the 12 - period moving average + the previous value of result.
The counter receives its next value
When Period = 13: The new Result = the 13 - period moving average + the previous value of result.
13 is the last value of the counter.
We end the FOR loop with the NEXT instruction.
We then display AverageResult.
This code simply means the "Variable" will, first of all get the beginning value of the series, then variable will
receive the next one (previous + 1) and so on until variable is equal to or greater than the last number in the
series. Then the loop is over.
Example: Average of the highest price over the 20 last bars
SUMhigh = 0
IF BarIndex < 5 THEN
MAhigh = Undefined
ELSE
FOR i = 0 TO 4 DO
SUMhigh = High[i]+SUMhigh
NEXT
ENDIF
MAhigh = SUMhigh / 5
RETURN MAhigh
Let us go back to the previous example (the 5-period moving average of "High"):
We can notice that we have just inverted the extremities of the scanned interval.
Mahigh = 0
SUMhigh = 0
IF BarIndex = 0 THEN
Mahigh = Undefined
ELSE
FOR i = 4 DOWNTO 0 DO
SUMhigh = High[i] + SUMhigh
NEXT
ENDIF
Mahigh = SUMhigh / 5
RETURN Mahigh
V 4.1.1 20160502
www.prorealtime.com
18 / 47
(Action n)
WEND
This code lets you show the number of bars separating the current candlestick from a previous higher
candlestick within the limit of 30 periods.
i = 1
WHILE high > high [i] and i < 30 DO
i = i + 1
WEND
RETURN i
The WHILE instruction does not recognize the value of i. Therefore, it cannot test whether i is equal to 10 or
not and the loop will not be processed, hence the count is equal to 0.
The correct code would be:
i = 0
Count = 0
WHILE i <> 11 DO
i = i + 1
Count = Count + 1
WEND
RETURN Count
In this code, i is initialized. The loop will then work correctly since the condition for beginning the loop is valid.
V 4.1.1 20160502
www.prorealtime.com
19 / 47
BREAK
The BREAK instruction allows you to make a forced exit out of a WHILE loop or a FOR loop. Combinations
are possible with the IF command, inside a WHILE loop or a FOR loop.
With WHILE
When we want to exit a conditional WHILE loop, we use BREAK in the following way:
WHILE (Condition) DO
(Action)
IF (ConditionBreak)
BREAK
WEND
The use of BREAK in a WHILE loop is only interesting if we want to test an additional condition for which the
value can not be known while in the WHILE loop. For example, lets look at a stochastic which is only
calculated in a bullish trend:
line = 0
Increase = (Close - Close[1]) > 0
i = 0
WHILE Increase[i] DO
i = i + 1
// Si high - low, we exit the loop to avoid a division by zero.
IF (high-low) = 0 then
BREAK
ENDIF
osc = (close low) / (high low)
line = AVERAGE [i] (osc)
WEND
RETURN line
With FOR
When we try to get out of an iterative FOR loop, without reaching the last (or first) value of the series, we use
BREAK.
FOR (Variable = BeginningValueOfTheSeries) TO EndingValueOfTheSeries DO
(Action)
BREAK
NEXT
Lets take for example an indicator cumulating increases of the volume of the last 19 periods. This indicator
will be equal to 0 if the volume decreases.
Count = 0
FOR i = 0 TO 19 DO
IF (Volume[i] > Volume[i + 1]) THEN
Count = Count + 1
ELSE
BREAK
ENDIF
NEXT
RETURN Count
In this code, if BREAK werent used, the loop would have continued until 19 (last element of the series) even
if the condition count is not valid.
However, with BREAK, as soon as the condition is valid, the result becomes 0.
V 4.1.1 20160502
www.prorealtime.com
20 / 47
CONTINUE
The CONTINUE instruction allows you to resume the program reader at the line where WHILE or FOR is
written, thus without restarting completely the loop (any incremented counter will thus keep its value and not
be reset to 0). This command is often used with BREAK, either to leave the loop (BREAK) or to stay in the
loop (CONTINUE).
With WHILE
Lets create a program counting the number of candlesticks whose close and open are greater than those of
the candlestick preceding them. If the condition is not valid, then the counter will be reset to 0.
Increase = Close > Close[1]
Count = 0
WHILE Open < Open[1] DO
IF Increase[Count] THEN
Count = Count + 1
CONTINUE
ENDIF
BREAK
WEND
RETURN Count
When using CONTINUE, if the IF condition is not valid, then the WHILE loop is not ended. This allows us to
count the number of patterns detected with this condition. Without the CONTINUE instruction, the program
would leave the loop, even if the IF condition is validated. Then, we would not be able to continue counting
the number of patterns detected and the result would be binary (1, 0).
With FOR
Lets create a program counting the number of candlesticks whose close and open are greater than those of
the candlestick preceding them. If the condition is not valid, then the counter will be reset to 0.
Increase = Close > Close[1]
Count = 0
FOR i = 1 TO BarIndex DO
IF Increase[Count] THEN
Count = Count + 1
CONTINUE
ENDIF
BREAK
NEXT
RETURN Count
FOR gives you the possibility to test the condition over all the data loaded. When used with CONTINUE, if
the IF condition is validated, then we do not leave the FOR loop and resume it with the next value of i. This is
how we count the number of patterns detected by this condition.
Without CONTINUE, the program would leave the loop, even if the IF condition is validated. Then, we would
not be able to count the number of patterns detected and the result would be binary (1, 0).
V 4.1.1 20160502
www.prorealtime.com
21 / 47
ONCE
The ONCE instruction is used to initialize a variable at a certain value "only ONE TIME".
Knowing that for the whole program, the language will read the code for each bar displayed on the chart
before returning the result, you must then keep in mind that ONCE:
Is processed only one time by the program including the second reading.
During the second reading of the program, it will stock the values calculated in the previous reading.
To fully understand how this command works, you need to perceive how the language processes the
code, hence the usefulness of the next example.
These are two programs returning respectively 0 and 15 and which only difference is the ONCE command
added:
Program 1
Program 2
1 Count = 0
1 ONCE Count = 0
2 i = 0
2 ONCE i = 0
3 IF i <= 5 THEN
3 IF i <= 5 THEN
Count = Count + i
Count = Count + i
i = i + 1
i = i + 1
6 ENDIF
6 ENDIF
7 RETURN Count
7 RETURN Count
V 4.1.1 20160502
www.prorealtime.com
22 / 47
Mathematical Functions
Common unary and binary Functions
Lets focus now on the Mathematical Functions. You will find in ProBuilder the main functions known in
mathematics. Please note that a and b are examples and can be numbers or any other variable in your
program.
MIN(a, b): calculate the minimum of a and b
MAX(a, b): calculate the maximum of a and b
ROUND(a): round a to the nearest whole number
ABS(a): calculate the absolute value of a
SGN(a): shows the sign of a (1 if positive, -1 if negative)
SQUARE(a): calculate a squared
SQRT(a): calculate the square root of a
LOG(a): calculate the Neperian logarithm of a
EXP(a): calculate the exponent of a
COS(a): calculate the cosine of a
SIN(a): calculate the sine of a
TAN(a): calculate the tangent of a
ATAN(a): calculate the arc-tangent of a
Lets code the example of the normal distribution in mathematics. Its interesting because it use the square
function, the square root function and the exponential function at the same time:
REM Normal Law applied to x = 10, StandardDeviation = 6 and MathExpectation = 8
REM Lets define the following variables in the variable option:
StandardDeviation = 6
MathExpectation = 8
x = 10
Indicator = EXP((1 / 2) * (SQUARE(x MathExpectation) / Ecarttype)) / (StandardDeviation
* SQRT(2 / 3.14))
RETURN Indicator
V 4.1.1 20160502
www.prorealtime.com
23 / 47
Summation functions
cumsum: Calculates the sum of a price or indicator over all bars loaded on the chart
The syntax of cumsum is:
cumsum (price or indicator)
Ex: cumsum(Close) calculates the sum of the close of all the bars loaded on the chart.
summation: Calculates the sum of a price or indicator over the last n bars
The sum is calculated starting from the most recent value (from right to left)
The syntax of summation is:
summation[number of bars]((price or indicator)
Ex: summation[20](Open) calculates the sum of the open of the last 20 bars.
Statistical functions
The syntax of all these functions is the same as the syntax for the Summation function, that is:
lowest[number of bars](price or indicator)
lowest: displays the lowest value of the price or indicator written between brackets, over the number of
periods defined
highest: displays the highest value of the price or indicator written between brackets, over the number
of periods defined
STD: displays the standard deviation of a price or indicator, over the number of periods defined
STE: displays the standard error of a price or indicator, over the number of periods defined
Logical operators
As any programming language, it is necessary to have at our disposal some Logical Operators to create
relevant indicators. These are the 4 Logical Operators of ProBuilder:
NOT(a): logical NO
a OR b: logical OR
a AND b: logical AND
a XOR b: exclusive OR
Calculation of the trend indicator: On Balance Volume (OBV):
IF NOT((Close > Close[1]) OR (Close = Close[1])) THEN
MyOBV = MyOBV - Volume
ELSE
MyOBV = MyOBV + Volume
ENDIF
RETURN MyOBV
ProBuilder instructions
RETURN: displays the result
CustomClose: displays a customizable price value; by default, this price is "Close"
CALL: calls another ProBuilder indicator to use in your current program
AS: names the result displayed
COLOURED: colors the displayed curve in with the color of your choice
V 4.1.1 20160502
www.prorealtime.com
24 / 47
RETURN
We have already seen in chapter I how important the RETURN instruction was. It has some specific
properties we need to know to avoid programming errors.
The main points to keep in mind when using RETURN in order to write a program correctly are that Return is
used:
One and only one time in each ProBuilder program
Always at the last line of code
Optionally with other functions such as AS and COLOURED
To display many results; we write RETURN followed with what we want to display and separated with a
comma (example: RETURN a,b)
REM or //
REM allows you to write remarks or comments inside the code. They are mainly useful to remember how a
function you coded works. These remarks will be read but of course not processed by the program. Lets
illustrate the concept with the following example:
REM This program returns the simple moving average over 20 periods applied to the closing
price
RETURN Average[20](Close)
Dont use special characters (examples: ,,,) in ProBuilder. This does not apply in the REM
or // sections (comments).
CustomClose
CustomClose is a constant allowing you to display the Close, Open, High, Low constants and many
others, which can be customized in the Settings window of the indicator.
Its syntax is the same as the one of the constants adapted to the timeframe of the chart:
CustomClose[n]
Example:
// Displays the average over 20 periods applied to CustomClose
RETURN CustomClose[2]
By clicking on the wrench in the upper left corner of the chart, you will see that it is possible to customize the
prices used in the calculation.
V 4.1.1 20160502
www.prorealtime.com
25 / 47
CALL
CALL allows you to use a personal indicator you have coded before in the platform.
The quickest method is to click Insert Function then select the "User Indicators" category and then select
the name of the indicator you want to use and click "Add".
For example, imagine you have coded the Histogram MACD and named it HistoMACD.
Select your indicator and click on "Add". You will see in the programming zone:
myHistoMACD = CALL HistoMACD
AS
The keyword AS allows you to name the different results displayed. This instruction is used with RETURN
and its syntax is:
RETURN Result1 AS "Curve Name", Result2 AS "Curve Name",
The advantage of this command is that it makes it easier to identify the different curves on your chart.
Example:
a = ExponentialAverage[200](Close)
b = WeightedAverage[200](Close)
c = Average[200](Close)
RETURN a AS "Exponential Average", b AS "Weighted Average", c AS "Arithmetical Average"
COLOURED
COLOURED is used after the RETURN command to color the curve displayed with the color of your choice,
defined with the RGB norm (red, green, blue). These are the main colors of this norm:
COLOR
V 4.1.1 20160502
RGB VALUE
(RED, GREEN, BLUE)
ENGLISH
(0, 0, 0)
Black
White
(255, 0, 0)
Red
(0, 255, 0)
Green
(0, 0, 255)
Blue
(255, 255, 0)
Yellow
Cyan
(255, 0, 255)
Magenta
www.prorealtime.com
26 / 47
The AS command can be associated with the COLOURED(. , . , .) command. This association must be used
in this order:
RETURN Indicator COLOURED(Red, Green, Blue) AS "Name Of The Curve"
Lets go back to the previous example and insert COLOURED in the "RETURN" line.
a = ExponentialAverage[200](Close)
b = WeightedAverage[200](Close)
c = Average[200](Close)
RETURN a COLOURED(255, 0, 0) AS "Exponential Moving Average", b COLOURED(0, 255, 0) AS
"WeightedMoving Average", c COLOURED(0, 0, 255) AS "Simple Moving Average"
V 4.1.1 20160502
www.prorealtime.com
27 / 47
Drawing instructions
The following instructions were added in version 10.3 of the software. They are available to use from this version
onwards. These instructions let you draw objects on charts and also draw custom candles and bar charts.
BACKGROUNDCOLOR : Lets you color the background of the chart or specific bars (such as odd/even
days). The colored zone starts halfway between the previous bar and the next bar
DRAWBARCHART : Draws a custom bar on the chart. Open, high, low and close can be constants or
variables.
Example: DRAWBARCHART (open, high, low, close) COLOURED (0, 255, 0)
DRAWCANDLE : Draws a custom candlestick on the chart. Open, high, low and close can be constants or
variables.
Example: DRAWCANDLE (open, high, low, close) COLOURED (0, 255, 0)
V 4.1.1 20160502
www.prorealtime.com
28 / 47
DRAWARROW : Draws an arrow pointing right. You need to define a point for the arrow (x and y axis). You
can also choose a color.
V 4.1.1 20160502
www.prorealtime.com
29 / 47
DRAWTEXT : Adds a text field to the chart with the text of your choice at a specified location.
DRAWONLASTBARONLY : Parameter that lets you draw drawn objects on the last bar only. This parameter
should always be used with "CALCULATEONLASTBARS" to optimize calculations.
www.prorealtime.com
30 / 47
V 4.1.1 20160502
www.prorealtime.com
31 / 47
Note: we have displayed the exponential moving average over 10 and 20 periods both applied to the close in
order to highlight the results of the indicator.
You can find other candlestick pattern indicators in the "Exercises" chapter later in this manual.
V 4.1.1 20160502
www.prorealtime.com
32 / 47
www.prorealtime.com
33 / 47
Inactivity STOP
An inactivity STOP closes the position when the gains have not obtained a certain objective (defined in % or
in points) over a certain period (defined in number of bars).
Remember to define the variables in the "Variables" section.
Example of Inactivity Stop on Intraday Charts:
This stop must be used with those two indicators:
The first indicator juxtaposed to the curve of the price
The second indicator must be displayed in a separated chart
Indicator1
// We define in the variable option:
// MyVolatility = 0.01 represents variation rate between the each part of the range and
the close
IF IntradayBarIndex = 0 THEN
ShortTarget = (1 - MyVolatility) * Close
LongTarget = (1 + MyVolatility) * Close
ENDIF
RETURN ShortTarget AS "ShortTarget", LongTarget AS "LongTarget"
Indicator2
// We define in the variable option:
REM We supposed that you take an "On Market Price" position
// MyVolatility = 0.01 represents variation rate between the each part of the range and
the close
// NumberOfBars=20: the close can fluctuate within the range defined during a maximum of
NumberOfBars before the position is cut (Result = 1)
Result = 0
Cpt = 0
IF IntradayBarIndex = 0 THEN
ShortTarget = (1 - MyVolatility) * Close
LongTarget = (1 + MyVolatility) * Close
ENDIF
FOR i = IntradayBarIndex DOWNTO 1 DO
IF Close[i] >= ShortTarget AND Close[i] <= LongTarget THEN
Cpt = Cpt + 1
ELSE
Cpt = 0
ENDIF
IF Cpt = NumberOfBars THEN
Result = 1
ENDIF
NEXT
RETURN Result
V 4.1.1 20160502
www.prorealtime.com
34 / 47
Trailing Stop
A trailing STOP follows the evolution of the price dynamically and indicates when to close a position.
We suggest you two ways to code the trailing STOP, the first one representing a Dynamic Trailing Stop Loss,
and the other one a Dynamic Trailing Take Profit.
Dynamic Trailing STOP LOSS (to be used in intraday trading)
// Define the following variables in the variable section:
// StartingTime = 090000 (this is an example for 9 am; set this to the time you entered
your position)
REM We supposed that you take an "On Market Price" position
// Amplitude represents the variation rate of the "Cut" curve compared to the "Lowest"
curves (for example, we can take Amplitude = 0.95)
IF Time = StartingTime THEN
IF lowest[5](Close) < 1.2 * Low THEN
IF lowest[5](Close) >= Close THEN
Cut = Amplitude * lowest[5](Close)
ELSE
Cut = Amplitude * lowest[20](Close)
ENDIF
ELSE
Cut = Amplitude * lowest[20](Close)
ENDIF
ENDIF
RETURN Cut AS "Trailing Stop Loss"
V 4.1.1 20160502
www.prorealtime.com
35 / 47
C h a p t e r I V: E x e r c i s e s
V 4.1.1 20160502
www.prorealtime.com
36 / 47
C h a p t e r I V: E x e r c i s e s
In this code, we define a doji to be a candlestick with a range (High Close) is greater
than 5 times the absolute value of (Open Close).
Indicators
BODY MOMENTUM
The Body Momentum is mathematically defined by:
BodyMomentum = 100 * BodyUp / (BodyUp + BodyDown)
BodyUp is a counter of bars for which close is greater than open during a certain number of periods.
BodyDown is a counter of bars for which open is greater than close during a certain number of periods.
Periods = 14
b = Close - Open
IF BarIndex > Periods THEN
Bup = 0
Bdn = 0
FOR i = 1 TO Periods
IF b[i] > 0 THEN
Bup = Bup + 1
ELSIF b[i] < 0 THEN
Bdn = Bdn + 1
ENDIF
NEXT
BM = (Bup / (Bup + Bdn)) * 100
ELSE
BM = Undefined
ENDIF
RETURN BM AS "Body Momentum"
V 4.1.1 20160502
www.prorealtime.com
37 / 47
C h a p t e r I V: E x e r c i s e s
Williams %R
This is an indicator very similar to the Stochastic oscillator. To draw it, we define 2 curves:
1) The curve of the highest of high over 14 periods
2) The curve of the lowest of low over 14 periods
The %R curve is defined by this formula: (Close Lowest Low ) / (Highest High Lowest Low) * 100
HighestH = highest[14](High)
LowestL = lowest[14](Low)
MyWilliams = (Close - LowestL) / (HighestH - LowestL) * 100
RETURN MyWilliams AS "Williams %R"
Bollinger Bands
The middle band is a simple 20-period moving average applied to close.
The upper band is the middle band plus 2 times the standard deviation over 20 periods applied to close.
The lower band is the middle band minus 2 times the standard deviation over 20 periods applied to close.
a = Average[20](Close)
// We define the standard deviation.
StdDeviation = STD[20](Close)
Bsup = a + 2 * StdDeviation
Binf = a - 2 * StdDeviation
RETURN a AS "Average", Bsup AS "Bollinger Up", Binf AS "Bollinger Down"
V 4.1.1 20160502
www.prorealtime.com
38 / 47
Glossary
Glossary
A
CODE
SYNTAX
FUNCTION
ABS
ABS(a)
AccumDistr
AccumDistr(price)
ADX
ADX[N]
ADXR
ADXR[N]
AND
a AND b
AroonDown
AroonDown[P]
AroonUp
AroonUp[P]
ATAN
ATAN(a)
AS
RETURN Result AS
"ResultName"
Average
Average[N](price)
AverageTrueRange
AverageTrueRange[N](price)
B
CODE
SYNTAX
FUNCTION
BACKGROUNDCOLOR
BACKGROUNDCOLOR(R,G,
B,a)
BarIndex
BarIndex
BollingerBandWidth
BollingerBandWidth[N](price)
BollingerDown
BollingerDown[N](price)
BollingerUp
BollingerUp[N](price)
BREAK
V 4.1.1 20160502
www.prorealtime.com
39 / 47
Glossary
C
CODE
SYNTAX
FUNCTION
CALCULATEONLASTBARS
DEFPARAM
CalculateOnLastBars = 200
CALL
myResult=CALL myFunction
CCI
CCI[N](price) or CCI[N]
ChaikinOsc
ChaikinOsc[Ch1, Ch2](price)
Chaikin oscillator
Chandle
Chandle[N](price)
ChandeKrollStopUp
ChandeKrollStopUp[Pp, Qq,
X]
ChandeKrollStopDown
ChandeKrollStopDown[Pp,
Qq, X]
Close
Close[N]
COLOURED
RETURN x
COLOURED(R,G,B)
COS
COS(a)
Cosine Function
CROSSES OVER
a CROSSES OVER b
CROSSES UNDER
a CROSSES UNDER b
cumsum
cumsum(price)
CurrentDayOfWeek
CurrentDayOfWeek
CurrentHour
CurrentHour
CurrentMinute
CurrentMinute
CurrentMonth
CurrentMonth
CurrentSecond
CurrentSecond
CurrentTime
CurrentTime
CurrentYear
CurrentYear
CustomClose
CustomClose[N]
Cycle
Cycle(price)
Cycle Indicator
V 4.1.1 20160502
www.prorealtime.com
40 / 47
Glossary
D
CODE
SYNTAX
FUNCTION
Date
Date[N]
Day
Day[N]
Days
Days[N]
DayOfWeek
DayOfWeek[N]
DClose
DClose(N)
DEMA
DEMA[N](price)
DHigh
DHigh(N)
DI
DI[N](price)
DIminus
DIminus[N](price)
DIplus
DIplus[N](price)
DLow
DLow(N)
DO
DOpen
DOpen(N)
DOWNTO
See FOR
DPO
DPO[N](price)
DRAWARROW
DRAWARROW(x1,y1)
DRAWARROWDOWN
DRAWARROWDOWN(x1,y1)
DRAWARROWUP
DRAWARROWUP(x1,y1)
DRAWBARCHART
DRAWCANDLE
DRAWELLIPSE
DRAWELLIPSE(x1,y1,x2,y2)
DRAWHLINE
DRAWHLINE(y1)
DRAWLINE
DRAWLINE(x1,y1,x2,y2)
DRAWONLASTBARONLY
DEFPARAM
DrawOnLastBarOnly = true
DRAWRECTANGLE
V 4.1.1 20160502
www.prorealtime.com
41 / 47
Glossary
DRAWSEGMENT
DRAWTEXT
DRAWVLINE
DRAWVLINE(x1)
E
CODE
SYNTAX
FUNCTION
EaseOfMovement
EaseOfMovement[I]
ELSE
See IF/THEN/ELSE/ENDIF
ELSEIF
See
IF/THEN/ELSIF/ELSE/ENDIF
EMV
EMV[N]
ENDIF
See IF/THEN/ELSE/ENDIF
EndPointAverage
EndPointAverage[N](price)
EXP
EXP(a)
ExponentialAverage
ExponentialAverage[N](price)
F-G
CODE
SYNTAX
FUNCTION
FOR/TO/NEXT
ForceIndex
ForceIndex(price)
H
CODE
SYNTAX
FUNCTION
High
High[N]
highest
highest[N](price)
HistoricVolatility
HistoricVolatility[N](price)
Hour
Hour[N]
V 4.1.1 20160502
www.prorealtime.com
42 / 47
Glossary
I-J-K
CODE
SYNTAX
FUNCTION
IF/THEN/ENDIF
IF a THEN b ENDIF
IF/THEN/ELSE/ENDIF
IntradayBarIndex
IntradayBarIndex[N]
L
CODE
LinearRegression
SYNTAX
LinearRegression[N](price)
LinearRegressionSlope LinearRegressionSlope[N]
FUNCTION
(price)
LOG
LOG(a)
Low
Low[N]
lowest
lowest[N](price)
M
CODE
SYNTAX
FUNCTION
MACD
MACD[S,L,Si](price)
MACDline
MACDLine[S,L,Si](price)
MassIndex
MassIndex[N]
MAX
MAX(a,b)
MedianPrice
MedianPrice
MIN
MIN(a,b)
Minute
Minute
MOD
a MOD b
Momentum
Momentum[I]
MoneyFlow
MoneyFlow[N](price)
MoneyFlowIndex
MoneyFlowIndex[N]
Month
Month[N]
V 4.1.1 20160502
www.prorealtime.com
43 / 47
Glossary
N
CODE
SYNTAX
FUNCTION
NEXT
See FOR/TO/NEXT
NOT
Not A
O
CODE
SYNTAX
FUNCTION
OBV
OBV(price)
On-Balance-Volume indicator
ONCE
ONCE VariableName =
VariableValue
Open
Open[N]
OR
a OR b
Logical Operator OR
P-Q
CODE
SYNTAX
FUNCTION
Pipsize
Pipsize
PriceOscillator
PriceOscillator[S,L](price)
PositiveVolumeIndex
PriceVolumeIndex(price)
PVT
PVT(price)
R
CODE
SYNTAX
FUNCTION
R2
R2[N](price)
Range
Range[N]
REM
REM comment
Repulse
Repulse[N](price)
RETURN
RETURN Result
ROC
ROC[N](price)
ROUND
ROUND(a)
RSI
RSI[N](price)
V 4.1.1 20160502
www.prorealtime.com
44 / 47
Glossary
S
CODE
SYNTAX
FUNCTION
SAR
SAR[At,St,Lim]
SARatdmf
SARatdmf[At,St,Lim](price)
SIN
SIN(a)
SGN
SGN(a)
SMI
SMI[N,SS,DS](price)
SmoothedStochastic
SmoothedStochastic[N,K]
(price)
Smoothed Stochastic
SQUARE
SQUARE(a)
SQRT
SQRT(a)
STD
STD[N](price)
STE
STE[N](price)
Stochastic
Stochastic[N,K](price)
summation
summation[N](price)
Supertrend
Supertrend[STF,N]
T
CODE
SYNTAX
FUNCTION
TAN
TAN(a)
TEMA
TEMA[N](price)
THEN
See IF/THEN/ELSE/ENDIF
Time
Time[N]
TimeSeriesAverage
TimeSeriesAverage[N](price)
TO
See FOR/TO/NEXT
Today
YYYYMMDD
Today's date
TotalPrice
TotalPrice[N]
TR
TR(price)
TriangularAverage
TriangularAverage[N](price)
TRIX
TRIX[N](price)
TypicalPrice
TypicalPrice[N]
V 4.1.1 20160502
www.prorealtime.com
45 / 47
Glossary
U
CODE
Undefined
SYNTAX
a = Undefined
FUNCTION
V
CODE
SYNTAX
FUNCTION
Variation
Variation(price)
Volatility
Volatility[S, L]
Chaikin volatility
Volume
Volume[N]
Volume indicator
VolumeOscillator
VolumeOscillator[S,L]
Volume Oscillator
VolumeROC
VolumeROC[N]
W
CODE
SYNTAX
FUNCTION
WeightedAverage
WeightedAverage[N](price)
WeightedClose
WeightedClose[N]
WEND
See WHILE/DO/WEND
WHILE/DO/WEND
WilderAverage
WilderAverage[N](price)
Williams
Williams[N](close)
%R de Williams indicator
WilliamsAccumDistr
WilliamsAccumDistr(price)
X
CODE
XOR
V 4.1.1 20160502
SYNTAX
a XOR b
FUNCTION
www.prorealtime.com
46 / 47
Glossary
Y
CODE
SYNTAX
FUNCTION
Year
Year[N]
Yesterday
Yesterday[N]
Z
CODE
SYNTAX
FUNCTION
ZigZag
ZigZag[Zr](price)
ZigZagPoint
ZigZagPoint[Zp](price)
Other
CODE
FUNCTION
CODE
FUNCTION
Addition Operator
<
Substraction Operator
>
Multiplication Operator
<=
Inferiority Operator
Division Operator
>=
Superiority Operator
Equality Operator
//
<>
Difference Operator
V 4.1.1 20160502
www.prorealtime.com
47 / 47
www.prorealtime.com