Functions and Technical Indicators

Functions and Technical Indicators

Introduction

In general, our strategy script language is equivalent to Perl Programming language. Perl is very robust and fully object oriented computer language. You may use Perl syntax except few specific commands, such as 'eval', 'system' etc.) which we remove due security reasons. We also support Perl Regular expressions (regex). Perl regular expressions are very powerful tools for matching, searching, and replacing text. Perl comes with over 100,000 ready to use modules and functions. We do support many of them and we are adding CPAN modules as needed. For example date manipulation module: Date::Manip, etc. You are not required to mention “use” statement, its built in our system (for all currently supported CPAN modules). If you try to use a CPAN module that is not supported by the system (you will get compilation error when saving the Strategy) and you have a need for such missing CPAN module go to Contact us and ask for, we will do our best to have it ready to everyone quickly.

Also, we do support the sub (Perl procedures and functions) so you may build your own functions, indicators and save them in your strategy code or even better, in your private library, so it is available to all your strategies.

We also recommend to check our public library, it has many useful strategies that may help writing interesting tasks such as complex pattern search, date manipulations, universe creation and filtering strategies, etc.

TOC:

·         Introduction

·         Technical Indicator functions

·         Candle indicators

·         Stock Values

·         Illegal characters and words

·         Signaling functions

·         Special and Debug functions

·         Date and date index

·         Date manipulations

·         General functions

·         Flow control

·         Regex – regular expressions

·         Strategy Seeker’s Public Strategy Library (you must first login to Strategy Seeker)

Technical Indicator functions                  GTop

Indicator

Function

Parameters

Usage example

Usage description

Average Directional Movement Index

ADX()

1. Number of days to calculate

2. Back bars/days

ADX( 10 )

ADX( 5 , 2)

ADX of last 10 Bars/Days

ADX of 5 days from 2 Bars/Days ago

Average True Range

ATR()

1. Number of days to calculate

2. Back bars/days

ATR( 14 )

ATR( 5 , 2)

ATR of last 14 Bars/Days

ATR of 5 days from 2 Bars/Days ago

Balance Of Power

BOP()

1. Number of days to calculate

2. Back bars/days

BOP( 14 )

BOP( 5 , 2)

BOP of last 14 Bars/Days

BOP of 5 days from 2 Bars/Days ago

Highest value over a specified period

MAX()

1. Number of days to calculate

2. Back bars/days

MAX(2)

MAX(1,3)

Highest value over last 2 Bars/Days

Highest value over 3 days starting yesterday

Lowest value over a specified period

MIN()

1. Number of days to calculate

2. Back bars/days

MIN(10)

MIN(10,3)

Lowest value over last 10 Bars/Days

Lowest value over 10 days starting 3 days ago and backward

Rate of change

ROC()

1. Number of days to calculate

2. Back bars/days

ROC(30)

ROC(30,1)

ROC of last 30 Bars/days

ROC of last 30 Bars/Days starting yesterday or one bar ago

Relative Strength Index

RSI()

1. Number of days to calculate

2. Back bars/days

RSI(14)

RSI(14,2)

RSI of last 14 Bars/days

RSI of last 14 Bars/Days two days or bars ago

Simple Moving Average

SMA()

1. Number of days to calculate

2. Back bars/days

SMA(200)

SMA(5,6)

SMA of last 200 Bars/Days

SMA of last 5 Bars/Days starting 6 Bars/Days ago

Exponential Moving Average

EMA()

1. Number of days to calculate

2. Back bars/days

EMA(14)

EMA(10,20)

EMA of last 14 bars/days ago

EMA 0f last 10 days starting 20 bars/days ago

On Balance Volume

OBV()

1. Number of days to calculate

2. Back bars/days

OBV(5)

OBV(5,4)

OBV of last 5 bars/days

OBV of last 5 days starting 4 bars/days ago

Moving Average Convergence-Divergence

MACD()

1. MACD EMA1

2. MACD EMA2

3. Single line

4. Back bars/days

Return values:

MACD value,

MACD Signal,

Histogram value

MACD( 12 , 26 , 9 )

($macdval, $signal,$hist ) = MACD( 12 , 26 , 9 ) calling MACD EMA=12, EMA=26 and a Single line=9

