myeatrade

Blog

MQL4 Technical indicators (1)

A group of functions intended for calculation of standard and custom indicators.

For an expert (or any other MQL4 program) to take up the value of any indicator, it is not necessary that this indicator is present in the chart. The requested indicator will be loaded and calculated in the thread of the module that has called it.

Any indicator can be calculated on the data of not only current chart, but also on the data of any available symbol/period. If data (symbol name and/or timeframe differ from the current ones) are requested from another chart, the situation is possible that the corresponding chart was not opened in the client terminal and the necessary data must be requested from the server. In this case, error ERR_HISTORY_WILL_UPDATED (4066 – the requested history data are under updating) will be placed in the last_error variable, and one will has to re-request (see example of ArrayCopySeries()).

 

iAC()

double iAC(string symbol, int timeframe, int shift)

Calculates the Bill Williams’ Accelerator/Decelerator oscillator.

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double result=iAC(NULL, 0, 1);

iAD()

double iAD(string symbol, int timeframe, int shift)

Calculates the Accumulation/Distribution indicator and returns its value.

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double result=iAD(NULL, 0, 1);

iAlligator()

double iAlligator(string symbol, int timeframe, 
                  int jaw_period, int jaw_shift, 
                  int teeth_period, int teeth_shift, 
                  int lips_period, int lips_shift, 
                  int ma_method, int applied_price, 
                  int mode, int shift)

Calculates the Bill Williams’ Alligator and returns its value.

Parameters:

symbol          - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe       - Timeframe. It can be one of Timeframe enumeration values. 0 means the current chart timeframe. 
jaw_period      - Blue line averaging period (Alligator's Jaw). 
jaw_shift       - Blue line shift relative to the chart. 
teeth_period    - Red line averaging period (Alligator's Teeth). 
teeth_shift     - Red line shift relative to the chart. 
lips_period     - Green line averaging period (Alligator's Lips). 
lips_shift      - Green line shift relative to the chart. 
ma_method       - MA method. It can be any of Moving Average methods. 
applied_price   - Applied price. It can be any of Applied price enumeration values. 
mode            - Data source, identifier of a line of the indicator. It can be any of the following values:
MODE_GATORJAW   - Gator Jaw (blue) balance line,
MODE_GATORTEETH - Gator Teeth (red) balance line,
MODE_GATORLIPS  - Gator Lips (green) balance line. 
shift           - Shift relative to the current bar (number of periods back) where the data should be taken from. 

Sample:

  double jaw_val=iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORJAW, 1);

iADX()

double iADX(string symbol, int timeframe, int period, 
            int applied_price, int mode, int shift)

Calculates the Movement directional index and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation. 
applied_price - Applied price. It can be any of Applied price enumeration values. 
mode          - Indicator line index. It can be any of the Indicators line identifiers enumeration value. 
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iADX(NULL,0,14,PRICE_HIGH,MODE_MAIN,0)>iADX(NULL,0,14,PRICE_HIGH,MODE_PLUSDI,0)) return(0);

iATR()

double iATR(string symbol, int timeframe, int period, int shift)

Calculates the Indicator of the average true range and returns its value.

Parameters:

symbol    - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period    - Averaging period for calculation.   
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iATR(NULL,0,12,0)>iATR(NULL,0,20,0)) return(0);

iAO()

double iAO(string symbol, int timeframe, int shift)

Calculates the Bill Williams’ Awesome oscillator and returns its value.

Parameters:

symbol    - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iAO(NULL, 0, 2);

iBearsPower()

double iBearsPower(string symbol, int timeframe, int period, 
                   int applied_price, int shift)

Calculates the Bears Power indicator and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation. 
applied_price - Applied price. It can be any of Applied price enumeration values.  
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iBearsPower(NULL, 0, 13,PRICE_CLOSE,0);

iBands()

double iBands(string symbol, int timeframe, int period, 
              int deviation, int bands_shift, int applied_price, 
              int mode, int shift)

Calculates the Bollinger Bands indicator and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate the indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period to calculate the main line. 
deviation     - Deviation from the main line. 
bands_shift   - The indicator shift relative to the chart. 
applied_price - Applied price. It can be any of Applied price enumeration values. 
mode          - Indicator line index. It can be any of the Indicators line identifiers enumeration value. 
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,0)>Low[0]) return(0);

iBandsOnArray()

double iBandsOnArray(double array[], int total, int period, 
                     int deviation, int bands_shift, int mode, 
                     int shift)

Calculation of the Bollinger Bands indicator on data stored in a numeric array. Unlike iBands(…), the iBandsOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function.

Parameters:

array[]     - Array with data. 
total       - The number of items to be counted. 0 means the whole array. 
period      - Averaging period to calculate the main line. 
deviation   - Deviation from the main line. 
bands_shift - The indicator shift relative to the chart.  
mode        - Indicator line index. It can be any of the Indicators line identifiers enumeration value. 
shift       - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iBandsOnArray(ExtBuffer,total,2,0,MODE_LOWER,0)>Low[0]) return(0);

MQL4 String functions

A group of functions intended for working with data of the string type.

 

StringConcatenate()

string StringConcatenate(...)

Forms a string of the data passed and returns it. Parameters can be of any type. Amount of passed parameters cannot exceed 64.

Parameters are transformed into strings according the same rules as those used in functions of Print(), Alert() and Comment(). The returned string is obtained as a result of concatenate of strings converted from the function parameters.

The StringConcatenate() works faster and more memory-saving than when strings are concatenated using addition operations (+).

Parameters:

... - Any values separated by commas. It can be up to 64 parameters. 

Sample:

  string text;
  text=StringConcatenate("Account free margin is ", AccountFreeMargin(), "Current time is ", TimeToStr(TimeCurrent()));
// slow text="Account free margin is " + AccountFreeMargin() + "Current time is " + TimeToStr(TimeCurrent())
  Print(text);

StringFind()

int StringFind(string text, string matched_text, int start=0)

