Friday, May 27, 2011

Common functions

Common functions
Alert ()
Comments ()
GetLastError ()
GetTickCount ()
IsDemo ()
IsTesting ()
IsTradeAllowed ()
MarketInfo ()
MessageBox ()
Period ()
PlaySound ()
Print ()
RefreshRates ()
Sendmail ()
ServerAddress ()
Sleep ()
SpeechText ()
Symbol ()


void Alert (...)

Displays a dialog box containing user-defined information. Parameters can be of any type. Arrays can not be transferred to the signaling function. Data of bool, datetime and color types will be printed as numerical presentation. To print values ��of datetime type string to convert by TimeToStr () function.
See also: comment () and print () functions.
Parameters

... - Any values, separated by commas.
Sample
if (Close [0]> SignalLevel)
Alert ("Close price coming, near [0 ],"!!!");


void Comments (...)

Prints some message to the top left corner of the chart. Parameters can be of any type. Arrays can not be transferred to the post office. Arrays should be output elementwise. Data of bool, datetime and color types will be printed as numerical presentation. To print values ��of datetime type string to convert by TimeToStr () function.
See also: signal () and print () functions.
Parameters

... - Any values, separated by commas.
Sample
Comment ("Your margin is", AccountFreeMargin (), "\ n",
"Current time", TimeToStr (CurTime));


int GetLastError ()

Returns the last error occurred after the operation and sets the last internal error value of zero. Error codes listed in error codes page.
Sample
FileWrite (handle, "Grills total =" Bars);
if alert ("Some error message") (GetLastError () = 0!)


int GetTickCount ()

GetTickCount function retrieves the number of milliseconds elapsed since the system was started. It is limited to the resolution of the system timer.
Sample
"Int" = home GetTickCount ();
/ / Do some heavy calculation ...
Print ("Calculating time", GetTickCount ()-start, "milliseconds.");


bool IsDemo ()

Returns true if the expert is working on a demo account, otherwise returns false.
Sample
if (IsDemo ()) print ("I am working on a demo account");
else print ("I am working on a real account");


bool IsTesting ()

Returns true if the expert works in testing, otherwise returns false.
Sample
if (IsTesting ()) print ("I'm testing now");


bool IsTradeAllowed ()

Returns true if trade is allowed for an expert, otherwise returns false.
Sample
if (IsTradeAllowed ()) print ("permitted trade");


double MarketInfo (string symbol, int type)

Returns the value of the market watch window.
Parameters

symbol - Guidelines symbol.
type - Return data type index. It could be any of the information market value identifiers.
Sample
double var;
var = MarketInfo ("EURUSD", MODE_BID);


int MessageBox (string text = NULL, string caption = NULL, int flags = empty)

MessageBox function creates, displays, and works on the message box. Window message contains application-defined message and title, plus any combination of predefined icons and buttons.
If the function succeeds, the return value is one of the MessageBox return code values.
Parameters

Text - Optional text that contains the message to be displayed.
title - Optional text field that contains the title. If this parameter is NULL, the title will be the name of the expert.
flag - determines the content and conduct of dialogue. This parameter can be combination of flags from the following groups of flags.
Sample
# Include <WinUser32.h>

if (ObjectCreate ("text_object", OBJ_TEXT, 0, T'2004 .02.20 12-30, 1,0045) == false)
{
int ret = MessageBox ("ObjectCreate () fails with code" + IntToStr (GetLastError ())+" \ nContinue "," P ", MB_YESNO | MB_ICONQUESTION);
if (RET == IDNO) return (false);
}
/ / Continue


Period int ()

Returns the number of minutes defining the use of time (time limit scheme is).
Sample
Print ("Q-e" Q ());


void PlaySound (string filename)

Function plays a sound file. The file must be located terminal_dir \ sounds directory or subdirectory.
Parameters

File - Sound file name.
Sample
if (IsDemo ()) PlaySound ("alert.wav");


void print (...)

Prints some message to the experts log. Parameters can be of any type. Arrays can not be transferred to the office for printing. Arrays to be printed out elementwise. Data of bool, datetime and color types will be printed as numerical presentation. To print values ��of datetime type string to convert by TimeToStr () function.
See also: signal () and Comment () functions.
Parameters

... - Any values, separated by commas.
Sample
Print ("Account is a margin", AccountFreeMargin ());
Print ("Current time", TimeToStr (CurTime));
/ / Print Array
for (int i = 0; i <10; i + +)
Print (Close [i]);


bool RefreshRates ()

Refreshing data in variables and built-series arrays. This function is used when calculating an expert advisor in a long time and should refresh data. Returns true if the data is refreshed, otherwise false.
Sample
while (true)
{
ticket = OrderSend (Symbol (), OP_BUY, 1,0, Ask, 3,0,0, "expert comment", 255,0, CLR_NONE);
if (ticket <= 0)
{
int error = GetLastError ();
if (error == 134) break; / / not enough money
if (error == 135) RefreshRates (); / / changed prices
break;
}
else {OrderPrint (); break;}
//---- 10 seconds wait
Sleep (10000);
}


void sendmail (string subject, string some_text)

Send mail to the address set in Tools-> Options-> Email tab if it is enabled.
Parameters

subject - Subject text.
some_text - e-mail body.
Sample
double lastclose = Close [0];
if (lastclose <my_signal)
Sendmail ("from your expert," "Price dropped" + DoubleToStr (lastclose));


array ServerAddress ()

Returns associated server address in the form of text string.
Sample
Print ("server responses", ServerAddress ());


Void Sleep (int milliseconds)

Sleep function suspends the execution of the current expert on a certain interval.
Parameters

milliseconds - Sleep interval in milliseconds.
Sample
Sleep (5);


void SpeechText (string text, int lang_mode = SPEECH_ENGLISH)

Computer speak some text.
Parameters

Text - Speech text.
lang_mode - SPEECH_ENGLISH (by default) or SPEECH_NATIVE values.
Sample
double lastclose = Close [0];
SpeechText ("The price dropped down to" + DoubleToStr (lastclose));


string symbol ()

Returns text string with the name of the current financial instrument.
Sample
for (CNT = 0; CNT <OrdersTotal (); CNT + +)
{
OrderSelect (CNT, SELECT_BY_POS);
if (OrderType ()> OP_SELL | | OrderSymbol () = Symbol ()!) continue;
/ / Some processing orders ...
}

No comments:

Post a Comment

Powered by Blogger.