Other Functions

hmtoggle_plus1Message notification

 

You can use message notifications in your strategies. For instance, you may want to create a strategy that will instead of actively trading work as an advisor, notifying you about the right time to perform transactions.   To do this, use the function ShowMessage(const s: String).

 

Example:

 

You need to get a message ‘Time to buy EURUSD’ every time when the difference between the open and the close price of the last finished candle is bigger than 20 points. You need the following lines:

 

procedure OnNewCandle;

begin

if (History.Last(1).Open – History.Last(1).Close > 20*History.Instrument.PointSize) then

ShowMessage('Time to Buy EURUSD’);

end;

 

ribbonactfx64

 

hmtoggle_plus1Sound Notification

 

You can use sound notifications in your strategies. For instance, you can write a strategy that will play an audio file every time some event takes place. To do this, use the function PlaySound(const FileName: String).

 

Example:

 

You want to hear a notification every time when the rate becomes higher than 1.5000. You need the following lines:

 

procedure OnNewRate;

begin

 if (History.Last(1).Rate < 1.5000) and (History.Last.Rate > 1.5000) then

 PlaySound('E:\MySounds\HighRate.wav');

end;

 

As a result, the audio file HighRate.wav from the directory  E:\MySounds will be played.

Note:

1) The Silent Mode in the WinClient settings should be disabled. Otherwise you will not hear any sounds.

2) The  directory and file names should contain only Latin letters.

3) The file should be in the .wav format.

 

hmtoggle_plus1Mathematical

 

Function

Description

function Sqr(const X: Double): Double

Square

function Max(const A, B: Double): Double

The greater of the two numbers

function Min(const A, B: Double): Double

The lesser of the two numbers

function Round(e: Extended): Integer

Rounds to the nearest integer

function Trunc(e: Extended): Integer

Truncates the fractional part

function Int(e: Extended): Integer

Returns the integer part of the number

function Frac(X: Extended): Extended

Returns the fractional part

function Sqrt(e: Extended): Extended

Square root

function Abs(e: Extended): Extended

Absolute value

function Sin(e: Extended): Extended

Sine

function Cos(e: Extended): Extended

Cosine

function ArcTan(X: Extended): Extended

Arctangent

function Tan(X: Extended): Extended

Tangent

function Exp(X: Extended): Extended

Exponential

function Ln(X: Extended): Extended

Natural logarithm

function Pi: Extended

Pi


hmtoggle_plus1Date/Time

 

function EncodeDate(Year, Month, Day: Word): TDateTime

Converts year, month and day into a date

procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word)

Converts a date into year, month and day

function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime

Converts hours, minutes and seconds into time

procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word)

Converts time into hours, minutes and seconds

function Date: TDateTime

Current date

function Time: TDateTime

Current time

function Now: TDateTime

Current date and time

function DayOfWeek(aDate: DateTime): Integer

Day of the week

function IsLeapYear(Year: Word): Boolean

Check if leap year

function DaysInMonth(nYear, nMonth: Integer): Integer

Number of days in a month

 

hmtoggle_plus1Data Type Conversion Functions

 

function IntToStr(i: Integer): String

Converts an integer into a string

function FloatToStr(e: Extended): String

Converts a fractional number into a string

function DateToStr(e: Extended): String

Converts a date into a string

function TimeToStr(e: Extended): String

Converts time into a string

function DateTimeToStr(e: Extended): String

Converts date and time into a string

function StrToInt(s: String): Integer

Converts a string into an integer

function StrToFloat(s: String): Extended

Converts a string into a fractional number

function StrToDate(s: String): Extended

Converts a string into a date

function StrToTime(s: String): Extended

Converts a string into time

function StrToDateTime(s: String): Extended

Converts a string into date and time

function StrToColor(const HexRGB: String): TColor

Converts a string into color

 

hmtoggle_plus1String Functions

 

function Length(s: String): Integer

Length of the string

function Copy(s: String; from, count: Integer): String