Search for a substring. Returns the position in the string from which the searched substring begins, or -1 if the substring has not been found.

Parameters:

text         - String to search in. 
matched_text - Substring to search for. 
start        - Position in the string to start search from. 

Sample:

  string text="The quick brown dog jumps over the lazy fox";
  int index=StringFind(text, "dog jumps over", 0);
  if(index!=16)
    Print("oops!");

StringGetChar()

int StringGetChar(string text, int pos)

Returns character (code) from the specified position in the string.

Parameters:

text - String. 
pos  - Char position in the string. Can be from 0 to StringLen(text)-1.  

Sample:

  int char_code=StringGetChar("abcdefgh", 3);
  // char code 'c' is 99

StringLen()

int StringLen(string text)

Returns character count in a string.

Parameters:

text - String where the length must be calculated.   

Sample:

  string str="some text";
  if(StringLen(str)<5) return(0);

StringSetChar()

string StringSetChar(string text, int pos, int value)

Returns the string copy with changed character in the specified position.

Parameters:

text  - String where character will be changed. 
pos   - The character position in the string. Can be from 0 to StringLen(text). 
value - New char ASCII code. 

Sample:

  string str="abcdefgh";
  string str1=StringSetChar(str, 3, 'D');
  // str1 is "abcDefgh"

StringSubstr()

string StringSubstr(string text, int start, int length=0)

Extracts a substring from text string starting from the given position.

The function returns a copy of the extracted substring if possible, otherwise, it returns an empty string.

Parameters:

text   - String from which the substring will be extracted. 
start  - Substring starting index. Can be from 0 to StringLen(text)-1. 
length - Length of the substring extracted. 
         If the parameter value exceeds or equals to 0 or the parameter is not specified, 
         the substring will be extracted starting from the given position and up to the end of the string.. 

Sample:

  string text="The quick brown dog jumps over the lazy fox";
  string substr=StringSubstr(text, 4, 5);
  // subtracted string is the "quick" word

StringTrimLeft()

string StringTrimLeft(string text)

The function cuts line feed characters, spaces and tabs in the left part of the string. The function returns a copy of the trimmed string, if possible. Otherwise, it returns an empty string.

Parameters:

text - String to be trimmed at the left.  

Sample:

  string str1="  Hello world   ";
  string str2=StringTrimLeft(str);
  // after trimming the str2 variable will be "Hello World   "

StringTrimRight()

string StringTrimRight(string text)

The function cuts line feed characters, spaces and tabs in the right part of the string. The function returns a copy of the trimmed string, if possible. Otherwise, it returns an empty string.

Parameters:

text - String to be trimmed at the right.  

Sample:

  string str1="  Hello world   ";
  string str2=StringTrimRight(str);
  // after trimming the str2 variable will be "  Hello World"

MQL4 Object functions (2)

A group of functions intended for working with graphical objects related to the current chart.

 

ObjectGetShiftByValue()

int ObjectGetShiftByValue(string name, double value)

The function calculates and returns bar index (shift related to the current bar) for the given price. The bar index is calculated by the first and second coordinates using a linear equation. Applied to trendlines and similar objects. To get the detailed error information, one has to call the GetLastError() function.

See also ObjectGetValueByShift() function.

Parameters:

name  - Object name. 
value - Price value.  

Sample:

  int shift=ObjectGetShiftByValue("MyTrendLine#123", 1.34);

ObjectGetValueByShift()

double ObjectGetValueByShift(string name, int shift)

The function calculates and returns the price value for the specified bar (shift related to the current bar). The price value is calculated by the first and second coordinates using a linear equation. Applied to trendlines and similar objects. To get the detailed error information, one has to call the GetLastError() function.

See also ObjectGetShiftByValue() function.

Parameters:

name  - Object name. 
shift - Bar index.  

Sample:

  double price=ObjectGetValueByShift("MyTrendLine#123", 11);

ObjectMove()

bool ObjectMove(string name, int point, datetime time1, double price1)

The function moves an object coordinate in the chart. Objects can have from one to three coordinates depending on their types. If the function succeeds, the returned value will be TRUE. Otherwise, it will be FALSE. To get the detailed error information, one has to call the GetLastError() function. The object coordinates are numbered starting from 0.

Parameters:

name   - Object name. 
point  - Coordinate index (0-2).   
time1  - New time value. 
price1 - New price value. 

Sample:

ObjectMove("MyTrend", 1, D'2005.02.25 12:30', 1.2345);

ObjectName()

string ObjectName(int index)

The function returns the object name by its index in the objects list. To get the detailed error information, one has to call the GetLastError() function.

Parameters:

index - Object index in the objects list. 
        Object index must exceed or equal to 0 and be less than ObjectsTotal(). 

Sample:

  int    obj_total=ObjectsTotal();
  string name;
  for(int i=0;i<obj_total;i++)
    {
     name=ObjectName(i);
     Print(i,"Object name is " + name);
    }

ObjectsDeleteAll()

int ObjectsDeleteAll(int window=EMPTY, int type=EMPTY)

Removes all objects of the specified type and in the specified sub-window of the chart. The function returns the count of removed objects. To get the detailed error information, one has to call the GetLastError() function.

Notes: The chart sub-windows (if there are sub-windows with indicators in the chart) are numbered starting from 1. The chart main window always exists and has the 0 index. If the window index is missing or it has the value of -1, the objects will be removed from the entire chart.

If the type value equals to -1 or this parameter is missing, all objects will be removed from the specified sub-window.

Parameters:

window - Optional parameter. 
         Index of the window in which the objects will be deleted. 
         Must exceed or equal to -1 (EMPTY, the default value) and be less than WindowsTotal(). 
type   - Optional parameter. 
         An object type to be deleted. 
         It can be any of the Object type enumeration values or EMPTY constant to delete all objects with any types. 

Sample:

  ObjectsDeleteAll(2, OBJ_HLINE); // all horizontal lines are removed from the 2nd sub-window.
  ObjectsDeleteAll(2);            // all objects are removed from the 2nd sub-window.
  ObjectsDeleteAll();             // all objects are removed from the chart.

