WHS NanoTrader Express Functions ENG
WHS NanoTrader Express Functions ENG
WHS NanoTrader Express Functions ENG
Express Functions
www.fipertec.com
Page 1 of 110
Contents
Introduction ............................................................................................................................... 6
Symbol information ................................................................................................................... 9
SymbolName() .................................................................................................................................... 9
PointValue() ...................................................................................................................................... 10
TickSize() ........................................................................................................................................... 11
TickValue()......................................................................................................................................... 12
PrevDayHigh() / Low() / Open() / Close() .......................................................................................... 13
PrevDayVol() ..................................................................................................................................... 14
Time information ..................................................................................................................... 15
DayOfWeek()..................................................................................................................................... 15
Duration() .......................................................................................................................................... 16
IsNewDay() ........................................................................................................................................ 17
NumericToTime() .............................................................................................................................. 18
TimeToNumeric() .............................................................................................................................. 19
NumericToDate() .............................................................................................................................. 20
DateToNumeric() .............................................................................................................................. 21
GetExpiration() .................................................................................................................................. 22
Alerting & Informing ................................................................................................................ 23
MessageBox() .................................................................................................................................... 23
PlaySound() ....................................................................................................................................... 24
SendEmail() ....................................................................................................................................... 25
Screenshot() ...................................................................................................................................... 26
ScreenshotEx() .................................................................................................................................. 27
ShowTip() .......................................................................................................................................... 29
Highlight() / HighlightRGB() .............................................................................................................. 31
HighlightAT() / HighlightRGBat() ....................................................................................................... 33
Annotate() / AnnotateRGB() ............................................................................................................. 34
AnnotateAT() / AnnotateRGBAT()..................................................................................................... 35
CreateFile()........................................................................................................................................ 36
NumericToString() ............................................................................................................................. 37
PriceToString()................................................................................................................................... 38
TimeToString()................................................................................................................................... 39
Page 2 of 110
IsBarCompleted() .............................................................................................................................. 40
Loops & Arrays ......................................................................................................................... 41
For … to / For … downto ................................................................................................................... 41
While … do ........................................................................................................................................ 43
SetArrayTo() / SetArraySize() / GetArraySize() ................................................................................. 44
Indexing & Efficient programming ........................................................................................... 46
CurrentBarIndex() / FinalBarIndex() ................................................................................................. 46
IndexOfHighest() / IndexOfLowest() ................................................................................................. 47
CalculateAtEveryTick() ...................................................................................................................... 48
IsFirstBar / IsFinalBar and associated functions ...................................................................... 50
IsFinalBar() / IsFirstBar().................................................................................................................... 50
MovingAverage()............................................................................................................................... 52
ExpMovingAverage() ......................................................................................................................... 53
RSI() ................................................................................................................................................... 54
StdDev()............................................................................................................................................. 55
Unaggregate() ................................................................................................................................... 56
Mathematical functions ........................................................................................................... 58
AbsValue() ......................................................................................................................................... 58
Sign() ................................................................................................................................................. 59
Floor() / Ceiling() ............................................................................................................................... 60
Sum() ................................................................................................................................................. 61
Atr() ................................................................................................................................................... 62
AtrAbs() ............................................................................................................................................. 63
Sine() ................................................................................................................................................. 64
Cosine() ............................................................................................................................................. 65
Tangent() ........................................................................................................................................... 66
ArcTangent() ..................................................................................................................................... 67
Exp() .................................................................................................................................................. 68
Log() .................................................................................................................................................. 69
Power().............................................................................................................................................. 70
SquareRoot() ..................................................................................................................................... 71
Highest() ............................................................................................................................................ 72
Lowest()............................................................................................................................................. 73
IsZero() .............................................................................................................................................. 74
Page 3 of 110
IsNonZero() ....................................................................................................................................... 75
Max() ................................................................................................................................................. 76
Min().................................................................................................................................................. 77
Round() ............................................................................................................................................. 78
RoundMultiple() ................................................................................................................................ 79
NormalCDF()...................................................................................................................................... 80
NormalPDF()...................................................................................................................................... 81
Charting functions .................................................................................................................... 82
Plotline() ............................................................................................................................................ 82
Plot().................................................................................................................................................. 83
Plotband() ......................................................................................................................................... 84
Plotcrossinglines() ............................................................................................................................. 85
Plotbars()........................................................................................................................................... 86
Plotcandles() ..................................................................................................................................... 87
GetPriceFormat() .............................................................................................................................. 88
SetYscaleFormat() ............................................................................................................................. 89
Importing series ....................................................................................................................... 90
Importing a series from a platform built-in indicator ....................................................................... 90
Importing a series from another express indicator .......................................................................... 91
Importing a price series from a symbol ............................................................................................ 92
Creating customized stops and targets ................................................................................... 93
SetIntraPeriodUpdate()..................................................................................................................... 93
EntryPrice() ....................................................................................................................................... 94
EntryPriceOriginal() ........................................................................................................................... 95
BarsSinceEntry() ................................................................................................................................ 96
IsIntradayEntry() ............................................................................................................................... 97
MarketPosition() ............................................................................................................................... 98
MinPriceEntryBar() / MaxPriceEntryBar()......................................................................................... 99
SetLongTrigger() / SetShortTrigger() ............................................................................................... 100
SetStopPrice() ................................................................................................................................. 102
SetTargetPrice() .............................................................................................................................. 103
Predefined interpretation tools ............................................................................................. 104
CrossesAbove() / CrossesBelow() ................................................................................................... 104
CrossesAboveThreshold() / CrossesBelowThreshold() ................................................................... 105
Page 4 of 110
Triggerline() ..................................................................................................................................... 106
Swing() ............................................................................................................................................ 107
Bands() ............................................................................................................................................ 108
TwoThresholds() ............................................................................................................................. 109
Additional tips ........................................................................................................................ 110
Using external text editors.............................................................................................................. 110
Page 5 of 110
Introduction
This manual offers an overview of the available functions in the Express Module, intended as an
educational tool to aid a step by step learning process. The functions are logically classified by
category and grouped together to reflect a close relation to one another.
For every function, described in this manual, an example is provided to illustrate its utility and
execution. The examples can be copy-pasted from this manual into the Express editor (see the
appendix to the introduction for details on p. 7). Please note that the examples are solely offered
for evaluation purposes, and must not be considered an adequate strategy for trading.
Before starting programming in WHS NanoTrader using the Express Module, it is important to
familiarize oneself with the platform’s most basic principles. These principles are well documented
and explained in our platform manuals, video clips, and many forums, which can all be accessed
from our client website.
Our video clips, in particular, deserve special recommendation. There are 75 video clips illustrating
general platform capabilities and 42 video clips describing programming procedures. The
programming video clips are distinctly separated into a theoretical explanation on the one hand and
a practical example on the other.
Not only will the user experience freedom from his platform, as he will be duly notified by an
indicator or signal, so too will the user experience freedom of creativity, thanks to an almost endless
number of possible applications and customizations (colors, messages, sounds, etc.).
Array functions, on the other hand, are intended for more experienced users with very specific
needs.
A very nice feature that falls under this category is CalculateAtEveryTick(), which allows the user to
save a tremendous amount of computing capacity by holding calculations until the end of a period,
rather than re-calculating the entire series at every tick.
Page 6 of 110
IsFirstBar / IsFinalBar and Associated Functions
These functions should be used to concentrate all the instructions that do not need to be repeated
at every bar. For example, this is the reason why IsFirstBar/IsFinalBar is used in conjunction with
MovingAverage and ExpMovingAverage.
Mathematical Functions
This section is a straight-forward recapitulation of mathematical tools incorporated in Express, which
will likely bring back fond memories of one’s high-school days and teachers.
Charting Functions
This is a very interesting function area, allowing the user to express his creativity in customizing
chart representation, such as background, chart color and type.
Importing Series
Answers the common request of applying one series to another, e.g. applying an RSI to a Moving
Average.
Page 7 of 110
Appendix to the Introduction
How to copy an express code from the manual and add it the express editor for display.
Select the text from the manual’s example (Ctrl 1. Click Add an Indicator
+ A), right-click, and copy (or Ctrl + C) 2. Select Express and Express again
3. Click Display in Master Chart or in a sub
window
4. Insert as Sentimentor
Page 8 of 110
Symbol information
SymbolName()
Definition:
Format:
• string SymbolName()
Example:
• Below we generate a message each time the condition (close > close[1]) and (close > close[2]) is
verified. The message is made of two parts, a piece of text and the name of the symbol:
Express f_SymbolName
Calculation
Interpretation
begin
end
Page 9 of 110
PointValue()
Definition:
Format:
• Float PointValue()
Example:
• Displays the monetary values of a single point in DAX and MINI S&P futures: EUR 25 and USD 50
respectively.
Express f_PointValue
vars
Series a;
calculation
a = PointValue();
interpretation
begin
end
Page 10 of 110
TickSize()
Definition:
Format:
• Float TickSize()
Example:
• Indicator a displays the number of ticks par bar for a given instrument.
Express f_TickSize
Vars
Series
a;
Calculation
a = (h-l)/TickSize();
Interpretation
begin
end
Page 11 of 110
TickValue()
Definition:
Format:
• Float TickValue ()
Example:
• Indicator a displays the monetary values of the daily price variations of a given instrument.
Express f_TickValue;
Vars
Series
a;
Calculation
a = (h - l)/TickSize()*TickValue();
Interpretation
begin
end
Page 12 of 110
PrevDayHigh() / Low() / Open() / Close()
Definition:
Format:
• Float PrevDayHigh() …
Example:
• The high, low, open and close values of the previous days are represented in the chart below by
the colored lines.
Express f_PrevDayOpenCloseHighLow;
Vars
Series
yopen, yclose, yhigh, ylow;
Calculation
yopen = PrevDayOpen();
yclose = PrevDayClose();
yhigh = PrevDayHigh();
ylow = PrevDayLow();
Interpretation
begin
end
Page 13 of 110
PrevDayVol()
Definition:
• Returns the volume of the previous day or void in case the data is not available.
Format:
• Float PrevDayVol ()
Example:
• The value of the volume of the previous days is displayed in the sub window:
Express f_PrevDayVol
Vars
Series
yvolume;
Calculation
yvolume = PrevDayVol();
Interpretation
begin
end
Page 14 of 110
Time information
DayOfWeek()
Definition:
Format:
Example:
Express f_DayOfWeek
vars
calculation
interpretation
begin
end
Page 15 of 110
Duration()
Definition:
Format:
Example:
• Below we are looking at the last candle of a 1min chart on the Dax future:
o Open time is 12:59:00.
o Current time is 12:59:51.
• Our indicator displays three durations in seconds between different times:
o Red: Duration between current and open times = 51.
o Blue: Duration between current time and $StartTime (= 12:52) = 4712.
o Green: Duration between current “date time” now and 3 candles ago: 1733.
Express f_Duration
vars
series
a, b, d;
input
$StartTime(0800, 2359, 1252);
calculation
if IsFinalBar() then
begin
a = Duration(timeOpen, time);
b = Duration(NumericToTime($StartTime), time);
d = Duration(dateTime[3], dateTime);
end
interpretation
begin
end
1
Express predefined time series are: date, dateOpen, time, timeOpen, dateTime, dateTimeOpen.
2
471 seconds = 7 x 60 + 0.85 x 60 seconds = 7 minutes + 51 seconds. Hence current time is: 12:52:00 +
00:07:51 = 12:59:51.
3
173 seconds = 2 x 60 + 51 seconds.
Page 16 of 110
IsNewDay()
Definition:
Format:
• bool IsNewDay()
Example:
• Below the background of the first candle of each day is highlighted in magenta:
Express f_IsNewDay
calculation
interpretation
begin
end
Page 17 of 110
NumericToTime()
Definition:
• Converts a 4 digits number into a HHMM time value (e.g. 1545 becomes 15:45).
o If the first 2 digits are more than 23, HH is set to 23.
o If the second 2 digits are more than 59, HH is set to 59.
Format:
Example:
• Below we create a blocker which blocks trades outside the 09:00 – 20:00 interval as indicated
by the darker background color:
Vars
Input
$t1(0,2400,900), $t2(0,2400,2000);
Calculation
Interpretation
begin
if (time >= NumericToTime($t1)) and
(time <= NumericToTime($t2)) then
sentiment = senti_pass;
else
sentiment = senti_block;
end
Page 18 of 110
TimeToNumeric()
Definition:
• Converts a HHMM time value into a 4 digits number (e.g. 15:45 becomes 1545).
Format:
Example:
• Below we display in the sub-window the number of minutes of the open time of each bar:
express f_TimeToNumeric
vars
calculation
hhmn = TimeToNumeric(timeopen);
mn = round(100*((hhmn/100) - floor(hhmn/100)),2);
interpretation
begin
end
plot(mn,blue,2);
Page 19 of 110
NumericToDate()
Definition:
• Converts a 6 digits number into a YYYYMMDD time value (e.g. 130423 becomes 2013-04-23).
o The first group of 2 digits cannot be larger than 99.
o If the second group of 2 digits is more than 12, MM is set to 12.
o If the third group of 2 digits is more than the number of days in a given month, DD is set
to that number of days.
Format:
Example:
• Below we create a blocker which blocks trades outside the [2013-04-10;2013-05-10] interval as
indicated by the darker background color:
Vars
Input
$day1(130401,131231,130410),
$day2(130401,131231,130510);
Calculation
Interpretation
begin
if (date >= NumericToDate($day1)) and
(date <= NumericToDate($day2)) then
sentiment = senti_pass;
else
sentiment = senti_block;
end
Page 20 of 110
DateToNumeric()
Definition:
• Converts a YYYYMMDD time value into a 6 digits number (e.g. 2013-04-23 becomes 130423).
Format:
Example:
• Below we display in the sub-window under a daily chart the day of the month:
express f_DateToNumeric
vars
calculation
yymmdd = DateToNumeric(dateopen);
dd = 100*round(((yymmdd/100) -
floor(yymmdd/100)),2);
interpretation
begin
end
plot(dd,blue,2);
Page 21 of 110
GetExpiration()
Definition:
• Renvoie la date et l'heure d'expiration du symbole auquel le sentimentor Express est rattaché.
Si le symbole n'a pas de date d'échéance, la fonction indiquera le 1er janvier 1970 à 0:00.
Format:
• time GetExpiration()
Example:
• Ci-dessous, nous utilisons cette fonction comme un bloqueur afin d'empêcher l'exécution des
signaux de trading le jour d'expiration.
Express f_GetExpiration
Calculation
Interpretation
begin
if (date >= GetExpiration()) then
begin
sentiment = senti_block;
end
end
Page 22 of 110
Alerting & Informing
MessageBox()
Definition:
• Opens a pop-up window with a pre-defined message when a particular condition is met using a
live data stream. Without live data there can be no messages.
o Only one message box can be shown over the duration of a bar. A message box is shown
once at the first occurrence.
o To send out a message once at the end of a period use the following instruction:
if IsBarCompleted() then MessageBox("Price > Moving Average");
o To write 2 lines in a message use this instruction:
▪ MessageBox("Line 1 \n Line 2”);
Format:
Example:
• Below we are generating messages every time the price crosses the blue moving average.
Messages may appear several times within the same bar.
Express f_MessageBox
Vars
Series
myMA;
Input
$span(1, 200, 30);
Calculation
If IsFirstBar() then MovingAverage(close,
myMA, $span);
Interpretation
begin
end
Page 23 of 110
PlaySound()
Definition:
• Plays a pre-defined sound when a particular condition is met using a live data stream. Without
live data there can be no audible notifications.
o A sound is triggered once per occurrence and per bar.
o To play a sound once at the end of a period use the following instruction:
if IsBarCompleted() and …… then PlaySound(“gong”);
• The sound files are available at the following folder: NanoTrader\Wav
• If several PlaySound() functions are triggered at the same time only the first PlaySound()
function in the code will be executed.
Format:
Example:
• Here a sound is triggered every time three bullish bars occur consecutively.
Express f_PlaySound
vars
calculation
if (c > c[1]) and (c[1] > c[2]) and (c[2] > c[3])
then begin
Highlightat(0, "slot","green");
Highlightat(1, "slot","green");
Highlightat(2, "slot","green");
MessageBox("3 Bullish Bars - Possible
Trend");
Playsound("corkpop");
end
Interpretation
begin
end
Page 24 of 110
SendEmail()
Definition:
Format:
Example:
• Below we generate a notification email after the completion of a given chart pattern, i.e.
Market Structure low.
express f_SendEmail
vars
series signal(50);
input $EmailActivate(0,1,1);
calculation
interpretation
begin
sentiment = signal;
end
Page 25 of 110
Screenshot()
Definition:
• Creates a screenshot file of the master chart when a particular condition is met using a live data
stream. Without live data there can be no screenshot files.
• The files can be saved in a given location on a PC.
o The path and filename are defined using a syntax similar to:
"C:\NanoFiles\screenshot1.png".
• A screenshot can be created once per occurrence and per bar. To create a screenshot only at
the end of a period use the following instruction: if IsBarCompleted() and …… then
Screenshot(“My path\filename.png”).
• If several Screenshot() functions are triggered at the same time only the first Screenshot()
function in the code will be executed.
Format:
Example:
• Below we are generating a screenshot every time the price crosses the blue moving average.
The screenshots are saved inside the folder “C:\Pictures\Screenshot.png”).
Express f_Screenshot
Vars
Series
myMA;
Input
$span(1, 200, 30);
Calculation
If IsFirstBar() then MovingAverage(close,
myMA, $span);
If IsBarCompleted() then
begin
if CrossesAbove(close, myMA) then
Screenshot(“C:\Pictures\Screenshot.png”);
if CrossesBelow(close, myMA) then
Screenshot(“C:\Pictures\Screenshot.png”);
end
Interpretation
Begin end
Page 26 of 110
ScreenshotEx()
Definition:
• Creates a screenshot file of either the master chart or the equity window when a particular
condition is met.
• The files are saved as .png files in a given location on the PC.
o The path and filename are defined using a syntax similar to:
"C:\NanoFiles\screenshot1.png".
o If the filename does not contain a full path then it is saved in the general screenshot
directory of NanoTrader.
• The `style’ determines the elements of the MasterChart to be drawn and defines the default
dimensions. The settings are as follows:
o 0 = exactly as shown on the screen
o 1 = less decoration, medium sized
o 2 = even less decoration, small sized
o 3 = show equity window, medium sized
o 4 = show equity window, small sized
• The `width’ and `height’ are used to define the dimension of the created image. Set to 0 to use
the default as defined by the style.
• `periodsOrDays’ defines the number of periods to be displayed, counting from the last available
period.
o If set to a value greater than 0 then it defines the total number of periods to be shown.
o If set to 0 then it shows the starting point of the current zoom in the MasterChart
o If set to a negative number then it is interpreted as full days, e.g., -2 means “show today
and yesterday”.
• A screenshot can be created once per occurrence and per bar. To create a screenshot only at
the end of a period use the following instruction: if IsBarCompleted().
• If several ScreenshotEx() functions are triggered at the same time only the first ScreenshotEx()
function in the code will be executed.
Format:
• void ScreenshotEx(string filename, int style, int width, int height, int periodsOrDays)
Example:
• Below we are generating a screenshot every day at the same time at 3:30 PM // 15:30. The
screenshots are saved inside the folder “C:\NanoPictures\Chart.png”) with the same elements
as shown on the screen (=0). The dimensions are 600x300 pixels and the chart is only showing
the candles of the current day (=-1).
Page 27 of 110
Express f_ScreenshotEx
Vars
Input
$EnterAT(000,2359,1530);
Calculation
If (time >=
NumericToTime($EnterAT)) AND
((time[1] <
NumericToTime($EnterAT)) OR
IsNewDay()) then
ScreenshotEx("C:\NanoPictures\Char
t.png",0,600,300,-1);
Interpretation
begin
end
Page 28 of 110
ShowTip()
Definition:
Format:
Example:
• Example 1: The Bollinger Band indicator is calculated and the values of the upper and lower
band are displayed in the tip.
• Example 2: Various information of the current instrument as well as active indicator values are
displayed in the tip of the last candle.
Express f_ShowTip_Example1
Vars
Series
TL, BL, ML, delta;
Input
$span(1, 200, 20),
$StD_factor(1, 200, 20);
Calculation
If IsFirstBar() then
begin
MovingAverage(close, ML, $span);
StdDev(close, delta, $span);
end
TL = ML + (($StD_factor/10) *delta);
BL = ML - (($StD_factor/10) *delta);
Interpretation
begin
end
Page 29 of 110
Express f_ShowTip_Example2
Vars
Input
$MA_50(1, 500, 50),
$MA_200(1, 500, 200);
Series
MA50,
MA200;
Numeric
MinLo,
MaxHi;
Calculation
If IsFirstBar() then
begin
MovingAverage(c, MA50, $MA_50);
MovingAverage(c, MA200, $MA_200);
end
if h > MaxHi then MaxHi = h; else MaxHi = MaxHi;
if l < MinLo then MinLo = l; else MinLo = MinLo;
If IsFinalBar() then
ShowTip(
"-------------------------------------------------------"
+ "\n" + "Current Symbol: " + Symbolname()
+ "\n" + "Daily Open : " + NumericToString(o,"%6.2f")
+ "\n" + "Daily High : " + NumericToString(Maxhi,"%6.2f")
+ "\n" + "Daily Low : " + NumericToString(MinLo,"%6.2f")
+ "\n" + "last Close : " + NumericToString(c,"%6.2f")
+ "\n" + "MA 50 : " + NumericToString(MA50,"%6.2f")
+ "\n" + "MA 200 : " + NumericToString(MA200,"%6.2f")
+ "\n" + "-------------------------------------------------------");
Interpretation
begin
end
Page 30 of 110
Highlight() / HighlightRGB()
Definition:
• Both functions enable the user to highlight the current bar using a specific marker and color.
• The available markers are: “ellipse”, “upTriangle”, “downTriangle”, “slot”, “bottomLine”,
“topLine”, “textAbove” and “textBelow”.
• The following colors are available for the Highlight() function: “red”, “lightRed”, “green”,
“lightGreen”, “blue”, “lightBlue”, “magenta”, “lightMagenta”, “yellow”, “lightYellow”, “cyan”,
“lightCyan”, “grey”, “black”, “white”.
• For the HighlightRGB() function, an almost infinite number of colors can be selected using the
RGB color scheme (RGB = Red-Green-Blue).
• Refer to the section on Plotting functions to learn how to create a RGB color code.
Format:
Example 1:
• Highlights the 50th candle of the chart by coloring the background behind the bar in a lightgreen
color.
Express f_Highlight
vars
calculation
if CurrentBarIndex() = 50 then
Highlight("slot", "lightgreen");
interpretation
begin
end
Page 31 of 110
Example 2:
• Here we create a box using highlight(textbelow,“black“) with a message whose information gets
updated tick by tick. Note some very useful rules for creating content:
o Pieces of texts must be surrounded with quotes: "Instrument: "
o Numbers must be converted in a text format using NumericToString().
o String variable can be typed without quotes: contract
o To go to the next line use the expression: "\n"
o All pieces must be joined with a + sign.
express f_Highlight2
vars
input
$period(1,100,14);
string
contract;
calculation
Page 32 of 110
HighlightAT() / HighlightRGBat()
Definition:
• Both functions enable the user to highlight a given bar using a specific marker and color. The
given bar refers to a bar that is x bars away from the current bar. For example:
o HighlightAT(0,”slot”,”blue”): the given bar is the current bar.
o HighlightAT(10,”slot”,”blue”): the given bar is the 10th bar to the left of the current bar.
o HighlightAT(-5,”slot”,”blue”): the given bar is the 5th bar to the right of the current bar.
• The available markers are: “ellipse”, “upTriangle”, “downTriangle”, “slot”, “bottomLine”,
“topLine”, “textAbove” and “textBelow”.
• The following colors are available for the HighlightAT() function: “red”, “blue”, “green”,
“yellow”, “black”, “grey”, “white”, “magenta”, “lightred”, lightblue”, “lightgreen”, “lightyellow”,
“black”, “lightgrey”, “white” and “lightmagenta”.
• For the HighlightRGBat() function, an almost infinite number of colors can be selected using the
RGB color scheme (RGB = Red-Green-Blue).
• Refer to the section on Plotting functions to learn how to create a RGB color code.
Format:
Example:
Express f_HighlightAT
Calculation
If IsFirstBar() then
Highlightat(-3,"slot","magenta");
If IsFinalBar() then
begin
Highlightat(0,"slot","lightred");
Highlightat(1,"slot","blue");
Highlightat(5,"ellipse","lightgreen");
end
Interpretation
begin
end
Page 33 of 110
Annotate() / AnnotateRGB()
Definition:
• Both functions enable the user to enrich the chart with individual notes which are added to the
current bar with respect to the chosen ‘type’ in the specified ‘color’.
• The available types are: “ellipse”, “upTriangle”, “downTriangle”, “labelLeft”, “labelCenter” and
“labelRight”.
• The vertical position and size of the annotation for the types “ellipse”, “upTriangle” and
“downTriangle” is determined by the parameters `high’ and `low’.
• The text to be displayed with “labelLeft”, “labelCenter” and “labelRight” is appended to the
type separated by a colon.
• A line break can be enforced by using the character sequence \n. Lines are not wrapped
automatically.
• The vertical position of the text is determined by the parameter `high’.
• The following colors are available for the Highlight() function: “red”, “lightRed”, “green”,
“lightGreen”, “blue”, “lightBlue”, “magenta”, “lightMagenta”, “yellow”, “lightYellow”, “cyan”,
“lightCyan”, “grey”, “black”, “white”.
• For the HighlightRGB() function, an almost infinite number of colors can be selected using the
RGB color scheme (RGB = Red-Green-Blue).
• Refer to the section on Plotting functions to learn how to create a RGB color code.
Format:
Example:
Express f_Annotate
Calculation
Interpretation
begin
end
Page 34 of 110
AnnotateAT() / AnnotateRGBAT()
Definition:
• Both functions enable the user to enrich the chart with individual notes which are added to a
given bar with respect to the chosen ‘type’ in the specified ‘color’. The given bar refers to a bar
that is x bars away from the current bar. For example:
o HighlightAT(0,”slot”,”blue”): the given bar is the current bar.
o HighlightAT(10,”slot”,”blue”): the given bar is the 10th bar to the left of the current bar.
o HighlightAT(-5,”slot”,”blue”): the given bar is the 5th bar to the right of the current bar.
• The available types are: “ellipse”, “upTriangle”, “downTriangle”, “labelLeft”, “labelCenter” and
“labelRight”.
• The vertical position and size of the annotation for the types “ellipse”, “upTriangle” and
“downTriangle” is determined by the parameters `high’ and `low’.
• The text to be displayed with “labelLeft”, “labelCenter” and “labelRight” is appended to the
type separated by a colon.
• A line break can be enforced by using the character sequence \n. Lines are not wrapped
automatically.
• The vertical position of the text is determined by the parameter `high’.
• The following colors are available for the Highlight() function: “red”, “lightRed”, “green”,
“lightGreen”, “blue”, “lightBlue”, “magenta”, “lightMagenta”, “yellow”, “lightYellow”, “cyan”,
“lightCyan”, “grey”, “black”, “white”.
• For the HighlightRGB() function, an almost infinite number of colors can be selected using the
RGB color scheme (RGB = Red-Green-Blue).
• Refer to the section on Plotting functions to learn how to create a RGB color code.
Format:
• void AnnotateAT(int offset, string type, string color, float high, float low)
• void AnnotateRGBAT(int offset, string type, int red, int green, in blue, float high, float low)
Example:
• The second last and the third last candle are highlighted with an ‘upTriangle”.
Express f_AnnotateAT
Calculation
If IsFinalBar() then
begin
AnnotateAT(1,"upTriangle","green",l[1],(l[1]-(h-l)/2));
AnnotateAT(2,"upTriangle","lightred",h[2],(h[2]+(h-
l)/2));
end
Interpretation
begin
end
Page 35 of 110
CreateFile()
Definition:
• Creates a text file to be saved in a given location on a PC and allows writing any given text in this
file.
• The path and filename are defined using a syntax similar to: "C:\NanoLogs\nano-actions.txt"
• The text must be placed between " ". If the file already exists, the given text will be added to
the existing text.
• A file can be created once per occurrence and per bar. To create a file only at the end of a
period use the following instruction: if IsBarCompleted() and …… then CreateFile(“My Text”);
• If several CreateFile() functions are triggered at the same time only the first CreateFile()
function in the code will be executed.
Format:
Example:
• In the example below a text file with the message: “New peak at symbol " + SymbolName()” is
created and saved in the folder C:\NanoLogs on their computer if the following condition is met:
(close > high[1]) and (close > high[2])
• For visual purposes the candle is also highlighted in blue.
Express f_CreateFile
Calculation
Interpretation
begin
end
Page 36 of 110
NumericToString()
Definition:
• Applies to the elements of a series a given format and convert them into a string.
o NumericToString applies the “%g” format by default.
o Supports all formats used for the C-function “printf()”. The most important are:
“%f” decimal floating point
”%6.2f” rounds to two decimals
”%g” discards trailing zeroes
”%e” scientific notation
Format:
Example:
• Below we display the format of the close price to be shown using the ShowTip function.
o For example by selecting type 4 we show the price in scientific notation:
Express f_NumericToString
vars
input
$type(0,4,0);
calculation
interpretation
begin
end
Page 37 of 110
PriceToString()
Definition:
• Rounds the price to which it applies to the nearest price in respect to the defined ticksize and
precision of the analyzed symbol and converts it into a string. Takes fractional notations into
account.
Format:
Example:
Example:
Express f_PriceToString
calculation
interpretation
begin
end
Page 38 of 110
TimeToString()
Definition:
Format:
Example:
• Below we create a tip which shows the time when we move the mouse over a candle:
Express f_TimeToString
Calculation
showtip(TimeToString(time, "%H:%M:%S"));
interpretation
begin
end
Page 39 of 110
IsBarCompleted()
Definition:
Format:
• bool IsBarCompleted()
Example 1:
Example 2:
Express f_IsBarCompleted
Calculation
If IsBarCompleted() then
MessageBox("A new period has begun");
Interpretation
begin
end
Page 40 of 110
Loops & Arrays
Definition:
Syntax:
Example 1:
• Below we use For … loop to calculate the average of the last 10 bars, bar by bar. Please note:
o The loop is run at each bar to add up the last 10 close prices. We make i vary between 0
and 9 and we execute sum = sum + close[i].
▪ i = 0 is the current bar, i = 1 is the first bar on the left, i = 2 is the second bar on the
left, .. etc.
Express f_ForLoop_1
Vars
Numeric i;
Series avgsum, sum;
Calculation
Calculateateverytick(false);
for i = 0 to 9
begin
sum = sum + close[i];
end
avgsum = (sum/10);
Interpretation
begin
end
Page 41 of 110
Example 2:
• Below we create a MACD indicator using a loop to calculate the difference between two
exponential moving averages. Please note:
o Here we do all the calculations at the first bar. Exponential moving averages are easily
computed using an express internal function.
o The MACD is computed using a loop. We make i vary between 0 and FinalBarIndex.
▪ We do not use ‘begin … end’ because there is only one expression.
▪ Being at the first bar: i = 0 is the first bar, -1 is the second bar on the right, -2 is the
third bar on the right, ... etc.
▪ Note: We could also have used the following instruction:
For i = 0 downto (- FinalBarIndex())
Express f_ForLoop_2
Vars
Series
ema1, ema2, macd, emacd, FBI;
numeric
i;
Calculation
CalculateAtEveryTick(false);
if IsFirstBar() then
begin
ExpMovingAverage(close, ema1, 12);
ExpMovingAverage(close, ema2, 26);
for i = 0 to FinalBarIndex() macd[-i] = ema1[-i] - ema2[-i];
ExpMovingAverage(MACD, eMACD, 9);
end
Interpretation
begin
end
Page 42 of 110
While … do
Definition:
Syntax:
Example:
• Below we count how many times the price closes consecutively higher (green line) and lower
(red line) and record the results bar by bar.
express f_WhileDo;
vars
series longPeriods, shortPeriods;
numeric counter;
calculation
counter = 1;
longPeriods = 0;
while (c[counter-1] >= c[counter]) and (c[counter] <> void)
begin
longPeriods = longPeriods + 1;
counter = counter +1;
end
counter = 1;
shortPeriods = 0;
while (c[counter-1] <= c[counter]) and (c[counter] <> void)
begin
shortPeriods = shortPeriods + 1;
counter = counter +1;
end
interpretation
begin
end
Page 43 of 110
SetArrayTo() / SetArraySize() / GetArraySize()
Definitions:
• Elements of an array are set by default to zero. To affect 500 to all elements we write:
o SetArrayTo(abc, 500);
Format:
Example:
Page 44 of 110
Express f_Array;
vars
input
$AbcSize(1, 100, 10), $AbcValue(1, 100, 15);
array
abc[0];
series
ShowResults, ShowResults2;
numeric
i;
calculation
if IsFinalBar() then
begin
SetArraySize(abc, $AbcSize);
SetArrayTo(abc, $AbcValue);
for i=0 to GetArraySize(abc)-1
begin
ShowResults[i] = abc[i];
abc[i] = i * power(-1,i);
ShowResults2[i] = abc[i];
end
end
interpretation
begin
end
Page 45 of 110
Indexing & Efficient programming
CurrentBarIndex() / FinalBarIndex()
Definition:
• For a given chart FinalBarIndex() indicates the number of bars displayed on the chart minus one.
For example:
o The index of the first bar on the left of a chart is 0
o The index of the last or final bar on the right of a chart is 99
o If a chart displays 1000 bars, FinalBarIndex() = 999
• CurrentBarIndex() indicates the index number of a bar.
For example:
o When considering the first bar CurrentBarIndex() = 0
o When considering the second bar CurrentBarIndex() = 1
o When considering the 10th bar CurrentBarIndex() = 9
o When considering the nth bar CurrentBarIndex() = n - 1
Format:
• int CurrentBarIndex()
Example:
Express f_CurrentBarIndex
vars
series x,y;
calculation
x = CurrentBarIndex();
y = FinalBarIndex();
interpretation
begin
end
Page 46 of 110
IndexOfHighest() / IndexOfLowest()
Definition:
• Returns the index of the highest / lowest value for the elements series[0], ... series[span – 1].
Format:
Example:
Express f_IndexOfHighest
vars
input $period(1,50,10);
calculation
if IsFinalBar() then
begin
for i = 0 to ($period - 1)
begin
if ((FinalBarIndex() - i) =
IndexOfHighest(h,$period)) then
HighlightAT(i,"slot","lightgreen");
if ((FinalBarIndex() - i) =
IndexOfLowest(l,$period)) then
HighlightAT(i,"slot","lightred");
end
end
interpretation
begin
end
Page 47 of 110
CalculateAtEveryTick()
Definition:
Example 1:
Express f_CalculateAtEveryTick
vars
series x;
calculation
x = c;
interpretation
begin
end
plot(x,blue,2);
Example 2:
Page 48 of 110
Express f_CalculateAtEveryTick
vars
series x;
calculation
CalculateAtEveryTick(false);
x = c;
interpretation
begin
end
plot(x,blue,2);
Page 49 of 110
IsFirstBar / IsFinalBar and associated functions
IsFinalBar() / IsFirstBar()
Definition:
Format:
• bool IsFinalBar()
• bool IsFirstBar()
Example 1:
• Here we need to calculate a constant numeric variable which will be used at every successive
bar. The constant K equals the opening price of the first bar. The result, series x, is the
difference between the close price and the opening price of the first bar.
Express f_IsFirstBar_example1
vars
series x, zero;
numeric k;
calculation
if IsFirstBar() then
begin
k = o;
end
x = c – k;
interpretation
begin
end
Page 50 of 110
Example 2:
Express f_IsFirstBar_example2
vars
calculation
if IsFirstBar() then
begin
ExpMovingAverage(c, ema1, $period1);
ExpMovingAverage(c, ema2, $period2);
end
interpretation
begin
end
Page 51 of 110
MovingAverage()
Definition:
Format:
Example:
Express f_MovingAverage
Vars
Series
MA1, MA2;
Input
$spanMA1(1, 200, 8), $spanMA2(1, 200, 30);
Calculation
Interpretation
begin
end
Page 52 of 110
ExpMovingAverage()
Definition:
• Returns the exponential moving average of a series over a given period of time.
o This function should only be used in combination with IsFirstBar() or IsFinalBar() in order
to save a tremendous amount of computation (see IsFirstBar and IsFinalBar).
Format:
Example:
Express f_ExpMovingAverage
Vars
Series
MA1, MA2;
Input
$spanMA1(1, 200, 8), $spanMA2(1, 200, 30);
Calculation
If IsFirstBar() then
begin
ExpMovingAverage(close, MA1, $spanMA1);
ExpMovingAverage(close, MA2, $spanMA2);
end
Interpretation
begin
end
Page 53 of 110
RSI()
Definition:
Format:
Example:
Express f_RSI
Vars
Series
myRSI, smoothedRSI;
Input
$a(1,100,14), $b(1,100,3);
Calculation
If IsFirstBar() then
begin
RSI(close, myRSI, $a);
MovingAverage(myRSI, smoothedRSI, $b);
end
Interpretation
begin
end
Page 54 of 110
StdDev()
Definition:
Format:
Example:
• Below we draw the Bollinger Bands which are based on a 20 periods moving average plus and
minus two times the standard deviation.
• Note: Since series RSI and smoothedRSI are calculated at the first bar we do not execute the RSI
and MovingAverage functions at other bars (see IsFirstBar and IsFinalBar for more details).
Express f_StdDev
Vars
Series
MA, SD, BBH, BBL;
Calculation
If IsFirstBar() then
begin
MovingAverage(close, MA, 20);
StdDev(close, SD, 20);
end
BBH = MA + 2*SD;
BBL = MA - 2*SD;
Interpretation
begin
end
Page 55 of 110
Unaggregate()
Definition:
• Takes an indicator in a large time unit, e.g. a 5 minute MACD, and projects its values into
another indicator that can be displayed in the master chart in a smaller time unit, e.g. 1 minute.
• This function should only be used in combination with IsFirstBar() or IsFinalBar() in order to save
a tremendous amount of computation (see IsFirstBar or IsFinalBar).
Format:
Example:
express AggregatedSentimentor
vars
series MAbig, colorbig ;
input $Span(1,200,10);
calculation
CalculateAtEveryTick(false);
if IsFirstBar() then MovingAverage(c,MAbig,$Span);
if (colorbig[1] = 0) then colorbig = 1; else colorbig = 0;
interpretation
begin
end
plot(MAbig,blue,2);
plotcandles(o,c,h,l);
4
Right-click on the upper left blue label, select Aggregation, and type 20.
5
To make it clearer the master chart’s background color alternates with each new aggregated bar.
Page 56 of 110
express UnaggregatedSignal
vars
series
colorbig(AggregatedSentimentorExpress.colorbig),color,
MAbig(AggregatedSentimentorExpress.MAbig), MA;
calculation
CalculateAtEveryTick(false);
if IsFirstBar() then
begin
Unaggregate(colorbig,color);
Unaggregate(MAbig,MA);
end
if (color = 0) then HighlightRGB("slot",192,192,192);
interpretation triggerline(c,MA);
plot(MA,blue,2);
Page 57 of 110
Mathematical functions
AbsValue()
Definition:
Format:
Example 1:
• AbsValue(5) = AbsValue(-5) = 5
Example 2:
• Below we display the absolute value of the difference in points between the open and close
prices of every candle.
Express f_AbsValue
Vars
Series
span;
Calculation
span = AbsValue(open-close);
Interpretation
begin
end
Page 58 of 110
Sign()
Definition:
Format:
• Sign(float value).
Example:
• Below we draw a curve Y in red and another one in green which shows the opposite sign of the
Y:
Express f_Sign
Vars
Series
Y, OppositeSignY;
Calculation
Y = Power(-1.01, CurrentBarIndex());
OppositeSignY = -Sign(Y);
Interpretation
begin
end
Page 59 of 110
Floor() / Ceiling()
Definition:
• floor() returns the biggest integer which is less than or equal to a given number.
• ceiling() returns the smallest integer which is greater than or equal to a given number.
Format:
Example 1:
x floor(x) ceiling(x)
2.3 2.0 3.0
5.7 5.0 6.0
0.0 0.0 0.0
-0.5 -1.0 0.0
-1.5 -2.0 -1.0
Example 2:
• Below we draw a green line of ceiling values and a red line of floor values.
Express f_Floor_Ceiling
Vars
Series
line_floor, line_ceiling;
Calculation
line_floor = floor(c);
line_ceiling = ceiling(c);
Interpretation
begin
end
Page 60 of 110
Sum()
Definition:
Format:
Example:
Express f_Sum
Vars
Series
amount;
Input
$span(1, 100, 5);
Calculation
Interpretation
begin
end
Page 61 of 110
Atr()
Definition:
• Measures the price volatility over a given period as a percentage value. It is an average of True
Range over a given period. True Range being defined as follows:
TrueRange = high - low;
If (previous close <= high) then TrueRange = max(TrueRange, high - previous close);
If (previous close >= low) then TrueRange = max(TrueRange, previous close - low);
Atr(14) is TrueRange’s moving average over 14 periods divided by the close price.
Format:
Example:
• The indicator below plots three different versions of the ATR: 1/ ATR in points, 2/ ATR in
percent and 3/ ATR in ticks
Express f_Atr
Vars
input
$Period(1, 50, 14), $Type("points;percent;ticks",1);
series
ATRpoints, ATRpercent, ATRticks, ATRline;
calculation
// ATR in points
if $Type = 0 then ATRline =
Round(Atr($Period)/100*close/TickSize(),0)*TickSize()
;
// ATR in percent
if $Type = 1 then ATRline = Atr($Period);
//ATR in ticks
if $Type = 2 then ATRline =
Round(Atr($Period)/100*close/TickSize(),0);
interpretation
begin
end
plot (ATRline,blue,2);
Page 62 of 110
AtrAbs()
Definition:
• Measures the price volatility over a given period in points6. It is an average of True Range over a
given period. True Range being defined as follows:
TrueRange = high - low;
If (previous close <= high) then TrueRange = max(TrueRange, high - previous close);
If (previous close >= low) then TrueRange = max(TrueRange, previous close - low);
AtrAbs(14) is TrueRange’s moving average over 14 periods.
Format:
Example:
Express f_AtrAbs
vars
calculation
ATRline = AtrAbs($Period);
interpretation
begin
end
plot (ATRline,red,2);
6
AtrAbs() differs from Atr() in that it is expressed as an absolute value (= points) and not as a percentage value.
Page 63 of 110
Sine()
Definition:
Format:
Example 1:
• Sine(0) = 0
• Sine(45) = 0.7071…
• Sine(90) = 1
Example 2:
Express f_Sine
Vars
Series
val;
Calculation
val = sine(CurrentBarIndex());
Interpretation
begin
end
Page 64 of 110
Cosine()
Definition:
Format:
Example 1:
• Cosine(0) = 1
• Cosine(45) = 0.7071…
• Cosine(90) = 0
Example 2:
Express f_Cosine
Vars
Series
val;
Calculation
val = cosine(CurrentBarIndex());
Interpretation
begin
end
Page 65 of 110
Tangent()
Definition:
Format:
Example 1:
• Tangent(0) = 0
• Tangent(45) = 1
Example 2:
Express f_Tangent
Vars
Series
value;
Calculation
Interpretation
begin
end
Page 66 of 110
ArcTangent()
Definition:
Format:
Example:
• Below we display the angle defining the slope of the green moving average line.
o To adjust the measure of the angle with what we see we enter two parameters:
▪ Number of candles per centimeter
▪ Number of points per centimeter
o In the example below the angle goes from 0° (bottoming green line) to around 50°
(steadily rising green line) before returning to 0° (flattening green line).
Express f_ArcTangent
vars
series
ma, angle;
input
$NumberOfpointsPerCM(0.1, 10.0, 2.9, 0.1, 1),
$NumberOfcandlesPerCM(0.1, 10.0, 4.0, 0.1, 1), $period(1, 50, 10);
calculation
if IsFirstBar() then
begin
CalculateAtEveryTick(false);
MovingAverage(c, ma, $period);
end
angle = ArcTangent((ma -
ma[1])/$NumberOfpointsPerCM*$NumberOfcandlesPerCM);
interpretation
begin
end
plot(angle,blue,2);
Page 67 of 110
Exp()
Definition:
Format:
Example 1:
• Exp(0) = 1
• Exp(1) = 2.718281828….
Example 2:
Express f_Exp
Vars
Series
val;
Calculation
val = exp(close);
Interpretation
begin
end
Page 68 of 110
Log()
Definition:
Format:
Example 1:
• Log(0.1) = -2.30…
• Log(1) = 0
• Log(1000) = 6.91…
Example 2:
Express f_Log
Vars
Series
val;
Calculation
val = log(close);
Interpretation
begin
end
Page 69 of 110
Power()
Definition:
Format:
Example 1:
• Power(3, 0) = 1
• Power(3, 1) = 3
• Power(3, 2) = 9
Example 2:
• Below we draw an exponential curve equal to the bar indices raised to power 2:
Express f_Power
Vars
series
Result;
input
$Exponent(1, 50, 2);
Calculation
Interpretation
begin
end
Page 70 of 110
SquareRoot()
Definition:
Format:
Example 1:
Number SquareRoot(Number)
1 1
4 2
9 3
16 4
Example 2:
Express f_SquareRoot
Vars
Series
val;
Calculation
val = SquareRoot(CurrentBarIndex());
Interpretation
begin
end
Page 71 of 110
Highest()
Definition:
• Returns the highest value for the elements series[0], ... , series[span – 1].
Format:
Example:
• Below the green line TenBarHigh returns the highest value of the ten previous highs:
Express f_Highest
Vars
Series TenBarHigh;
Calculation
interpretation
begin
end
Page 72 of 110
Lowest()
Definition:
• Returns the lowest value for the elements series[0], ... , series[span – 1].
Format:
Example:
• Below the red line TenBarLow returns the lowest value of the ten previous lows:
Express f_Lowest
Vars
Series TenBarLow;
Calculation
interpretation
begin
end
Page 73 of 110
IsZero()
Definition:
Format:
Example:
• Below we draw the CurrentBarIndex line and highlight the background in light red if
IsZero(CurrentBarIndex()/1 000 000 000) is true:
o For the first 1001 bars the condition is true and the background is light red.
o From the 1002 bar onwards the condition is false.
Express f_IsZero
Vars
series
x, y;
numeric
a, b;
Calculation
x = a*CurrentBarIndex();
y = CurrentBarIndex();
Interpretation
begin
end
Page 74 of 110
IsNonZero()
Definition:
Format:
Example:
• Below we draw the CurrentBarIndex line and highlight the background in green if
IsNonZero(CurrentBarIndex()/1 000 000 000) is true:
o For the first 1001 bars the condition is false.
o From the 1002 bar onwards the condition is true and the background is green.
Express f_IsNonZero
Vars
series
x, y;
numeric
a, b;
Calculation
x = a*CurrentBarIndex();
y = CurrentBarIndex();
Interpretation
begin
end
Page 75 of 110
Max()
Definition:
Format:
Example 1:
• Max(3, 8) returns 8.
Example 2:
• Below we draw a line made of the maximum of the previous two close prices:
Express f_Max
Vars
series
MaxClose;
Calculation
interpretation
begin
end
Page 76 of 110
Min()
Definition:
Format:
Example 1:
• Min(3, 8) returns 3.
Example 2:
• Below we draw a line made of the minimum of the previous two close prices:
Express f_Min
Vars
series
MinClose;
Calculation
interpretation
begin
end
Page 77 of 110
Round()
Definition:
• Returns the nearest rational number to a given number for a given number of decimals.
o Midpoint (0.5) is rounded up to nearest rational number.
Format:
Example 1:
• Round(1.1550, 0) = 1
• Round(1.1550, 1) = 1.2
• Round(1.1550, 2) = 1.16
• Round(1.1550, 3) = 1.155
Example 2:
• Below we draw a curve made of the rounded values to three decimals of EUR/USD prices:
Express f_Round
Vars
series
myClose;
Calculation
Interpretation
begin
end
Page 78 of 110
RoundMultiple()
Definition:
• Returns a number which is the nearest multiple of a given base to a given number. For example:
o If the base is 2.5 and the number is 3743.5 the result is 3742.5:
▪ 3743.5 / 2.5 = 1497.4 which is rounded to 1497.0
▪ 1497 x 2.5 = 3742.5
o If the base is 2.5 and the number is 3739.5 the result is 3740.0:
▪ 3739.5 / 2.5 = 1495.8 which is rounded to 1496.0
▪ 1496 x 2.5 = 3740.0
Format:
Example:
• Below we draw in green the line of the RoundMultiple applied to the close and based on a
multiple of 2.5:
Express f_RoundMultiple
Vars
input
$Base(0.1, 5.0, 2.5, 0.1, 1);
Series
val;
Calculation
val = RoundMultiple (close, $Base);
Interpretation
begin
end
Page 79 of 110
NormalCDF()
Definition:
Format:
Example:
• Below we draw the curve representing the normal CDF function (use parameters a and b to
adjust it):
Express f_NormalCDF
vars
series
CBI, x;
input
$a(1, 500, 100), $b(1, 500, 10);
calculation
CBI = CurrentBarIndex();
x = NormalCDF((CBI - $b) / $a);
interpretation
begin
end
Page 80 of 110
NormalPDF()
Definition:
Format:
Example:
• Below we draw the curve representing the normal PDF function (use parameters a and b to
adjust it):
Express f_NormalPDF
vars
series
CBI, x;
input
$a(1,500,10), $b(1,500,150);
calculation
CBI = CurrentBarIndex();
x = NormalPDF((CBI - $b)/$a);
interpretation
begin
end
Page 81 of 110
Charting functions
Plotline()
Definition:
Format:
Example:
Express f_plotline
Vars
Series
myRSI;
Numeric
upper(70), lower(30);
Calculation
interpretation
begin
end
Page 82 of 110
Plot()
Definition:
Format:
Example:
Express f_plotRGB
Vars
Series
myMA, myMA2;
Calculation
If IsFirstBar() then
begin
MovingAverage(close, myMA, 30);
MovingAverage(close, myMA2, 10);
end
Interpretation
begin
end
plot(myMA, 230, 160, 79, 5);
plot(myMA2, "blue", 5);
7
Predefined colors are black, white, red, green, blue, magenta, yellow, grey, lightred, lightgreen, lightblue.
Page 83 of 110
Plotband()
Definition:
• Draws a band made of two curves and paints in one color the space in between.
• For Plotband() an almost infinite number of colors can be selected using the RGB color scheme
(RGB = Red-Green-Blue).
• Refer to the section on Plotting functions to learn how to create a RGB color code.
Format:
• plotband(<upper series name>, <color name>, <pen width>, <lower series name>, <color
name>, <pen width>,<fill color>);
• plotband(<upper series name>, int red, int green, int blue, <pen width>, <lower series name>,
int red2, int green2, int blue2, <pen width>, int red3, int green3, int blue3);
Example:
• Below we draw a band based on the highest highs and lowest lows of the last 10 bars:
o The highest highs curve is in green and the lowest lows curve is in red.
o The area between the two curves is in lightgreen.
o Colors must be put in quotes: “blue”.
Express f_plotband
Vars
series
upper, lower, upper1, lower1;
input
$span (0, 200, 10);
Calculation
upper1 = Highest(close, $span);
lower1 = Lowest(close, $span);
upper = upper1[1];
lower = lower1[1];
Page 84 of 110
Plotcrossinglines()
Definition:
• Draws a band made of two curves and paints in two colors the space in between.
• For Plotcrossinglines() an almost infinite number of colors can be selected using the RGB color
scheme (RGB = Red-Green-Blue).
• Refer to the section on Plotting functions to learn how to create a RGB color code.
Format:
• plotcrossinglines (<series1 name>, <color name>, <pen width>, <series2 name>, <color name>,
<pen width>, <fill color series1 above series2>, <fill color series1 below series2>);
• plotcrossinglines (<series1 name>, int red, int green, int blue, <pen width>, <series2 name>, int
red2, int green2, int blue2, <pen width>, int red3, int green3, int blue3, int red4, int green4, int
blue4);
Example:
• Below we draw a band based on the highest highs and lowest lows of the last 10 bars:
o The highest highs curve is in green and the lowest lows curve is in red.
o The area between the two curves is in lightgreen when the fast MA is above the slow MA
and in lightred otherwise.
o Colors must be put in quotes: “blue”.
Express f_CrossingMovingAverages
Vars
Series
FastMA, SlowMA;
Input
$spanFMA(1, 200, 9), $spanSMA(1, 200, 30);
Calculation
If IsFirstBar() then
begin
MovingAverage(close, SlowMA, $spanSMA);
MovingAverage(close, FastMA, $spanFMA);
end
Interpretation
begin
end
Page 85 of 110
Plotbars()
Definition:
Format:
Example:
• Below we draw a bar chart with custom colors for the bars:
Express f_Plotbars
Calculation
Interpretation
begin
end
Page 86 of 110
Plotcandles()
Definition:
Format:
Example:
• Below we draw two candle charts based on the above bar chart with both the predefined and
custom RGB colors.
Express f_PlotcandleChart
vars
calculation
interpretation
begin
end
Express f_PlotcandleChart
vars
calculation
interpretation
begin
end
Page 87 of 110
GetPriceFormat()
Definition:
Format:
• string GetPriceFormat()
Example:
• Below we are applying to our indicator’s y-axis the same format as the MasterChart’s.
Express f_GetPriceFormat_EFX
Vars
series
daxopen(studyDaxsep.open),
daxclose(studyDaxsep.close),
daxhigh(studyDaxsep.high),
daxlow(studyDaxsep.low);
Calculation
SetYscaleFormat (GetPriceFormat());
Interpretation
begin
end
Page 88 of 110
SetYscaleFormat()
Definition:
• Defines the format of the y-axis in the sub window where indicators are plotted when they are
not in the MasterChart.
o Supports all formats used for the C-function “printf()”. The most important are:
“%f” decimal floating point
”%6.2f” rounds to two decimals
”%g” discards trailing zeroes
”%e” scientific notation
Format:
Example:
• Below we set the format of the y-axis in the sub window as numbers with four decimals.
express f_SetYscaleFormat
vars
series
a;
numeric ;
input ;
calculation
a = (c - c[10])/c[10]*100;
SetYscaleFormat("%9.4f");
interpretation
begin
end
plot(a, blue,2);
Page 89 of 110
Importing series
Definition:
• Import a series from one of the standard indicator of the platform (see for an
extract of the list of standard indicators on the right).
Syntax:
Example:
Express f_ImportBollingerBands
Vars
series
Calculation
interpretation
begin
end
Page 90 of 110
Importing a series from another express indicator
Definition:
Syntax:
Example:
• The first indicator below creates a moving average 6 of RSI(14) called MAR (2nd chart). The
second indicator imports MAR and displays it back in color:
Vars vars
Series series
R, MAR; MAR(fMARSIExpress.MAR),
MARup, MARdw;
Calculation
calculation
If IsFirstBar() then
begin if MAR >= MAR[1] then
RSI(c, R, 14); begin
MovingAverage(R, MAR, 6); MARup = MAR;
end MARup[1] = MAR[1];
end
Interpretation else MARup = void;
begin
end if MAR < MAR[1] then
begin
plot(MAR, blue, 2); MARdw = MAR;
MARdw[1] = MAR[1];
end
else MARdw = void;
interpretation
begin
end
Page 91 of 110
Importing a price series from a symbol
Definition:
• Imports any of symbol 2’s open, close, high, low and volume series into a symbol 1’s study.
Syntax:
Example:
• Below symbol 1 is the Dax future. The imported symbol 2 is the Mini Nasdaq future. The top
chart refers to symbol 1. The middle chart refers to symbol 2. The bottom chart is a bar chart
constructed with the imported price series from symbol 2.
o Because we are importing only one symbol we can work with reduced expression like
studyMININSDQ.close instead of studyMININSDQMAR.close.
express f_ImportAnotherSymbol
vars
series
oo(studyMININSDQMAR.open),
cc(studyMININSDQ.close),
ll(studyMINI.low),
hh(study.high);
numeric ;
input ;
calculation
interpretation
begin
end
Page 92 of 110
Creating customized stops and targets
SetIntraPeriodUpdate()
Definition:
Format:
• void SetIntraPeriodUpdate()
Example:
• Below we create a High/Low stop which is updated tick by tick so it is positioned at the lowest
lows of the last 5 bars or at the highest highs of the latest 5 bars.
Calculation
SetIntraPeriodUpdate();
Page 93 of 110
EntryPrice()
Definition:
• Returns two different values depending on whether TradeGuard8 was activated and when:
o TradeGuard deactivated: EntryPrice = Executed price9.
o TradeGuard activated before opening of position: EntryPrice = Executed price3.
o TradeGuard activated after opening of position: EntryPrice = TradeGuard activation
price3.
Format:
• float EntryPrice()
Example:
• Below we create a fixed stop at 6 ticks (3 points) from the entry price. As the TradeGuard was
activated when the position was opened entry price = executed price:
o Executed price of 7732.5 as can be under Average Price.
o On the chart the stop is 3 points (6 ticks) above 7732.5 as expected.
vars
numeric
StopLong, StopShort;
calculation
if BarsSinceEntry() = 0 then
begin
StopLong = EntryPrice() - 6*TickSize();
StopShort = EntryPrice() + 6*TickSize();
end
If MarketPosition() = 1 then SetStopPrice(StopLong);
else
if MarketPosition() = -1 then SetStopPrice(StopShort);
8
With the activation of the Tradeguard stops are being placed automatically by the platform.
9
We are referring to two prices. The first is the actual price at which we opened the position. It is called
Executed price. The second is the price when we activated the TradeGuard. It is called TradeGuard activation
price. These prices are different.
Page 94 of 110
EntryPriceOriginal()
Definition:
Format:
• float EntryPriceOriginal()
Example:
• Below we create a fixed stop at 10 ticks (5 points) from the entry price original:
o We opened the position at the executed price of 7729.0 as can be seen under Average
Price and on the chart with the ‘-1 mark’.
o We activated the TradeGuard afterwards and the platform positioned our stop 10 ticks (5
points) above as we wanted.
vars
numeric
StopLong, StopShort;
calculation
if BarsSinceEntry() = 0 then
begin
StopLong = EntryPriceOriginal() - 10*TickSize();
StopShort = EntryPriceOriginal() + 10*TickSize();
end
10
We are referring to two prices. The first is the actual price at which we opened the position. It is called
Executed price. The second is the price when we activated the TradeGuard. It is called TradeGuard activation
price. These prices are different.
Page 95 of 110
BarsSinceEntry()
Definition:
Format:
• int BarsSinceEntry()
Example:
• Below we create a linear stop which starts 20 ticks away from our entry price before moving by
one tick at the close of each bar. BarsSinceEntry() is used to define the bar of the entry and then
to adapt the stop bar by bar.
vars
numeric
StpLong, StpShort;
calculation
if BarsSinceEntry() = 0 then
begin
StpLong = EntryPriceOriginal() - 20*TickSize();
StpShort = EntryPriceOriginal() + 20*TickSize();
end
else
begin
StpLong = max(StpLong, c - (20 +
BarsSinceEntry())*TickSize());
StpShort = min(StpShort, c + (20 -
BarsSinceEntry())*TickSize());
end
Page 96 of 110
IsIntradayEntry()
Definition:
• Returns true if the position has been opened in the current and not yet closed period.
Format:
• bool IsIntradayEntry()
Example:
• Below we create a linear stop which starts 10 ticks away from the original entry price before
evolving one tick by one tick at the close of each bar. IsIntradayEntry is used to define the bar of
the entry (in the same way as BarsSinceEntry() = 0 does it).
vars
numeric
last, StopL, StopS;
calculation
if MarketPosition() = 1 then
begin
if IsIntradayEntry() then
last = EntryPriceOriginal() - 10*TickSize();
else last = max(last, last + TickSize());
end
else if MarketPosition() = -1 then
begin
if IsIntradayEntry() then
last = EntryPriceOriginal() + 10*TickSize();
else last = min(last, last - TickSize());
end
SetStopPrice(last);
Page 97 of 110
MarketPosition()
Definition:
Format:
• int MarketPosition()
Example:
• Below we create a fixed stop placed at 10 ticks from the original entry price. MarketPosition
enables us to place a stop for each position long or short:
vars
numeric
StopLong, StopShort;
calculation
if BarsSinceEntry() = 0 then
begin
StopLong = c - 10*TickSize();
StopShort = c + 10*TickSize();
end
Page 98 of 110
MinPriceEntryBar() / MaxPriceEntryBar()
Definition:
• MinPriceEntryBar()
If a position is opened when TradeGuard is activated, MinPriceEntryBar returns the lowest price
traded at the first bar (the bar of the entry) after the position is opened.
If TradeGuard is activated when a position is already open, MinPriceEntryBar returns the lowest
price traded at the first bar after the activation of TradeGuard.
• MaxPriceEntryBar()
If a position is opened when TradeGuard is activated, MaxPriceEntryBar returns the highest
price traded at the first bar (the bar of the entry) after the position is opened.
If TradeGuard is activated when a position is already open, MaxPriceEntryBar returns the
highest price traded at the first bar after the activation of TradeGuard.
Format:
Example:
Vars
numeric
StopH, StopL;
Calculation
if BarsSinceEntry() = 0 then
begin
StopH = MaxPriceEntryBar() + 20*TickSize();
StopL = MinPriceEntryBar() - 20*TickSize();
end
else
begin
StopH = min(StopH, Highest(h, 10));
StopL = max(StopL, Lowest(l, 10));
end
Page 99 of 110
SetLongTrigger() / SetShortTrigger()
Definition:
Format:
Example 1:
• Below we generate automated signals based on the crossing of two moving averages. We are
trying to enter at more favorable prices with a conditional limit12 order placed at the mid price
of the signal bar. Note below the set-up conditions and the description of what happens in blue:
Vars
numeric
bl, bs;
Calculation
bl = (h + l)/2;
bs = (h + l)/2;
SetLongTrigger(bl); Set-up of Evaluator Settings:
SetShortTrigger(bs);
11
Only apply to automated trades (AutoOrder must be activated) with AutoOrder Entry Orders set on “Limit =
Limit” and “Stop = Stop” (To set up in Order Defaults) and Entry signals set on “confirmation price next bar” or
“limit price next bar” (To set up in Evaluator Settings).
12
If Evaluator Settings is set on “limit price next bar” and there are no functions like SetLongTrigger or
SetShortTrigger in a program, the limit price will be set to the close of the period generating the signal. In case
many indicators call this routine the strictest price is taken.
• Below we generate automated signals based on the crossing of two moving averages. We are
trying to enter at more favorable prices with a conditional stop13 order placed 5 ticks away
from the close price of the signal bar. Note below the set-up conditions and the description of
what happens in blue:
o When a signal is created the platform places a stop order at the start of the next bar at
the price level given by SetLongTrigger or SetShortTrigger.
o If the stop is hit before the next bar closes a position is opened, otherwise the stop order
is cancelled.
Vars
numeric
bl, bs;
Calculation
bl = c + 5* TickSize();
bs = c - 5*TickSize();
SetLongTrigger(bl); Set-up of Evaluator Settings:
SetShortTrigger(bs);
13
If Evaluator Settings is set on “confirmation price next bar” and there are no functions like SetLongTrigger or
SetShortTrigger in a program, the stop price will be set to the high/low of the period generating the signal. In
case many indicators call this routine the strictest price is taken
Definition:
Format:
Example:
• Below we place a stop 2 ticks away from the lowest lows or the highest highs of the last 10
candles:
o As we entered short two stops were positioned. The click stop at 4047 and the stop we
programmed below which is 2 ticks above the line of the highest highs.
vars
series
ll, hh;
Calculation
ll = Lowest(l, 10);
hh = Highest(h, 10);
If MarketPosition() = 1 then
SetStopPrice (ll - 2*TickSize());
else
if MarketPosition() = -1 then
SetStopPrice (hh + 2*TickSize());
Definition:
Format:
Example:
• Below we create a dynamic target which is depends on the range between the highest highs
and lowest lows of the latest 5 bars.
o Just after the entry the range was increasing so the target price was moved down at
3720.
o Later the range contracted so our target remained at the same level.
o Then as the range started again to expand while the market moved down our target
moved down as well.
vars
numeric
TargetL, TargetS, Range;
input
$n(1, 50, 5), $k(0.1, 2.0, 1.0, 0.1, 1);
calculation
CrossesAbove() / CrossesBelow()
Definition:
Format:
Example:
• Below the indicator is a Bollinger Bands indicator (which has been imported).
• The CrossesAbove and CrosseBelow functions help define the interpretation:
o A long signal is triggered when the close crosses above the upperband
o A short signal is triggered when the close crosses below the lowerband
Express f_CrossesAboveThreshold
Vars
Series
upperband(BollingerBands.upperband),
lowerband(BollingerBands.lowerband);
Calculation
Interpretation
begin
if CrossesAbove(close, upperband) then sentiment
= 100;
if CrossesBelow(close, lowerband) then sentiment
= 0;
end
Definition:
Format:
Example:
Express f_CrossesAboveBelowThreshold
Vars
series;
input $span (0, 200, 10);
Calculation
interpretation
begin
if CrossesAboveThreshold(close, 6930) then sentiment =
100;
if CrossesBelowThreshold(close, 6930) then sentiment = 0;
end
Definition:
• Interpretation scheme for indicators based on the crossing by a curve of another curve.
o For example the close price crossing a moving average.
Format:
Example:
Express f_Triggerline
Vars
Series
FastMA, SlowMA;
Input
$spanFMA(1, 200, 8), $spanSMA(1, 200, 30);
Calculation
If IsFirstBar() then
begin
MovingAverage(close, SlowMA, $spanSMA);
MovingAverage(close, FastMA, $spanFMA);
end
Definition:
Format:
Example:
Express f_Swing
Vars
Series
myRSI, smoothedRSI;
Input
$spanLEFT(1,100,2), $spanRIGHT(1,100,2),
$RSIspan(1, 100, 14), $MAspan(1, 200, 10);
Calculation
If IsFirstBar() then
begin
RSI(close, myRSI, $RSIspan);
MovingAverage(myRSI, smoothedRSI, $MAspan);
end
Definition:
• Interpretation scheme for indicators based on the crossing by a curve of two other curves
forming a band.
o For example the close price crossing these types of bands: Bollinger Bands, Donchian-
Channel, Price-Channel, Commodity-Channel, ….
Format:
Example:
• Below the indicator is a channel based on the highest highs and lowest lows over 10 bars.
• The interpretation is defined using the Bands interpretation.
• By right clicking on the indicator and selecting Edit Interpretation one can display a window
where the interpretation parameters can be modified.
o Here we buy when the close crosses the upper curve (= 100) and we sell when the close
crosses below the lower curve (= 0).
Express f_Bands
Vars
series
upper, lower, upper1, lower1;
input
$span (0, 200, 10);
Calculation
upper = upper1[1];
lower = lower1[1];
Definition:
• Interpretation scheme for indicators based on the crossing by a curve of two horizontal lines.
o For example a RSI, a stochastic or other oscillators crossing two upper and lower lines.
Format:
Example:
Express f_TwoThresholds
Vars
Series
myRSI, smoothedRSI;
Input
$RSIspan(1, 100, 14), $MAspan(1, 200, 10),
$upperzone(51, 99, 80), $lowerzone(1, 49, 20);
Calculation
If IsFirstBar() then
begin
RSI(close, myRSI, $RSIspan);
MovingAverage(myRSI, smoothedRSI, $MAspan);
end
Interpretation TwoThresholds(smoothedRSI,
$upperzone, $lowerzone);
A powerful, fast and secure way to improve the programming experience in NanoTrader is to resort
to external text editors like Notepad++, UltraEdit etc. Some of them are completely free and provide
very helpful features such as:
- Autosave
- Finding and replacing strings of code
- Move blocks of code by one TAB to the right
- Vertical alignments
- Working on several scripts simultaneously
In order to use an external text editor simply copy&paste the code from the external text editor into
NanoTrader’s Express editor and vice versa.
Example:
Below shows a piece of NanoTrader Express code which was copied into the free Notepad++ text
editor.