Our Functions and Technical Indicators

In general, our strategy script language is Perl Programming language. You may use Perl syntax except few commands, such as 'eval', 'system' etc.) that have been removed due security reasons. We also support Perl Regular expressions (regex). Regular expressions are very powerful tools for matching, searching, and replacing text. Also, we are adding CPAN modules as needed, such as date manipulation Date::Manip (no need to add use, its built in our system), etc. If you have a need for a CPAN module that is missing here, Contact us and ask for, we will do our best to have it ready to everyone quickly.

The following list supported functions within a strategy:

Signaling functions:
Buy() - issue a Buy signal. Buy() optional parameter is a string that will be printed in Chart report, example: Buy(" Buy signal close=".Close() ); #this will print in the Chart report: "Buy signal close=131.00"
Sell() - issue a Sell signal. Sell() optional parameter is a string that will be printed in Chart report, example: Sell(" Sell signal low=".Low() );#this will print in the Chart report: "Sell signal low=139.00"
MP() - Market position. This function returns 0 - if no Buy was issued and we hold no position, 1 - if we had a Buy and therefore we hold position or -1 if we had a SellShort and therefore we have such position (note: SellShort is yet not supported).
Sellshort() - issue a Sell Short signal. Sellshort() optional parameter is a string that will be printed in Chart report, example: Sellshort(" Sellshort signal high=".High() );#this will print in the Chart report: "Sellshort signal high=192.00"
Buytocover() - issue a Buy to cover signal. Buytocover() optional parameter is a string that will be printed in Chart report, example: Buytocover(" Buy To Cover signal close=".Close() ); #this will print in the Chart report: "Buy To Cover signal close=131.00"
Buyprice() - Last Buy price. For Long trades: this function returns the price of last Buy. This function gets no optional parameters and is valid only when MP() == 1.
Buydate() - Last Buy date. For Long trades: this function returns the dateof last Buy. This function gets no optional parameters and is valid only when MP() == 1.
Sellprice() - Last Buy price. For Short trades: this function returns the price of last Sellshort. This function gets no optional parameters and is valid only when MP() == -1.
Selldate() - Last Buy date. For Short trades: this function returns the dateof last Sellshort. This function gets no optional parameters and is valid only when MP() == -1.

Date calculation functions:
Date2index( date input ) - Convert date to index. Date input format: "01-Apr-11" (March 1st 2011). Note if day number is smaller than 10 a zero must be added. Return value - day 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).
Index2date( index input ) - Convert index to date to index. index input: integer. Date output format: "01-Apr-11" (March 1st 2011). If input index is out of range, for example when drawing a 1Y chart index input is 5000, the function Index2date(5000) will return empty string "".

Stock values:
Note: the following functions has 1 optional parameter, number of days back from today. for example '1' is yesterday, '2' is two days ago, etc.
Close() - today's close. Close(1) - yesterday close, Close(2) - close two days ago, etc.
High() - today's high. High(1) - yesterday high, etc.
Low() - today's low. Low(1) - yesterday low, etc.
Open() - today's open. Open(4) - open four days ago....
Volume() - today's volume.
Date() - today's date. Date(5) - date of 5 days ago.

General functions:
Add2Universe($username,$universename,$symbol) - Add a symbol to a universe (if do not exist, create new universe).
MaxIndex() - return the max number of bars in current Strategy Execution (for example: in strategy execution of 1 year it will be 250).
CurrentIndex() - return the current index/bar of current Strategy Execution (for example: in strategy execution of 1 year there are 250 days so CurrentIndex will start at 0 and will grow in each iteration up to 250 - last day execution).
GetSecurityName() - return the current Symbol used by the strategy.
getStrategyCapital() - return the current Strategy Allocation (from Portfolio Capital).
getStrategyMaxpositions() - return the current Strategy max positions.
getStrategyPossize() - return the current Strategy position size.
abs() - returns the absolute value of its argument. Examples: abs(-10) returns 10, abs($x) returns the absolute value of variable $x, etc.
uc() - returns an uppercased version of a string.
lc() - returns a lowercased version of string.

Debug functions:
DebugMSG - writes a debug message to log file.
DrawEvent - draws arrow and comment on Stock Chart.

Special functions:
SetGraph - Create a private graph (will show in Chart menu under Symbol Chart)
ReferenceSymbol - Open a reference symbol ("channel")
Example:

# Open a Reference Symbol to "AAPL"
my $security2 = ReferenceSymbol( "AAPL");
#
# Calculate RSI(14) of AAPL on last close
my $rsi1 = RSI($security2 , 14 );
#
# Compare current symbol RSI( 14 ) to AAPL's RSI( 14 )
if( RSI( 14 ) > RSI( $security2 , 14 ) {
....
}

GetGlobal - Get (read) Global parameter value (may simple var, constant, array or hash)
SetGlobal - Sets (save) Global parameter value (may simple var, constant, array or hash)
FormatNumber - Nice print: formats a number.
CloseValue - Close value on a specific Date Index. (different than Close() which provides "Today" Close or Close(1) for Yesterday Close etc.
LowValue - Low value on a specific Date Index.
HighValue - High value on a specific Date Index.
OpenValue - Open value on a specific Date Index.
sprintf () - Returns a string formatted by the usual printf conventions of the C library function sprintf. Examples:
#declare local variables:
my $result ;
my $number = 120 ;
# Format number with up to 8 leading zeroes
$result = sprintf("%08d", $number);
# Round number to 3 digits after decimal point
$number = 120.123 ;
$rounded = sprintf("%.3f", $number);

Date manipulation functions:
Note: check details of date manipulation Date::Manip :
ParseDate - parsing a date, examples:

$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");

ParseDateDelta - parsing an amount of time, examples:

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

DateCalc - calculating the amount of time between two dates, examples:

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

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

Date_Cmp - compare two dates, examples:

$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 will be: => -1, 0, 1

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

UnixDate($datestr,'%s');
return will be: => number of seconds

ParseRecur - recurring events, examples:

# To find the 2nd Tuesday of every month from Jan 1 1999 to Apr 30 1999:
@date = ParseRecur("0:1*2:2:0:0:0","","Jan 1 1999","Apr 30 1999");
# To find the Monday after Easter in 1997-1999.
@date = ParseRecur("*1997-1999:0:0:0:0:0:0*EASTER,ND1");

Technical Indicator functions:
Note: the following functions has at least one optional parameter, number of days back from today. for example '1' is yesterday, '2' is two days ago, etc. More details on technical indicator function usage below.
ADX() - Average Directional Movement Index.
ATR() - Average True Range.
BOP() - Balance Of Power.
MAX() - Highest value over a specified period.
MIN() - Lowest value over a specified period.
ROC() - Rate of change : ((price/prevPrice)-1)*100.
RSI() - Relative Strength Index.
SMA() - Simple Moving Average.
EMA() - Exponential Moving Average.
OBV() - On Balance Volume.
MACD() - Moving Average Convergence-Divergence .
SAR() - Parabolic SAR.
STOCH() - Stochastic.
STOCHRSI() - Stochastic Relative Strength Index.
MFI() - Money Flow Index.

Flow-control keywords:
if
else
elsif
unless
for
( EXPR ? BLOCK : BLOCK )

Examples:
if (EXPR) BLOCK
if (EXPR) BLOCK else BLOCK
if (EXPR) BLOCK elsif (EXPR) BLOCK ...
if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK
unless (EXPR) BLOCK


for( my $i=0 ; $i se 10 ; $i++ ) BLOCK


for ( my $J = 0 ; $j se 20 ; $j++ ) {
DebugMSG(" j=" . $j );
}
my $bignumber = ( $x > 10 ? $x : -1 ); # if $x is bigger than 10 $bignumber gets $x otherwise $bignumber gets -1

Special Japanese Candle Indicator functions:
Note: the following functions returns TRUE or FALSE if a specific Japanese Candle pattern is reached on a specific date. All functions starts with "JC_" - stands for Japanese Candles. You may use '1', '2' or other number to specify days back.
JC_3WhiteSoldiers() - Three Advancing White Soldiers.
JC_Doji() - Doji.
JC_DojiDragonFly() - Doji Dragon Fly.
JC_DojiGreaveStone() - Doji Dragon Stone.
JC_DojiStar() - Doji Star.
JC_EveningStar() - Evening Doji Star.
JC_Hammer() - Hammer.
JC_InvertedHammer() - Inverted Hammer.
JC_Marubozu() - Marubozu.

Regular Expressions (regex):
You can use a regular expression for matching, substitution, and translation of patterns in strings. Its an ultra powerfull 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:
recommended: Perl 5 by examples, by David Medinets
Steve Litt's Perls of Wisdom: Perl Regular Expressions
Regular expressions in Perl by Jukka "Yucca" Korpela.
PerlDoc
Perl Regular Expression Quick Reference Card
Perl Regular Expressions Tip Sheet

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