ObjectSetText()

bool ObjectSetText(string name, string text, int font_size, 
                   string font=NULL, color text_color=CLR_NONE)

Changes the object description. For objects of OBJ_TEXT and OBJ_LABEL, this description is shown as a text line in the chart. If the function succeeds, the returned value will be TRUE. Otherwise, it is FALSE. To get the detailed error information, one has to call the GetLastError() function.

Parameters of font_size, font_name and text_color are used for objects of OBJ_TEXT and OBJ_LABEL only. For objects of other types, these parameters are ignored.

See also ObjectDescription() function.

Parameters:

name       - Object name. 
text       - A text describing the object. 
font_size  - Font size in points. 
font       - Font name. 
text_color - Text color. 

Sample:

ObjectSetText("text_object", "Hello world!", 10, "Times New Roman", Green);

ObjectsTotal()

int ObjectsTotal(int type=EMPTY)

Returns total amount of objects of the specified type in the chart.

Parameters:

type - Optional parameter. An object type to be counted. 
       It can be any of the Object type enumeration values or 
       EMPTY constant to count all objects with any types. 

Sample:

  int    obj_total=ObjectsTotal();
  string name;
  for(int i=0;i<obj_total;i++)
    {
     name=ObjectName(i);
     Print(i,"Object name for object #",i," is " + name);
    }

ObjectType()

int ObjectType(string name)

The function returns the object type value. To get the detailed error information, one has to call the GetLastError() function.

Parameters:

name - Object name. 

Sample:

if(ObjectType("line_object2")!=OBJ_HLINE) return(0);

MQL4 Object functions (1)

A group of functions intended for working with graphical objects related to the current chart.

 

ObjectCreate()

bool ObjectCreate(string name, int type, int window, 
                  datetime time1, double price1, 
                  datetime time2=0, double price2=0, 
                  datetime time3=0, double price3=0)

Creation of an object with the specified name, type and initial coordinates in the specified window. Count of coordinates related to the object can be from 1 to 3 depending on the object type. If the function succeeds, the returned value will be TRUE. Otherwise, it will be FALSE. To get the detailed error information, one has to call the GetLastError() function. Objects of the OBJ_LABEL type ignore the coordinates. Use the function of ObjectSet() to set up the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.

Notes: The chart sub-windows (if there are sub-windows with indicators in the chart) are numbered starting from 1. The chart main window always exists and has the 0 index.

Coordinates must be passed in pairs: time and price. For example, the OBJ_VLINE object needs only time, but price (any value) must be passed, as well.

Parameters:

name   - Object unique name. 
type   - Object type. It can be any of the Object type enumeration values. 
window - Index of the window where the object will be added. Window index must exceed or equal to 0 and be less than WindowsTotal(). 
time1  - Time part of the first point. 
price1 - Price part of the first point. 
time2  - Time part of the second point. 
price2 - Price part of the second point. 
time3  - Time part of the third point. 
price3 - Price part of the third point. 

Sample:

  // new text object
  if(!ObjectCreate("text_object", OBJ_TEXT, 0, D'2004.02.20 12:30', 1.0045))
    {
     Print("error: can't create text_object! code #",GetLastError());
     return(0);
    }
  // new label object
  if(!ObjectCreate("label_object", OBJ_LABEL, 0, 0, 0))
    {
     Print("error: can't create label_object! code #",GetLastError());
     return(0);
    }
  ObjectSet("label_object", OBJPROP_XDISTANCE, 200);
  ObjectSet("label_object", OBJPROP_YDISTANCE, 100);

ObjectDelete()

bool ObjectDelete(string name)

Deletes object having the specified name. If the function succeeds, the returned value will be TRUE. Otherwise, it will be FALSE.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

name - Name of the object to be deleted.  

Sample:

ObjectDelete("text_object");

ObjectDescription()

string ObjectDescription(string name)

Return object description. For objects of OBJ_TEXT and OBJ_LABEL types, the text drawn by these objects will be returned.

To get the detailed error information, one has to call the GetLastError() function.

See also ObjectSetText() function.

Parameters:

name - Object name.  

Sample:

  // writing the chart objects list to the file
  int    handle, total;
  string obj_name,fname;
  // file name
  fname="objlist_"+Symbol();
  handle=FileOpen(fname,FILE_CSV|FILE_WRITE);
  if(handle!=false)
    {
     total=ObjectsTotal();
     for(int i=-;i<total;i++)
       {
        obj_name=ObjectName(i);
        FileWrite(handle,"Object "+obj_name+" description= "+ObjectDescription(obj_name));
       }
     FileClose(handle);
    }

ObjectFind()

int ObjectFind(string name)

Search for an object having the specified name. The function returns index of the windows that contains the object to be found. If it fails, the returned value will be -1. To get the detailed error information, one has to call the GetLastError() function. The chart sub-windows (if there are sub-windows with indicators in the chart) are numbered starting from 1. The chart main window always exists and has the 0 index.

Parameters:

name - Object name to search for.

Sample:

if(ObjectFind("line_object2")!=win_idx) return(0);

ObjectGet()

double ObjectGet(string name, int index)

The function returns the value of the specified object property. To check errors, one has to call the GetLastError() function.

See also ObjectSet() function.

Parameters:

name  - Object name. 
index - Object property index. It can be any of the Object properties enumeration values. 

Sample:

color oldColor=ObjectGet("hline12", OBJPROP_COLOR);

ObjectSet()

bool ObjectSet(string name, int index, double value)

Changes the value of the specified object property. If the function succeeds, the returned value will be TRUE. Otherwise, it will be FALSE. To get the detailed error information, one has to call the GetLastError() function.

See also ObjectGet() function.

Parameters:

name  - Object name. 
index - Object property index. It can be any of the Object properties enumeration values. 
value - New value of the given property. 

