Subroutine support in Strategy code

Yes, you can now define your own subroutine (and functions) with your strategy code. This is required when writing complex strategies in a logic and simple way.
Also, it is required when there is a need to reuse existing code in different strategies.

So how we do it?

Very simple, as any Perl code (yes, Strategy Seeker’s script language is in fact Perl :-) ) we use the “sub” keyword, for example:

sub GetMyName(){
$str = “John Smith”;
return $str;
}

This subroutine (function as it return a value) returns a string. How to call it:

$myname = GetMyName();

What if we want to send parameters to the subroutine?

sub show_me {
$str = shift;
DebugMSG( $str );
}

The parameter is sent (“by value”) to show_me subroutine and is obtained using the shift command. Here is how we call it:

show_me(“ This is a debug message that will be sent to our log…”);

If we have few parameters:

sub show_me {
$str = shift;
$num = shift;
DebugMSG( “String:” . $str . ” Number:” . $num );
}

Alternative way to send parameters to a subroutine:

sub print_me(){
$str = $_[0] ; # obtain first parameter
$n = $_[1] ; # obtain second parameter
$long_str = "Hello: $str you are num: $n \n";
DebugMSG( $long_str );
}

Remember, our strategy language is simply Perl, check the internet for complex Perl options such as lists, passing parameters by reference, etc. They are all supported.

Have a great trading day!
Strategy Seeker Team.

Example:

The following example shows two subroutines, print_me and show_me, and two different ways to send parameters.
Also, note the use of a global variable $GlobalName, that can be used within the strategy code or within any of its subroutines.

Strategy sub

Output in message log will be:

18-12-2012 17:42:2: Barak Obama say: Me too...
18-12-2012 17:42:2: Hello: Hi there.... you are num: 2

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

This login is SSL protected

Loading