The function returns two values: MACD line and histogram

Note the way to obtain the values by having the two return values together as described in ($macdval, $hist )

bollinger bands

BBANDS()

1. Time range  (default=20)

2. Deviation Up  (default=2)

3. Deviation Dn  (default=2)

4. MA type  (default=0)

5. Back bars/days

MA types:

SMA = 0

EMA = 1

WMA = 2

DEMA = 3

TEMA = 4

TRIMA = 5

KAMA = 6

MAMA = 7

T3 = 8

Return values:

High band

Mid band

Low band

 

($upper,$mid,$low) = BBANDS( 20 , 2 , 2, 0 );

 

 

If( $upper <= $mid )         {

….

}

 

 

BBANDS(20,2,2,3,4 );

Calculate Bollinger bands for 20,2,2 using SMA average and store the results in $upper (high band value), $mid (mid band value) and $low (low band)

 

 

 

 

 

 

 

Calculate Bollinger bands for 20,2,2 using TEMA average valid for 3 days/bars ago.

Standard Deviation

STDDEV()

1. Number of days to calculate

2. Back bars/days

STDDEV(14)

STDDEV(14,2)

STDDEV of last 14 Bars/days

STDDEV of last 14 Bars/Days two days or bars ago

Parabolic SAR

SAR()

1. Step

2. Maximum Step

3. Back bars/days

SAR( 0.02 , 0.2)

SAR(0.03,0.3,2)

$sarval =SAR( 0.02 , 0.2 ) calling SAR with step 0.02 and max step 0.2

$sarval =SAR( 0.03 , 0.3 ,1) calling SAR with step 0.02 and max step 0.3 calculated to yesterday or one bar/day ago.

The function returns one value, the Parabolic SAR value.

Stochastic

STOCH()

1. Fast Range

2. Slow Range

3. Signal Range

4. Back bars/days

Return values: SlowK and SlowD

STOCH( 14 ,3 ,3 )

STOCH( 14, 3, 3, 6)