Sample:

  // moving the first coord to the last bar time
  ObjectSet("MyTrend", OBJPROP_TIME1, Time[0]);
  // setting the second fibo level
  ObjectSet("MyFibo", OBJPROP_FIRSTLEVEL+1, 1.234);
  // setting object visibility. object will be shown only on 15 minute and 1 hour charts
  ObjectSet("MyObject", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15 | OBJ_PERIOD_H1);

ObjectGetFiboDescription()

string ObjectGetFiboDescription(string name, int index)

The function returns the level description of a Fibonacci object. The amount of Fibonacci levels depends on the object type. The maximum amount of Fibonacci levels is 32.

To get the detailed error information, one has to call the GetLastError() function.

See also ObjectSetFiboDescription() function.

Parameters:

name  - Fibonacci object name. 
index - Index of the Fibonacci level (0-31). 

Sample:

#include <stdlib.mqh>
  ...
  string text;
  for(int i=0;i<32;i++)
    {
     text=ObjectGetFiboDescription(MyObjectName,i);
     //---- checking whether the objects has less than 32 levels
     if(GetLastError()!=ERR_NO_ERROR) break;
     Print(MyObjectName,"level: ",i," description: ",text);
    }

ObjectSetFiboDescription()

bool ObjectSetFiboDescription(string name, int index, string text)

The function assigns a new description to a level of a Fibonacci object. The amount of Fibonacci levels depends on the object type. The maximum amount of Fibonacci levels is 32.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

name  - Object name. 
index - Index of the Fibonacci level (0-31). 
text  - New description of the level. 

Sample:

ObjectSetFiboDescription("MyFiboObject",2,"Second line");

MQL4 Math & Trig (2)

A set of mathematical and trigonometric functions.

 

MathMax()

double MathMax(double value1, double value2)

Returns the maximum value of two numeric values.

Parameters:

value1 - The first numeric value. 
value2 - The second numeric value. 

Sample:

  double result=MathMax(1.08,Bid);

MathMin()

double MathMin(double value1, double value2)

Returns the minimum value of two numeric values.

Parameters:

value1 - The first numeric value. 
value2 - The second numeric value. 

Sample:

  double result=MathMin(1.08,Ask);

MathMod()

double MathMod(double value, double value2)

The function returns the floating-point remainder of division of two numbers.

The MathMod function calculates the floating-point remainder f of x / y such that x = i * y + f , where i is an integer, f has the same sign as x, and the absolute value of f is less than the absolute value of y.

Parameters:

value  - Dividend value. 
value2 - Divisor value. 

Sample:

  double x=-10.0,y=3.0,z;
  z=MathMod(x,y);
  Print("The remainder of ",x," / ",y," is ",z);
  //Output: The remainder of -10 / 3 is -1

MathPow()

double MathPow(double base, double exponent)

Returns the value of the base expression raised to the specified power (exponent value).

Parameters:

base  - Base value. 
exponent - Exponent value. 

Sample:

  double x=2.0,y=3.0,z;
  z=MathPow(x,y);
  Printf(x," to the power of ",y," is ", z);
  //Output: 2 to the power of 3 is 8

MathRand()

int MathRand()

The MathRand function returns a pseudorandom integer within the range of 0 to 32767. The MathSrand function must be used to seed the pseudorandom-number generator before calling MathRand.

Sample:

  MathSrand(TimeLocal());
  // Display 10 numbers.
  for(int i=0;i<10;i++ )
    Print("random value ", MathRand());

MathRound()

double MathRound(double value)

Returns value rounded to the nearest integer of the specified numeric value.

Parameters:

value - Numeric value to be rounded. 

Sample:

  double y=MathRound(2.8);
  Print("The round of 2.8 is ",y);
  y=MathRound(2.4);
  Print("The round of -2.4 is ",y);
  //Output: The round of 2.8 is 3
  //        The round of -2.4 is -2

MathSin()

double MathSin(double value)

Returns the sine of the specified angle.

Parameters:

value - An angle measured in radians. 

Sample:

  double pi=3.1415926535;
  double x, y;
  x=pi/2;
  y=MathSin(x);
  Print("MathSin(",x,") = ",y);
  y=MathCos(x);
  Print("MathCos(",x,") = ",y);
  //Output: MathSin(1.5708)=1
  //        MathCos(1.5708)=0

MathSqrt()

double MathSqrt(double x)

The MathSqrt function returns the square root of x. If x is negative, MathSqrt returns an indefinite (same as a quiet NaN).

Parameters:

x - Positive numeric value. 

Sample:

  double question=45.35, answer;
  answer=MathSqrt(question);
  if(question<0)
    Print("Error: MathSqrt returns ",answer," answer");
  else
    Print("The square root of ",question," is ", answer);
  //Output: The square root of 45.35 is 6.73

MathSrand()

void MathSrand(int seed)

The MathSrand() function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point. MathRand retrieves the pseudorandom numbers that are generated. Calling MathRand before any call to MathSrand generates the same sequence as calling MathSrand with seed passed as 1.

Parameters:

seed - Seed for random-number generation. 

Sample:

  MathSrand(TimeLocal());
  // Display 10 numbers.
  for(int i=0;i<10;i++ )
    Print("random value ", MathRand());

MathTan()

double MathTan(double x)

MathTan returns the tangent of x. If x is greater than or equal to 263, or less than or equal to -263, a loss of significance in the result occurs, in which case the function returns an indefinite (same as a quiet NaN).

Parameters:

x - Angle in radians. 

Sample:

  double pi=3.1415926535;
  double x,y;
  x=MathTan(pi/4);
  Print("MathTan(",pi/4," = ",x);
  //Output: MathTan(0.7856)=1

MQL4 Math & Trig (1)

A set of mathematical and trigonometric functions.

 

MathAbs()

double MathAbs(double value)

Returns the absolute value (modulus) of the specified numeric value.

Parameters:

value - Numeric value. 

Sample:

  double dx=-3.141593, dy;
  // calc MathAbs
  dy=MathAbs(dx);
  Print("The absolute value of ",dx," is ",dy);
  // Output: The absolute value of -3.141593 is 3.141593