Returns a substring of the given length starting from the specified position

function Pos(substr, s: String): Integer

Returns the position of a substring within given string

procedure Delete(var s: String; from, count: Integer)

Removes a substring of the given length starting from the specified position

procedure Insert(s: String; var s2: String; pos: Integer)

Appends the second string to the first

function Uppercase(s: String): String

Converts the string into uppercase

function Lowercase(s: String): String

Converts the string into lowercase

function Trim(s: String): String

Removes blank spaces from the string

function NameCase(s: String): String

Converts the first letter into uppercase

function CompareText(s, s1: String): Integer

Compares two strings

function Chr(i: Integer): Char

Returns the character with specified position

function Ord(ch: Char): Integer

Returns the position of the specified character

procedure SetLength(var S: String; L: Integer)

Sets the length of a string

 

hmtoggle_plus1Other functions

 

procedure Inc(var i: Integer; incr: Integer = 1)

Increment

procedure Dec(var i: Integer; decr: Integer = 1)

Decrement

procedure RaiseException(Param: String)

Generates error message

procedure Randomize

Initializes the random numbers generator

function Random: Extended

Generates a random number in the range between 0 and 1

function ValidInt(cInt: String): Boolean

Validates an integer

function ValidFloat(cFlt: String): Boolean

Validates a fractional number

function ValidDate(cDate: String): Boolean

Validates a date

 

hmtoggle_plus1TStringList class objects

 

TStringList class objects are used to save and load data to/from a .txt file.

In order to create such an object, use the method TStringList.Create.

 

Example:

 

procedure OnStart;

var

 Settings: TStringList;

begin

 Settings := TStringList.Create;

end;

 

This object has 5 properties:

a) Count: Integer – the number of strings in the list

b) Names[ ]: String – the name at a given index in the list
c) Values[ ]: String – the value for a given name when using name/value pair strings
d) Strings[ ]: String - the string at a given index in the list
e) Text: String – the whole list

 

There is a dual approach to store individual strings in a file. Each string can be stored as simple text (string), or if it contains the equals sign ('='), it can be treated as a name/value pair. The text on the left of the equals sign is regarded as a name, and the text on the right is regarded as a value.

This concept provides an alternative way to refer to a particular value. The values property returns the value for a given name, therefore it is not necessary to know the index of the string.

You can create a name/value string by simply assigning some value to some name.

 

Example:

 

MyParameters.Values['Amount'] := '5';

 

If the name 'Amount' is already present in the list, the corresponding value will be changed to 5. If there is no such name, a new string will be appended to the end of the list.

 

Example:

 

Let us create a name/value pair when a position is opened. We will store the position ticket # with the  name 'Trade'. We will also output this information into the log.

 

var

 MyParameters: TStringList;

 

procedure OnStart;

begin

 MyParameters := TStringList.Create;

end;

 

procedure OnTradeChange;

begin

 if Action = dmtInsert then

 begin

 MyParameters.Values ['Trade'] := Trade.Id;

 MyParameters.SaveToFile ('c:\list.txt');

 log ('Trade id: ' + MyParameters.Values['Trade'] );

 end;

end;

 

You can use the following methods when working with this object:

 

Methods

Description

TStringList.Create

Creates a TStringList object

TStringList.Add(const S: string): Integer

Adds a string to the list

TStringList.Clear

Clears the list

TStringList.Delete(Index: Integer)

Deletes the string with the given index from the list

TStringList.IndexOf(const S: string): Integer

Returns the index of the given string.

TStringList.IndexOfName(const Name: string): Integer

Returns the index of the string with a given name.

TStringList.Insert(Index: Integer; const S: string)

Inserts the given string into the given position.

TStringList.LoadFromFile(const FileName: string)

Loads the values from a file into the String list.

TStringList.SaveToFile(const FileName: string)

Saves the String list into the file.

TStringList.Free

Removes a TStringList object from memory

 

Show/Hide Hidden Text