($SlowK,$SlowD = STOCH( 14 , 3 , 3 ) calling STOCH with Fast range of 14, slow 3 and signal 3.

($SlowK,$SlowD = STOCH( 14 , 3 , 3, 6 ) calling STOCH with Fast range of 14, slow 3 and signal 3 calculated to 6 bars/days ago.

The function returns two values:SlowK and SlowD

Stochastic Fast

STOCHF()

1. Fast Range

2. Slow Range

3. Signal Range

4. Back bars/days

Return values: FastK and FastD

STOCHF( 14 ,3 ,3 )

STOCHF( 14, 3, 3, 6)

($FastK,$FastD = STOCH( 14 , 3 , 3 ) calling STOCH with Fast range of 14, slow 3 and signal 3.

($FastK,$FastD = STOCH( 14 , 3 , 3, 6 ) calling STOCH with Fast range of 14, slow 3 and signal 3 calculated to 6 bars/days ago.

The function returns two values:FastK and FastD

Stochastic Relative Strength Index

STOCHRSI()

1. Period Range

2. FastK

3. FastD

4. Back bars/days

Return values: FastK and FastD

STOCKRSI( 14 )

STOCKRSI( 14 , 14, 3 )

STOCKRSI( 14,14,3,7)

($FastK,$FastD = STOCH( 14 ) calling STOCHRSI with time period of 14 calculating for today or current bar.

($FastK,$FastD = STOCH( 14 14, 3, 7 ) calling STOCHRSI with time period of 14, FastK = 14, FastD=3 and calculated for 7 days or bars ago.

Money Flow Index

MFI()

1. Number of days to calculate

2. Back bars/days

MFI(14)

MFI(10,20)

MFI of last 14 bars/days ago

MFI 0f last 10 days starting 20 bars/days ago

Candle Indicators                                            GTop

Indicator

Function

Parameters

Usage example

Usage description

Three Advancing White Soldiers

JC_3WhiteSoldiers()

1. Back bars/days

Returns: True or false

JC_3WhiteSoldiers()

if (JC_3WhiteSoldiers( 2 ) ) {

     Buy();

      }

True if three advancing white soldiers condition met during last bar/day

Check if if three advancing white soldiers condition 2 bars/days ago met and if yes, issue Buy();

Doji

JC_Doji()

1. Back bars/days

Returns: True or false

JC_Doji()

JC_Doji(3)

True if Doji condition met during last bar/day.

True if Doji condition met 3 bars/days ago.

Doji Dragon Fly

JC_DojiDragonFly()

1. Back bars/days

Returns: True or false

JC_DojiDragonFly()

JC_DojiDragonFly(7)

True if Doji Dragon Fly condition met during last bar/day.

True if Doji Dragon Fly condition met 7 bars/days ago.

Doji Dragon Stone

JC_DojiGreaveStone()

1. Back bars/days

Returns: True or false

JC_DojiGreaveStone(11)

JC_DojiGreaveStone()

True if Doji Dragon Stone condition met 11 bars/days ago.

True if Doji Dragon Stone condition met during last bar/day.

 Doji Star

JC_DojiStar()

1. Back bars/days

Returns: True or false

$flag = JC_DojiStar(3)

$flag = 1 unless JC_DojiStar();

$flag gets true if Doji Star event met during last bar/day

$flag gets value 1 unless Doji Star condition met 2 bars/days ago.

Evening Doji Star

JC_EveningStar()

1. Back bars/days

Returns: True or false

JC_EveningStar()

JC_EveningStar(2)

True if Evening Doji Star condition met during last bar/day.

True if Evening Doji Star condition met 2 bars/days ago.

Hammer

JC_Hammer()

1. Back bars/days

Returns: True or false

JC_Hammer()

JC_Hammer(2)

True if Hummer condition met during last bar/day.

True if hummer condition met 2 bars/days ago.

Inverted Hammer

JC_InvertedHammer()

1. Back bars/days

Returns: True or false

JC_InvertedHammer(6)

If( ! JC_InvertedHammer() ) {

    Sellshort();

    }

True if Inverted Hummer condition met 6 bars/days ago.

If there was no Inverted Hummer last during  bar/day issue Sellshort();

Marubozu

JC_Marubozu()

1. Back bars/days

Returns: True or false

JC_Marubozu()

JC_Marubozu(3)

True if Marubozu condition met during last bar/day.

True if Marubozu condition met 3 bars/days ago.

Stock Values                 GTop

Name

Function

Parameters

Usage example

Usage description

Close

Close()

1. Optional: reference symbol

2. Back bars/days

$LastClose = Close()

If( Close(2) < 10 ))

$a = Close( $symbolRef ,2)

Obtain symbol last Close value

Check that Symbol Close value of 2 days/bars ago is lower than 10

Close value of 2 days/bars ago for $symbolRef. Note, you need to load $symbolRef using referenceSymbol function

Note: Close must start with capital C

Open

Open()

1. Optional: reference symbol

2. Back bars/days

$B = Open()

If( Open() < Open(1))

$a = Open($symbolRef)

Obtain symbol last Open value

Check that Symbol last Open value is smaller than Open 1 day or bar ago

$a gets the value of last Open $symbolRef.

Note, you need to load $symbolRef using referenceSymbol function

High

High()

1. Optional: reference symbol

2. Back bars/days

$myhigh = High()

If( High(3)>20.5)

$a = High($symbolRef,5)

Obtain symbol last High value

Check that Symbol High value of 3 bars/days ago is greater than 20.

$a gets the High value of $symbolRef of 5 bars/days ago. Note, you need to load $symbolRef using referenceSymbol function

Low

Low()

1. Optional: reference symbol

2. Back bars/days

$myhigh = Low()

If( Low(3)>20.5)

$a = Low($symbolRef,5)

Obtain symbol last Low value

Check that Symbol Low value of 3 bars/days ago is greater than 20.

$a gets the Low value of $symbolRef of 5 bars/days ago. Note, you need to load $symbolRef using referenceSymbol function

Volume

Volume()

1. Optional: reference symbol

2. Back bars/days

Volume()

If( Volume(3)>200000)

$a = Volume($symbolRef,5)

Obtain symbol last Volume value

Check that Symbol Volume value of 3 bars/days ago is greater than 200,000.

$a gets the Volume value of $symbolRef of 5 bars/days ago. Note, you need to load $symbolRef using referenceSymbol function

Date

Date()

1. Optional: reference symbol

2. Back bars/days

$lastday=Date()

If( Date(2) eq “25-Jul-12”)

Obtain the last Date, example for return: 25-Jul-12

Check that Date 2 days/bars ago was “25-Jul-12”

Buydate

(for Long trades)

Buydate()

None

If( Buydate() eq “25-Aug-11” )

$myd = Buydate()

Check if the Buy date (long position) is equal to 25-Aug-11.

Obtain the date of last Buy and store it in $myd variable

 

Note: the function will return a value only if MP() == 1 (we have a long position)

Buyprice

(for Long trades)

BuyPrice()

None

If( Buyprice > Close() * 1.05 )

 

Check if we gain 5% over the Buy price

 

Note: the function will return a value only if MP() == 1 (we have a long position)

Selldate

(for Short trades)

Selldate()

None

Selldate()

Returns the date of last Sellshort, e.g. “14-Jan-10”

Sellprice

(for Short trades)

Sellprice()

None

If ( Sellprice() > 12.12 )

Check if the Sellprice of a short trade is greater than 12.12

Illegal characters and words          GTop

Name

Forbidden Word

Parameters

Usage example

Usage description

Perl Module load

use

1. Module name

Use Data::Debug

Use can never be used in a strategy as we do not allow to load unsupported CPAN modules. The supported modules are loaded by the system and there is no need to use use.

If you need an unsupported module, please contact us and we will do our best to pre load it to the system (assuming there may be no security implications).

System call

system

` `

exec

1. system function or Perl programs

system(“who”)

Exec(“ls”)

`whoami `

System calls from any kind are not allowed

Eval

eval

1. code

 

Eval is not allowed from security reasons

apostrophe

¢

1. definition of string

‘This is a string’

Apostrophe cannot be used for defining a string.

You must use double quote instead:

Use:  “This is a string”  and not    This is a string’

Signaling functions                GTop

Name

Function

Parameters

Usage example

Usage description

Buy

Buy()

1. Optional: comment(string)

 

Buy()

Buy(“I am buying now”);

 

Buy(“ Buy at Close=”.Close()  )

Issue a buy command (long entry)

Issue a Buy command and print “I am buying now” string in Chart summary report

Issue a Buy command and print “Close=XX” string in Chart summary report (XX will have the value of last Close)

Note: ‘.’ Is used for string concatenation. Use it to join two or more strings together. In th example first string is “Buy at Close=” and second string is the result of Close(). The ‘.’ Function will join them together into a single string that will be used by Buy.

Sell

Sell()

1. Optional: comment(string)

 

Sell()

Sell(“My Comment today is”.Date()  );

Issue a Sell command  (long exit)

Issue a Sell command and print “My Comment Today is XX-XXX-XX” in the Chart summary report.

Sellshort

Sellshort()

1. Optional: comment(string)

 

Sellshort()

Sellshort(“ My Low is=”.Low() );

Issue a Sellshort command (short entry)

Issue a Sellshort command and print “My Low is=XX.XX” in the Chart summary report.

Buytocover

Buytocover()

1. Optional: comment(string)

 

Buytocover()

Buytocover(“nothing to say…”);

Issue a Buytocover command  (long exit)

Issue a Buytocover command and print “nothing to say…” in the Chart summary report.

Market Position

MP()

None.

If ( MP() == 0 )

MP() returns market position:

0 – no current position (holding) for the symbol

1 – Long position

-1 – Short position

You need to use this function in your strategy to check if you are already in a long or short position. Buy command, will change the value of MP from 0 to 1. Sell will change it back from 1 to 0. Sellshort will change it from 0 to -1 and Buytocover will change it back to 0.

Special and Debug functions                   GTop

Name

Function

Parameters

Usage example

Usage description

DebugMSG – write a debug message into debug message log file

DebugMSG()

1. String

 

DebugMSG(“This is our first run”);

 

DebugMSG(“Today is”.Date().” Close is:”.Close());

 

 

Write a string “This is our first run” into the log file

 

 

Write a string with values obtained from functions

 

Note:    accessing the message log file is possible from:

1.       Chart->Debug menu

2.       Lab->Result->Download log file (under strategy name)

DrawEvent – write an arrow with a comment in the Chart

DrawEvent()

1. comment (string)

2. arrow color

3. back bars/days

 

DrawEvent(“Buy Now”,”Green”);

 

DrawEvent(“Gap Up today”.Date(3) , “Brown” , 3);

Print Green arrow on the Chart on current Date with comment “Buy Now”.

 

Print Brown arrow on the Chart 3 days/bars ago with comment “Gap Up Today” and the date 3 days/bars ago.

 

Note:    The arrows with the comment can be viewed only in the Chart module when selecting the portfolio (that includes the strategy).

SetGraph – add graph point to a private graph (the graph will be the collection of points added with SetGraph)

SetGraph()

1. date

2. value

 

SetGraph(Date() , 10  );

 

 

 

For( my $i=1 ; $i<100 ; $i++ ){

      SetGraph( Date($i) , $i );

      }

Add point value 10 on last date/bar.

 

 

 

Create a graph with 99 points each value 1..99 on 1..99 days/bars from today

ReferenceSymbol

ReferenceSymbol ()

1. symbol

 

my $security2 = ReferenceSymbol( "AAPL");

 

# using the reference symbol:

my $rsi1 = RSI($security2 , 14 );

if( RSI( 14 ) > RSI( $security2 , 14 ) {

      Sell();

     }

Create a reference to another symbol. The strategy can refer to it during execution.

 

Calculate RSI(14) of AAPL on last close

 

 

Compare current symbol RSI( 14 ) to AAPL's RSI( 14 )

GetGlobal – obtain access to global many parameters

GetGlobal()

None.

my $params          = GetGlobal();

 

Obtaining multiple variables from Global parameter:

$counter = $params[0];

$str           = $params[1];

@ items   = $params[2];

 

.. now you may use the variables….

 

Get parameters from global variable.

 

Note: global variable is a variable that can be used during different date/time iterations. When back-test or forward test a strategy, the system runs iteration for every day in the time period. All values and parameters are private to each iteration and therefore cannot be pass from one iteration to another. The use of GetGlobal is to help maintaining values across many iterations.

SetGlobal – store many variables in global parameters to be used later

SetGlobal()

None.

SetGlobal(  \@params );

 

Storing multiple variables into Global parameter:

$params[0] = $counter ;

$params[1] = $str;

$params[2] = @items ;

 

.. now store the global parameter:

SetGlobal(  \@params );

Store @params array in global parameter.

 

Notes:

1. when sending array to global parameter you need to use \@ (address of the array0.

2. In this example we use @params array to store many different variable in global parameter. For example:

Storing integer in first params element:

$params[0] = $counter ;

Storing a string in 2nd element:

$params[1] = “My name is Dov” ;

Storing array in 3rd element:

$params[2] = @items ;

 

 

 

GetGlobalVar – store single variable in global parameter

GetGlobalVar()

1. Variable name (without $ sign)

$counter=GetGlobalVar(“counter” );

 

Obtain variable $counter from global variable

SetGlobalVar – store single variable in global parameters

SetGlobalVar()

1. Variable name (without $ sign)

2. Variable

SetGlobalVar( “counter” , $counter);

Store $counter variable in global parameter

Date and date index              GTop

 

Name

Function

Parameters

Usage example

Usage description

Date to index

Date2index()

1. date

Date2indx( “01-Apr-11”)

Convert the date “01-Apr-11” into an index

 

Note: Date format must be: “d-m-y” where:

d – day number (if smaller than 10 must have 0 first, such as 02, 05 04)

m – month short name: e.g. Jan, Feb,Mar

y – two digits year

Example legal date:  “23-Oct-07”

Example illegal dates: “23-01-2011”, “2011-08-12”

Return value: the date index or -1 (the input date is not a valid trading date or the input date in not in the date range (for example, selected range is 1Y and the date goes before).

Index to date

Index2date()

1. index

Index2date( 112 )

Returns the date of index 112. The date format “01-Apr-11”

Return value: the date of the input index or “” – empty string – if input index out of range for example when drawing a 1Y chart and the index input is 5000. There are less than 280 trading days in 1Y so index 5000 do not exist

CloseValue - Close value on a specific Date Index

CloseValue()

1. index

CloseValue(112)

Returns the close value on a specific date index, for example here – return close on date index 112

OpenValue - Open value on a specific Date Index

OpenValue()

1. index

OpenValue(1)

Returns the open value on date index 1

LowValue - Close value on a specific Date Index

LowValue()

1. index

LowValue(12)

Returns the low value on date index 12

HighValue - Close value on a specific Date Index

HighValue()

1. index

HighValue(3)

Returns the high value on date index 3

Max available index

MaxIndex()

none

If (CurrentIndex() == MaxIndex() )

  {

  Add2Universe( “u”,”NewU”,GetSecurityName() );

  }

MaxIndex return the maximum number of iteration for a selected time period. For example, a calendar year has about 260 trading days (indexes). If we run forward-test with time period of 1Y, maxIndex value will be 260.

 

 

Note MaxIndex and not Maxindex (capital i)

Current index

CurrentIndex()

none

If (CurrentIndex() == MaxIndex() )

  {

  Add2Universe( “u”,”NewU”, GetSecurityName () );

  }

Current index is the current iteration number. For example, running forward test for 1 months current index will start with 0 and grow by one on each iteration till reach max index which is 22 (for one month).

 

Note CurrentIndex and not Currentindex (capital i)

 

Date manipulations               GTop

Name

Function

Parameters

Usage example

description

parsing a date

ParseDate()

1. date string or date description

$date = ParseDate("today");
$date = ParseDate("1st Thursday in June 1992");
$date = ParseDate("05/10/93");
$date = ParseDate("12:30 Dec 12th 1880");
$date = ParseDate("8:00pm December tenth");

 

parsing an amount of time

ParseDateDelta()

1. datetime/period description

$delta = ParseDateDelta("in 12 hours");
$delta = ParseDateDelta("-1:30:0");
$delta = ParseDateDelta("4 business days later");

calculating the amount of time between two dates

DateCalc()

1. date 1

2. date 2

Return value: diff

$date1 = ParseDate($string1);
$date2 = ParseDate($string2);
$delta = DateCalc($date1,$date2);

 

and the approximate amount: 
$delta = DateCalc($date1,$date2,1);

 

Date compare

Date_Cmp()

1. date 1

2. date 2

Return value: -1,0,1

$datestr1 = "Jan 30 1999 13:00 EST";
$datestr2 = "2/Mar/1999 15:30:00 +0500";
$date1 = ParseDate($datestr1);
$date2 = ParseDate($datestr2);
Date_Cmp($date1,$date2); 

return value: < =>  or   -1, 0, 1 

 

number of seconds since the epoch (Jan 1, 1970 00:00:00 UTC)

UnixDate ()

1. date

2. flag

 

$total_seconds = UnixDate($datestr,'%s'); 

 

Parse recurring event

ParseRecur()

 

@date = ParseRecur("0:1*2:2:0:0:0","","Jan 1 1999","Apr 30 1999");



@date = ParseRecur("*1997-1999:0:0:0:0:0:0*EASTER,ND1");

Find the 2nd Tuesday of every month from Jan 1 1999 to Apr 30 1999

 

Find the Monday after Easter in 1997-1999.

Note: check details of date manipulation Date::Manip

 

General functions                  GTop

Name

Function

Parameters

Usage example

Usage description

Get current security name

GetSecurityName()

none

 

$sec = GetSecurityName()

Returns the current symbol used by the strategy. In Charts module its always the Chart selected symbol. In Lab testing and marketplace calculations it’s the current symbol loaded from the universe.

Get strategy capital

GetStrategyCapital()

none

 

$cash = GetStrategyCapital()

Returns the total strategy allocation from the portfolio capital. As defined in Strategy edit page.

Get strategy Max positions

GetStrategyMaxpositions()

none

 

GetStrategyMaxpositions()

Returns the strategy max allowed positions. As defined in Strategy edit page.

Get strategy position size

GetStrategyPossize()

none

 

GetStrategyPossize()

Returns the strategy position size. As defined in Strategy edit page.

Add a symbol to a universe

Add2Universe()

1. user name

2. universe name

3. symbol

4. optional: power

Add2Universe( ‘user’ , ‘MyNewUniverse’ , $sec , 12 )

 

Add2Universe( ‘user’ , ‘MyNewUniverse’ , $sec , SMA(30)  )

 

Add symbol defined in $sec to universe named ‘MyNewUniverse’ (if not exist, than create it) belonging to user ‘user’ (must be your user name) with a symbol power (rank) of 12.

 

Add symbol defined in $sec to universe named ‘MyNewUniverse’ (if not exist, than create it) belonging to user ‘user’ (must be your user name) with a symbol power (rank) equal to the symbol’s SMA of last 30 days.

 

Absolute value

abs()

1. number

$number = abs( -23 )

$number = abs( $var )

Store in $number the absolute value of -23 which is 23.

Store in $number the absolute value of variable $var

Lower case

lc()

1. string

$str = lc(“This is a Mix String”)

Store in $str the lower case of the string, meaning ‘this is a mix string’

Upper case

uc()

1. string

$str = uc(“This is a Mix String”)

Store in $str the upper case of the string, meaning ‘THIS IS A MIX STRING’

FormatNumber

FormatNumber()

1. number

$str = FormatNumber( 10000);

Will store in $str 10,000.00

FormatNumberNoComma

FormatNumberNoComma()

1. number

$str = FormatNumberNoComma ( 10000);

Will store in $str 10000.00

sprintf

Sprint()

1. format string

2. number

 

$result = sprintf("%08d", $number);

 

$rounded = sprintf("%.3f", $number);

Format number with up to 8 leading zeroes

 

 

Round number to 3 digits after decimal point

 

 

Note: check more on sprint here

 

Flow control                 GTop

Name

Function

Parameters

Usage example

Usage description

if

if (EXPR) BLOCK

Logical expression

 

If( Close() > Close(2) ){

     Buy();

     }

If close of last day/bar is greater than the close of 2 days/bars ago, issue Buy();

else

if (EXPR) BLOCK else BLOCK

none

 

If( Close() > Close(2) ){

     Buy();

     }

else {

         $myvar = Close(5);

         }

.., else store close of 5 days/bars ago in variable $myvar

elsif

if (EXPR) BLOCK elsif (EXPR) BLOCK ...

if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK

Logical expression

 

If( Close() > Close(2) ){

     Buy();

     }

elsif(  Close() > Close(5)  ) {

            $myvar = 12;

            }

 

…, else if close of last day/bar is greater than close of 5 days/bars ago, store value 12 in variable $myvar

unless

unless (EXPR) BLOCK

Logical expression

 

$total= 100 unless defined $total;

If $total is not defined than assign value 100, if it is defined, keep its previous value.

for

 

 

for ( my $J = 0 ; $j <= 20 ; $j++ ) {
DebugMSG(" j=" . $j );
}

Loop (21 times) from 0 to 20, each time write a message to the message log with ‘J=’ and the value

while

 

Logical expression

$flag = 0 ;

While( $flag <= 12 ) {

       $flag++;

       }

 

While $flag is smaller than 12 keep executing the block which is: increase $flag by one.

foreach

 

element

array

my @myArray = ( 12 , 8 , 40 , 20 , 15 , 5);

my $total = 0;

foreach $element (@myArray) {

               $total = $total + $element;

               }

 

Sum all elements of $myArray and store it in $total.

At the end of th eexmaple, $total equal to 100;

(  ? , )

( EXPR ? BLOCK1 , BLOCK2 )

 

my $bignumber = ( $x > 10 ? $x : -1 );

if $x is bigger than 10 $bignumber gets $x otherwise $bignumber gets -1

 

Regex – regular expressions           GTop

You can use a regular expression for matching, substitution, and translation of patterns in strings. It’s an ultra-powerful tool and with a little practice, you'll be able to do some incredibly strategy code. Check the following links to master Perl regex and use them in your strategies:

 

 

 

X
Enter your Strategy Seeker username.
Enter the password that accompanies your username.
2 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
Secure Login

This login is SSL protected

Loading