MathArccos()

double MathArccos(double x)

The MathArccos function returns the arccosine of x within the range 0 to π (in radians). If x is less than -1 or exceeds 1, the MathArccos returns NaN (indeterminate value).

Parameters:

x - Value between -1 and 1 the arccosine of which to be calculated. 

Sample:

  double x=0.32696, y;
  y=asin(x);
  Print("Arcsine of ",x," = ",y);
  y=acos(x);
  Print("Arccosine of ",x," = ",y);
  //Output: Arcsine   of 0.326960=0.333085
  //Output: Arccosine of 0.326960=1.237711

MathArcsin()

double MathArcsin(double x)

The MathArcsin function returns the arcsine of x in the range -π/2 to π/2 radians. If x is less than -1 or exceeds 1, the arcsine returns NaN (indeterminate value).

Parameters:

x - Value the arcsine of which to be calculated. 

Sample:

  double x=0.32696, y;
  y=MathArcsin(x);
  Print("Arcsine of ",x," = ",y);
  y=acos(x);
  Print("Arccosine of ",x," = ",y);
  //Output: Arcsine   of 0.326960=0.333085
  //Output: Arccosine of 0.326960=1.237711

MathArctan()

double MathArctan(double x)

The MathArctan returns the arctangent of x. If x is 0, MathArctan returns 0. MathArctan returns a value within the range of -π/2 to π/2 radians.

Parameters:

x - A number representing a tangent. 

Sample:

  double x=-862.42, y;
  y=MathArctan(x);
  Print("Arctangent of ",x," is ",y);
  //Output: Arctangent of -862.42 is -1.5696

MathCeil()

double MathCeil(double x)

The MathCeil function returns a numeric value representing the smallest integer that exceeds or equals to x.

Parameters:

x - Numeric value. 

Sample:

  double y;
  y=MathCeil(2.8);
  Print("The ceil of 2.8 is ",y);
  y=MathCeil(-2.8);
  Print("The ceil of -2.8 is ",y);
  /*Output:
    The ceil of 2.8 is 3
    The ceil of -2.8 is -2*/

MathCos()

double MathCos(double value)

Returns the cosine of the specified angle.

Parameters:

value - An angle measured in radians. 

Sample:

  double pi=3.1415926535;
  double x, y;
  x=pi/2;
  y=MathSin(x);
  Print("MathSin(",x,") = ",y);
  y=MathCos(x);
  Print("MathCos(",x,") = ",y);
  //Output: MathSin(1.5708)=1
  //        MathCos(1.5708)=0

MathExp()

double MathExp(double d)

Returns the value of e raised to the power of d. At overflow, the function returns INF (infinity), and it returns 0 at underflow.

Parameters:

d - A number specifying the power. 

Sample:

  double x=2.302585093,y;
  y=MathExp(x);
  Print("MathExp(",x,") = ",y);
  //Output: MathExp(2.3026)=10

MathFloor()

double MathFloor(double x)

The MathFloor function returns a numeric value representing the largest integer that is less than or equal to x.

Parameters:

x - Numeric value. 

Sample:

  double y;
  y=MathFloor(2.8);
  Print("The floor of 2.8 is ",y);
  y=MathFloor(-2.8);
  Print("The floor of -2.8 is ",y);
  /*Output:
    The floor of 2.8 is 2
    The floor of -2.8 is -3*/

MathLog()

double MathLog(double x)

The MathLog function returns the natural logarithm of x if successful. If x is negative, these functions return NaN (indeterminate value). If x is 0, they return INF (infinity).

Parameters:

x - Value logarithm of which to be found. 

Sample:

  double x=9000.0,y;
  y=MathLog(x);
  Print("MathLog(",x,") = ", y);
  //Output: MathLog(9000)=9.10498

MQL4 Global variables

A group of functions intended for working with global variables.

Global variables of the client terminal should not be mixed up with variables declared in the global scope of the MQL4 program.

Global variables are kept in the client terminal within 4 weeks since the last access, then they will be deleted automatically. An access to a global variable is not only setting of a new value, but reading of the global variable value, as well.

Global variables of the client terminal are accessible simultaneously from all MQL4 programs launched in the client terminal.

 

GlobalVariableCheck()

bool GlobalVariableCheck(string name)

Returns TRUE if the global variable exists, otherwise, returns FALSE.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

name - Global variable name. 

Sample:

  // check variable before use
  if(!GlobalVariableCheck("g1"))
    GlobalVariableSet("g1",1);

GlobalVariableDel()

bool GlobalVariableDel(string name)

Deletes the global variable. If the function succeeds, the returned value will be TRUE, otherwise, it will be FALSE.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

name - Global variable name. 

Sample:

  // deleting of the global variable named "gvar_1"
  GlobalVariableDel("gvar_1");

GlobalVariableGet()

double GlobalVariableGet(string name)

Returns the value of an existing global variable or 0 if an error occurs.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

name - Global variable name. 

Sample:

  double v1=GlobalVariableGet("g1");
  //---- check function call result
  if(GetLastError()!=0) return(false);
  //---- continue processing

GlobalVariableName()

string GlobalVariableName(int index)

The function returns the name of a global variable by its index in the list of global variables.

To get the detailed error information, one has to call the GetLastError().

Parameters:

index - Index in the list of global variables. 
        It must exceed or be equal to 0 and be less than GlobalVariablesTotal(). 

Sample:

  int    var_total=GlobalVariablesTotal();
  string name;
  for(int i=0;i<var_total;i++)
    {
     name=GlobalVariableName(i);
     Print(i,": Global variable name - ",name);
    }

GlobalVariableSet()

datetime GlobalVariableSet(string name, double value)

Sets a new value of the global variable. If it does not exist, the system creates a new gloabl variable. If the function succeeds, the returned value will be the last access time. Otherwise, the returned value will be 0.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

name  - Global variable name. 
value - The new numeric value. 

