Introduction to ProBuilder Programming
ProBuild is a BASIC-type programming language that allows you to create personalized technical indicators, trading systems and market scannign programs for the ProRealTime platform.
This article gives a simple introduction to ProBuilder Programming
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.
Add new indicator
- Click on "New indicator" to access the programming window. You can
choose between:
- Programming directly an indicator in the text zone designed for writing code
- Using the help function by clicking on "Insert Function". This will open a new window in which you can find all the functions available
Specificities of ProBuilder programming language
- The main ideas to know in the ProBuilder language are:
- It is not necessary to declare variables
- It is not necessary to type variables
- There is no difference between capital letters and small letters
- We use the same symbol "=" for mathematic equality and to attribute a value to a variable
- Financial constants
- Price and volume constants adapted to the timeframe of the chart
Open
: Opening price of each barHigh
: Highest price of each barLow
: Lowest price of each barClose
: Closing price of each barVolume
: The number of securities or contracts exchanged at each bar
- 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. This rule is valid for any
constant. For example:
- Value of the closing price of the current bar:
Close
- Value of the closing price preceding the current bar:
Close[1]
- Value of the closing price preceding the nth bar preceding
the current one:
Close[n]
- Value of the closing price of the current bar:
- Price and volume constants adapted to the timeframe of the chart
- Daily price constants
- Contrary to the constants adapted to the time frame of the chart, the daily price constants refer to the value of the day, regardless the timeframe of the chart
- The daily price constants use brackets and not square brackets to
call the values of previous bars
DOpen(n)
: Opening price of the nth day before the one of the current barDHigh(n)
: Highest price of the nth day before the one of the current barDLow(n)
: Lowest price of the nth day before the one of the current barDClose(n)
: Closing price of the nth day before the one of the current bar
- If "n" is equal to 0, "n" references the current day. As the maximum
and minimum values are not defined for
, we obtain a result for previous days but not for the current day
- Temporal constants
Date
: indicates the date of the close of each bar in the format YearMonthDay (YYYYMMDD)- Temporal constants are considered as whole numbers
Time
: indicates the hour of the closing price of each bar in the format HourMinuteSecond (HHMMSS)Minute
: Minute of the close of each bar (from 0 to 59): Only for intraday chartsHour
: Hour of the close of each bar (from 0 to 23): Only for intraday charts.Day
: Day of the months of the closing price of each bar (from 1 to 28 or 29 or 30 or 31)Month
: Month of the closing price of each bar (from 1 to 12)Year
: Year of the closing price of each barDayOfWeek
: Day of the Week of the close of each bar (does not use weekend days) (1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday)Time
indicates the closing time of each barCurrentTime
indicates the current market timeDays
: Counter of days since 1900BarIndex
: Counter of bars since the beginning of the displayed historical dataIntradayBarIndex
: Counter of intraday bars
- Constants derived from price
Range
: difference between High and LowTypicalPrice
: average between High, Low and CloseWeightedClose
: weighted average of High (weight 1), Low (weight 1) and Close (weight 2)MedianPrice
: average between High and LowTotalPrice
: average between Open, High, Low and Close
- The undefined constant
Undefined
: undefined data (equivalent to an empty box)
How to use pre-existing indicators?
1 | NameOfFunction [calculated over n periods] (applied to which price or indicator) |
For example:
Calculating the exponential moving average over 20 periods applied to the closing price:
1
RETURN ExponentialAverage[20](Close)
Calculating the weighted moving average over 20 bars applied to the typical price:
1
2mm = WeightedAverage[20](TypicalPrice)
RETURN mm
Control Structures
IF conditions
1
2
3
4
5
6
7IF condition1 THEN
procedure1
ELSIF condition2 THEN
procedure2
ELSE
procedure3
ENDIFFOR loop
1
2
3
4
5
6
7FOR (Variable = BeginningValueOfTheSeries) TO EndingValueOfTheSeries DO
(Action)
NEXT
FOR (Variable = EndingValueOfTheSeries) DOWNTO BeginningValueOfTheSeries DO
(Action)
NEXTWHILE loop
1
2
3
4WHILE (Condition) DO
(Action 1)
WENDBREAK
can be used to stop the loop andCONTINUE
can be used to jump to next loopONCE
: TheONCE
instruction is used to initialize a variable at a certain value "only ONE time" for the whole program- A variable without
ONCE
has scope in each run - A variable with
ONCE
has global scope
- A variable without
Logical operators
NOT(a)
: logical NOa OR b
: logical ORa AND b
: logical ANDa XOR b
: exclusive OR
Mathematical Functions
MIN(a, b)
: calculate the minimum ofa
andb
MAX(a, b)
: calculate the maximum ofa
andb
ROUND(a)
: rounda
to the nearest whole numberABS(a)
: calculate the absolute value ofa
SGN(a)
: shows the sign ofa
(1 if positive, -1 if negative)SQUARE(a)
: calculatea
squaredSQRT(a)
: calculate the square root ofa
LOG(a)
: calculate the Neperian logarithm ofa
EXP(a)
: calculate the exponent ofa
COS(a)
: calculate the cosine ofa
SIN(a)
: calculate the sine ofa
TAN(a)
: calculate the tangent ofa
ATAN(a)
: calculate the arc-tangent ofa
Charting comparison functions
a CROSSES OVER b
: thea
curve crosses over theb
curvea CROSSES UNDER b
: thea
curve crosses under theb
curve
Summation functions
cumsum
: Calculates the sum of a price or indicator over all bars loaded on the chart1
cumsum (price or indicator)
summation
: Calculates the sum of a price or indicator over the last n bars1
summation[number of bars]((price or indicator)
Statistical functions
lowest
: displays the lowest value of the price or indicator written between brackets, over the number of periods definedhighest
: displays the highest value of the price or indicator written between brackets, over the number of periods definedSTD
: displays the standard deviation of a price or indicator, over the number of periods definedSTE
: displays the standard error of a price or indicator, over the number of periods defined
ProBuilder instructions
RETURN
: displays the resultCustomClose
: displays a customizable price value; by default, this price isClose
CALL
: calls anotherProBuilder
indicator to use in your current program. 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 "Add1
myHistoMACD = CALL HistoMACD
AS
: names the result displayed1
RETURN Result1 AS "Curve Name", Result2 AS "Curve Name"
COLOURED
: colours the displayed curve in with the colour of your choice1
RETURN Indicator COLOURED(Red, Green, Blue) AS "Name Of The Curve"
REM
or//
: One line comment
Drawing instructions
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
1
BACKGROUNDCOLOR (0, 127, 255, 25)
DRAWBARCHART : Draws a custom bar on the chart. Open, high, low and close can be constants or variables
1
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
1
DRAWCANDLE (open, high, low, close) COLOURED (0, 255, 0)
DRAWARROW : Draws an arrow pointing right. You need to define a point for the arrow (x and y axis). You can also choose a colour
1
DRAWARROW (x1, y1) COLOURED (R, V, B, a)
- DRAWARROWUP : Draws an arrow pointing up
- DRAWARROWDOWN : Draws an arrow pointing down
DRAWRECTANGLE : Draws a rectangle on the chart
1
DRAWRECTANGLE (x1, y1, x2, y2) COLOURED (R, V, B, a)
DRAWELLIPSE : Draws an ellipse on the chart
1
DRAWELLIPSE (x1, y1, x2, y2) COLOURED (R, V, B, a)
DRAWSEGMENT : Draws a segment on the chart
1
DRAWSEGMENT (x1, y1, x2, y2) COLOURED (R, V, B, a)
DRAWTEXT : Adds a text field to the chart with the text of your choice at a specified location
1
DRAWTEXT ("your text", x1, y1) COLOURED (R, V, B, a)