Sample:

  //---- try to set new value
  if(GlobalVariableSet("BarsTotal",Bars)==0)
    return(false);
  //---- continue processing

GlobalVariableSetOnCondition()

bool GlobalVariableSetOnCondition(string name, 
                                  double value, 
                                  double check_value)

Sets the new value of the existing global variable if the current value equals to the third parameter check_value. If there is no global variable, the function will generate error ERR_GLOBAL_VARIABLE_NOT_FOUND (4058) and return FALSE. When successfully executed, the function returns TRUE, otherwise, it returns FALSE.

To get the detailed error information, one has to call the GetLastError() function.

If the current value of the global variable differs from the check_value, the function will return FALSE.

The function provides atomic access to the global variable, this is why it can be used for providing of a semaphore at interaction of several experts working simultaneously within one client terminal.

Parameters:

name        - Global variable name. 
value       - New value. 
check_value - Value to be compared to the current global variable value. 

Sample:

  int init()
    {
     //---- create global variable
     GlobalVariableSet("DATAFILE_SEM",0);
     //...
    }
  
  int start()
    {
     //---- try to lock common resource
     while(!IsStopped())
       {
        //---- locking
        if(GlobalVariableSetOnCondition("DATAFILE_SEM",1,0)==true)  break;
        //---- may the variable be deleted?
        if(GetLastError()==ERR_GLOBAL_VARIABLE_NOT_FOUND) return(0);
        //---- sleeping
        Sleep(500);
       }
     //---- resource locked
     // ... do some work
     //---- unlock resource
     GlobalVariableSet("DATAFILE_SEM",0);
    }

GlobalVariablesDeleteAll()

int GlobalVariableSet(string prefix_name=NULL)

Deletes global variables. If the name prefix is not specified, all global variables will be deleted. Otherwise, only those variables will be deleted, the names of which begin with the specified prefix. The function returns the count of deleted variables.

Parameters:

prefix_name - Name prefix of the global variables to be deleted. 

Sample:

Print(GlobalVariablesDeleteAll("test_")," test globals deleted");

GlobalVariablesTotal()

int GlobalVariablesTotal()

The function returns the total count of global variables.

Sample:

Print(GlobalVariablesTotal()," global variables detected");

MQL4 File functions (3)

A group of functions for working with files.

There are three directories (with subdirectories) where working files can be placed:

  • /HISTORY/<current broker> – especially for the FileOpenHistory function;
  • /EXPERTS/FILES – common case;
  • /TESTER/FILES – especially for testing.

Working with files from other directories is prohibited.

 

FileSize()

int FileSize(int handle)

The function returns file size in bytes. To get the detailed error information, one has to call the GetLastError() function.

Parameters:

handle - File handle returned by the FileOpen() function.  

Sample:

  int handle;
  int size;
  handle=FileOpen("my_table.dat", FILE_BIN|FILE_READ);
  if(handle>0)
    {
     size=FileSize(handle);
     Print("my_table.dat size is ", size, " bytes");
     FileClose(handle);
    }

FileTell()

int FileTell(int handle)

Returns the current position of the file pointer. To get the detailed error information, one has to call GetLastError() function.

Parameters:

handle - File handle returned by the FileOpen() function.  

Sample:

  int handle;
  int pos;
  handle=FileOpen("my_table.dat", FILE_BIN|FILE_READ);
  // reading some data
  pos=FileTell(handle);
  Print("current position is ", pos);

FileWrite()

int FileWrite(int handle, ...)

The function is intended for writing of data into a CSV file, delimiter being inserted automatically. After writing into the file, the line end character "\r\n" will be added. Numbers will be converted into a text at output (see the Print() function).

Returns the count of written characters or a negative number if an error occurs.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

handle - File handle returned by the FileOpen() function.  
...    - User data to write, separated by commas. It can be up to 63 parameters.
         Data of int and double types are automatically converted into a string, 
         but those of color, datetime and bool typesare not automatically converted 
         and will be written to file as they are (as integers).
         Arrays cannot be passed as a parameter, they can be output elementwise. 

Sample:

  int handle;
  datetime orderOpen=OrderOpenTime();
  handle=FileOpen("filename", FILE_CSV|FILE_WRITE, ';');
  if(handle>0)
    {
     FileWrite(handle, Close[0], Open[0], High[0], Low[0], TimeToStr(orderOpen));
     FileClose(handle);
    }

FileWriteArray()

int FileWriteArray(int handle, object array[], int start, int count)

The function writes the array to a binary file. Arrays of int, bool, datetime and color types will be written elementwise, as 4-bytes integers. Arrays of double type will be written elementwise, as 8-bytes floating point numbers. Arrays of string type will be written by strings, the line end character "\r\n" to be added at each string automatically.

Returns the number of written elements or a negative value if an error occurs.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

handle  - File handle returned by the FileOpen() function.  
array[] - Array to write. 
start   - Starting index in the array (the first written element number). 
count   - Count of elements to be written. 

Sample:

  int handle;
  double BarOpenValues[10];
  // copy first ten bars to the array
  for(int i=0;i<10; i++)
    BarOpenValues[i]=Open[i];
  // writing array to the file
  handle=FileOpen("mydata.dat", FILE_BIN|FILE_WRITE);
  if(handle>0)
    {
     FileWriteArray(handle, BarOpenValues, 3, 7); // writing last 7 elements
     FileClose(handle);
    }

FileWriteDouble()

int FileWriteDouble(int handle, double value, int size=DOUBLE_VALUE)

The function writes a double value with floating point to a binary file. If the format is specified as FLOAT_VALUE, the value will be written as a 4-bytes floating point number (of the float type), otherwise, it will be written in the 8-bytes floating point format (of the double type).

Returns the actually written bytes count or a negative value if an error occurs.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

handle - File handle returned by the FileOpen() function.  
value  - Double precision value. 
size   - Optional format flag. It can be any of the following values:
         DOUBLE_VALUE (8 bytes, default)
         FLOAT_VALUE (4 bytes). 

Sample:

  int handle;
  double var1=0.345;
  handle=FileOpen("mydata.dat", FILE_BIN|FILE_WRITE);
  if(handle<1)
    {
     Print("can't open file error-",GetLastError());
     return(0);
    }
  FileWriteDouble(h1, var1, DOUBLE_VALUE);
  //...
  FileClose(handle);

FileWriteInteger()

int FileWriteInteger(int handle, int value, int size=LONG_VALUE)

The function writes the integer value to a binary file. If the size is SHORT_VALUE, the value will be written as a 2-byte integer (the short type), if the size is CHAR_VALUE, the value will be written as a 1-byte integer (the char type), and if the size is LONG_VALUE, the value will be written as a 4-byte integer (the long int type).

Returns the actually written bytes count or a negative value if an error occurs.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

handle - File handle returned by the FileOpen() function.  
value  - Value to be written. 
size   - Optional format flag. It can be any of the following values:
         CHAR_VALUE (1 byte),
         SHORT_VALUE (2 bytes),
         LONG_VALUE (4 bytes, default). 

Sample:

  int handle;
  int value=10;
  handle=FileOpen("filename.dat", FILE_BIN|FILE_WRITE);
  if(handle<1)
    {
     Print("can't open file error-",GetLastError());
     return(0);
    }
  FileWriteInteger(handle, value, SHORT_VALUE);
  //...
  FileClose(handle);

FileWriteString()

int FileWriteString(int handle, string value, int length)

The function writes the string to a binary file from the current file position.

Returns the actually written bytes count or a negative value if an error occurs.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

handle - File handle returned by the FileOpen() function.  
value  - String to be written. 
length - The length of the string to be written. 
         If the string length exceeds the given value, it will be truncated. 
         If it is shorter, it will be extended by binary 0s up to the given length. 

Sample:

  int handle;
  string str="some string";
  handle=FileOpen("filename.bin", FILE_BIN|FILE_WRITE);
    if(handle<1)
    {
     Print("can't open file error-",GetLastError());
     return(0);
    }
  FileWriteString(handle, str, 8);
  FileClose(handle);

MQL4 File functions (2)

A group of functions for working with files.

There are three directories (with subdirectories) where working files can be placed:

  • /HISTORY/<current broker> – especially for the FileOpenHistory function;
  • /EXPERTS/FILES – common case;
  • /TESTER/FILES – especially for testing.

Working with files from other directories is prohibited.

 

FileOpenHistory()

int FileOpenHistory(string filename, int mode, int delimiter=';')

Opens file in the current history directory (terminal_directory\history\server_name) or in its subfolders. Returns the file handle for the opened file. If the function fails, the returned value is -1. To get the detailed error information, call the GetLastError() function.

Notes: Client terminal can connect to servers of different brokerage companies. History data (HST files) for each brokerage company are stored in the corresponding subfolder of the terminal_directory\history folder.

The function can be useful to form own history data for a non-standard symbol and/or period. The file formed in the history folder can be opened offline, not data pumping is needed to chart it.

Parameters:

filename  - Filename. 
mode      - Opening mode. Can be one or combination of values: 
            FILE_BIN, FILE_CSV, FILE_READ, FILE_WRITE. 
delimiter - Delimiter for csv files. 
            By default, the ';' symbol will be passed. 

Sample:

  int handle=FileOpenHistory("USDX240.HST",FILE_BIN|FILE_WRITE);
  if(handle<1)
    {
     Print("Cannot create file USDX240.HST");
     return(false);
    }
  // work with file
  // ...
  FileClose(handle);

FileReadArray()

int FileReadArray(int handle, object&array[], int start, int count)

Reads the specified amount of elements from the binary file into array. Before reading, make sure that the array is large enough. Returns the amount of actually read elements.

To get the detailed error information, call the GetLastError() function.

Parameters:

handle  - File handle returned by the FileOpen() function. 
array[] - Array where data will be stored. 
start   - Starting position for storing in array. 
count   - Count of elements to be read. 

Sample:

  int handle;
  double varray[10];
  handle=FileOpen("filename.dat", FILE_BIN|FILE_READ);
  if(handle>0)
    {
     FileReadArray(handle, varray, 0, 10);
     FileClose(handle);
    }

FileReadDouble()

double FileReadDouble(int handle, int size=DOUBLE_VALUE)

Reads the double-precision number with floating point from the current binary file position. The number format size can be 8 bytes (double) or 4 bytes (float).

To get the error information, one has to call the GetLastError() function.

Parameters:

handle - File handle returned by the FileOpen() function. 
size   - Number format size. Can be DOUBLE_VALUE(8 bytes) or FLOAT_VALUE(4 bytes). 

Sample:

  int handle;
  double value;
  handle=FileOpen("mydata.dat",FILE_BIN);
  if(handle>0)
    {
     value=FileReadDouble(handle,DOUBLE_VALUE);
     FileClose(handle);
    }

FileReadInteger()

int FileReadInteger(int handle, int size=LONG_VALUE)

The function reads the integer from the current binary file position. The integer format size can be 1, 2 or 4 bytes. If the format size is not specified, the system tries to read the 4-bytes value.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

handle - File handle returned by the FileOpen() function. 
size   - Format size. Can be CHAR_VALUE(1 byte), SHORT_VALUE(2 bytes) or LONG_VALUE(4 bytes). 

Sample:

  int handle;
  int value;
  handle=FileOpen("mydata.dat", FILE_BIN|FILE_READ);
  if(handle>0)
    {
     value=FileReadInteger(h1,2);
     FileClose(handle);
    }

FileReadNumber()

double FileReadNumber(int handle)

Read the number from the current file position before the delimiter. Only for CSV files.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

handle - File handle returned by the FileOpen() function.  

Sample:

  int handle;
  int value;
  handle=FileOpen("filename.csv", FILE_CSV, ';');
  if(handle>0)
    {
     value=FileReadNumber(handle);
     FileClose(handle);
    }

FileReadString()

string FileReadString(int handle, int length=0)

The function reads the string from the current file position. Applies to both CSV and binary files. For text files, the string will be read before the delimiter. For binary file, the given count of characters will be read to the string.

To get the detailed error information, one has to call the GetLastError() function.

Parameters:

handle - File handle returned by the FileOpen() function. 
length - Amount of characters for reading. 

Sample:

  int handle;
  string str;
  handle=FileOpen("filename.csv", FILE_CSV|FILE_READ);
  if(handle>0)
    {
     str=FileReadString(handle);
     FileClose(handle);
    }

FileSeek()

bool FileSeek(int handle, int offset, int origin)

The function moves the file pointer to a new position that is an offset, in bytes, from the beginning, the end or the current file position. The next reading or writing are made at a new position.

If file pointer has been moved successfully, the function returns TRUE, otherwise, it returns FALSE. To get the detailed error information, one has to call the GetLastError() function.

Parameters:

handle - File handle returned by the FileOpen() functions. 
offset - Offset, in bytes, from origin. 
origin - Initial position. Value can be one of the following constants:
         SEEK_CUR - from current position,
         SEEK_SET - from begin,
         SEEK_END - from end of file. 

Sample:

  int handle=FileOpen("filename.csv", FILE_CSV|FILE_READ|FILE_WRITE, ';');
  if(handle>0)
    {
     FileSeek(handle, 0, SEEK_END);
     //---- add data to the end of file
     FileWrite(handle, data1, data2);
     FileClose(handle);
     handle=0;
    }

MQL4 File functions (1)

A group of functions for working with files.

There are three directories (with subdirectories) where working files can be placed:

  • /HISTORY/<current broker> – especially for the FileOpenHistory function;
  • /EXPERTS/FILES – common case;
  • /TESTER/FILES – especially for testing.

Working with files from other directories is prohibited.

 

FileClose()

void FileClose(int handle)

Closes file previously opened by the FileOpen() function.

Parameters:

handle - File handle returned by the FileOpen() function.

Sample:

  int handle=FileOpen("filename", FILE_CSV|FILE_READ);
  if(handle>0)
    {
     // working with file ...
     FileClose(handle);
    }

FileDelete()

void FileDelete(string filename)

Removes specified file name. To get the detailed error information, call GetLastError().

Files can only be deleted if they are in the terminal_dir\experts\files directory (terminal_directory\tester\files, in case of testing) or its subdirectories.

Parameters:

filename - Path to the file.

Sample:

  // file my_table.csv will be deleted from terminal_dir\experts\files directory
  int lastError;
  FileDelete("my_table.csv");
  lastError=GetLastError();
  if(laseError!=ERR_NOERROR)
    {
     Print("An error ocurred while (",lastError,") deleting file my_table.csv");
     return(0);
    }

FileFlush()

void FileFlush(int handle)

Flushes all data stored in the file buffer to the disk.

Notes: The FileFlush() function must be called between operations of file reading and writing in the file.

At file closing, the data are flushed to the disk automatically, so there is no need to call the FileFlush() function before calling of the FileClose() function.

Parameters:

handle - File handle returned by the FileOpen() function.

Sample:

  int bars_count=Bars;
  int handle=FileOpen("mydat.csv",FILE_CSV|FILE_WRITE);
  if(handle>0)
    {
     FileWrite(handle, "#","OPEN","CLOSE","HIGH","LOW");
     for(int i=0;i<bars_count;i++)
       FileWrite(handle, i+1,Open[i],Close[i],High[i], Low[i]);
     FileFlush(handle);
     ...
     for(int i=0;i<bars_count;i++)
       FileWrite(handle, i+1,Open[i],Close[i],High[i], Low[i]);
     FileClose(handle);
    }

FileIsEnding()

bool FileIsEnding(int handle)

Returns logical true if file pointer is at the end of the file, otherwise returns false. To get the detailed error information, call GetLastError() function. If the file end is reached during reading, the GetLastError() function will return error ERR_END_OF_FILE (4099).

Parameters:

handle - File handle returned by the FileOpen() function.

Sample:

  if(FileIsEnding(h1))
    {
     FileClose(h1);
     return(false);
    }

FileIsLineEnding()

bool FileIsLineEnding(int handle)

For CSV file returns logical true if file pointer is at the end of the line, otherwise returns false. To get the detailed error information, call GetLastError() function.

Parameters:

handle - File handle returned by the FileOpen() function.

Sample:

  if(FileIsLineEnding(h1))
    {
     FileClose(h1);
     return(false);
    }

FileOpen()

int FileOpen(string filename, int mode, int delimiter=';')

Opens file for input and/or output. Returns a file handle for the opened file or -1 (if the function fails). To get the detailed error information, call GetLastError() function.

Notes: Files can only be opened in the terminal_directory\experts\files folder (terminal_directory\tester\files if for expert testing) or in its subfolders.

FILE_BIN and FILE_CSV modes cannot be used simultaneously.

If FILE_WRITE does not combine with FILE_READ, a zero-length file will be opened. If even the file containd some data, they will be deleted. If there is a need to add data to an existing file, it must be opened using combination of FILE_READ | FILE_WRITE.

If FILE_READ does not combine with FILE_WRITE, the file will be opened only if it already exists. If the file does not exist, it can be created using the FILE_WRITE mode.

No more than 32 files can be opened within an executable module simultaneously. Handles of files opened in the same module cannot be passed to other modules (libraries).

Parameters:

filename  - Filename. 
mode      - Opening mode. It can be one or combination of values: 
            FILE_BIN, FILE_CSV, FILE_READ, FILE_WRITE. 
delimiter - Delimiter character for csv files. 
            By default, the ';' symbol applies. 

Sample:

  int handle;
  handle=FileOpen("my_data.csv",FILE_CSV|FILE_READ,';');
  if(handle<1)
    {
     Print("File my_data.dat not found, the last error is ", GetLastError());
     return(false);
    }
第 1 页,共 7 页12345...最旧 »
menu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loader