Skip to content
kabirsandhu edited this page Jun 20, 2016 · 1 revision

Helper API

The Helper API provides many different helper methods to use. Char to string, Information on time, etc.

GetLastError
IsConnected
IsDllsAllowed
IsExpertEnabled
IsLibrariesAllowed
IsOptimization
IsStopped
IsTesting
IsTradeContextBusy
IsVisualMode
UnintializeReason
Alert
Comment
GetTickCount
MarketInfo
MessageBox
PlaySound
Print
SendFTP
SendMail
SendNotification
Sleep
CharToStr
DoubleToStr
NormalizeDouble
StrToDouble
StrToInteger
StrToTime
TimeToStr
Day
DayOfWeek
DayOfYear
Hour
Minute
Seconds
TimeCurrent
TimeDay
TimeDayOfWeek
TimeDayOfYear
TimeHour
TimeLocal
TimeMinute
TimeMonth
TimeSeconds
TimeYear
Year
CompareString
MathAbs
MathArccos
MathArcsin
MathArctan
MathCeil
MathCos
MathExp
MathFloor
MathLog
MathMax
MathMin
MathMod
MathPow
MathRand
MathRound
MathSin
MathSqrt
MathSrand
MathTan
StringConcatenate
StringFind
StringGetChar
StringLen
StringSetChar
StringSubstr
StringTrimLeft
Stringtrimright
TerminalCompany
TerminalName
TerminalPath
HideTestIndicators
Period
RefreshRates
Symbol
WindowBarsPerChart
WindowExpertName
WindowsFind
WindowFirstVisibleBar
WindowHandle
WindowIsVisible
WindowPriceMax
WindowPriceMin
WindowRedraw
WindowScreenshot
WindowsTotal

GetLastError

Get integer code of the last error and set last error value to 0.

protected int GetLastError()

Returns

  • Integer code of the last error

IsConnected

Return whether or not Data Provide is connected

protected bool IsConnected()

Returns

  • It returns true if connection to the server was successfully established, otherwise, it returns false.

IsDllsAllowed

Determinate ability to use external DLL`s. We don't support external DLL's

protected bool IsDllsAllowed()

Returns

  • Returns true if the DLL function call is allowed, otherwise returns false

IsExpertEnabled

Determinate is there Expert advisors on chart

protected bool IsExpertEnabled()

Returns

  • Returns true if Expert Advisors are enabled for running, otherwise returns false.

IsLibrariesAllowed

Determinate ability to use external libraries. We don't support external libraries

protected bool IsLibrariesAllowed()

Returns

  • Returns true if library function call is allowed, otherwise returns false

IsOptimization

Determine is there optimization mode using. Not supported, false in any cases

protected bool IsOptimization()

Returns

  • false

IsStopped

Determine if EA is stopped

protected bool IsStopped()

Returns

  • Returns true if EA is stopped, otherwise returns false

IsTesting

Used in Strategy testing, TRUE if EA running in Strategy test. Not supported, false in any cases

protected bool IsTesting()

Returns

  • false

IsTradeContextBusy

Can user trade now. Not supported, false in any cases

protected bool IsTradeContextBusy()

Returns

  • false

IsVisualMode

Used in Strategies testing, and show Strategies Test on chart. Not supported, false in any cases

protected bool IsVisualMode()

Returns

  • false

UnintializeReason

Return integer code of uninitializing reason

protected int UninitializeReason()

Returns

  • integer code of uninitializing reason

Alert

Show alert windows with new and old alerts

protected void Alert(params object[] values)

Parameters

  • values - Values that will be concatenated and showed as alert message

Comment

Show label on chart in top-left corner

protected void Comment(params object[] vals)

Parameters

  • vals - Values that will be concatenated and showed as comment

GetTickCount

Get the number of milliseconds elapsed since the system started

protected int GetTickCount()

Returns

  • Number of milliseconds elapsed since the system started

MarketInfo

Get information about instrument

protected double MarketInfo(string symbol, int type)

Parameters

  • symbol - Symbol name
  • type - Type of instrument parameter that you want to get (MODE_LOW, MODE_HIGH, MODE_LOTSIZE ...)

Returns

  • Double value of parameter

MessageBox

Show system message box

protected int MessageBox(string text = "", string caption = "", int flags = EMPTY)

Parameters

  • text - Text, containing message to output.
  • caption - Optional text to be displayed in the box header.
  • flags - Optional flags defining appearance and behavior of a message box. Flags can be a combination of a special group of flags.

Returns

  • If the function is successfully performed, the returned value is one of values of MessageBox() return codes.

PlaySound

Play sound from specified file

protected void PlaySound(string filename)

Parameters

  • filename - Full file path

Print

Show message in app journal

protected void Print(params object[] vals)

Parameters

  • vals - Values that will be concatenated and showed as print message

SendFTP

Send file by FTP. Not supported, return false in any cases.

protected bool SendFTP(string filename, string ftpPath = null)

Returns

  • false

SendMail

Send email Not supported

protected void SendMail(string subject, string someText)

SendNotification

Not supported, return false in any cases.

protected bool SendNotification(string message)

Returns

  • false

Sleep

Stop current thread for specified time in milliseconds.

protected void Sleep(int ms)

Parameters

  • ms - time in milliseconds

CharToStr

Convert Char to String

protected string CharToStr(int charCode)

Parameters

  • charCode - ASCII char code

Returns

  • Text string

DoulbeToStr

Convert double to string

protected string DoubleToStr(double value, int digits)

Parameters

  • value - Floating point value
  • digits - Precision format, number of digits after decimal point (0-8).

Returns

  • Text string

NormalizeDouble

Round double value to a specified numbers of fractional digits

protected double NormalizeDouble(double value, int digits)

Parameters

  • value - Value with a floating point.
  • digits - Accuracy format, number of digits after point (0-8).

Returns

  • Value of double type with preset accuracy.

StrToDouble

Converts string representation of number to double type (double-precision format with floating point).

protected double StrToDouble(string value)

Parameters

  • value - String containing the number character representation format.

Returns

  • Value of double type. NaN in case of error.

StrToInteger

Converts string containing the value character representation into a value of the int (integer) type.

protected int StrToInteger(string value)

Parameters

  • value - String containing the integer character representation format.

Returns

  • Value of int type. MinValue in case of error.

StrToTime

Converts string in the format "yyyy.mm.dd hh:mi" to datetime type (the amount of seconds that have passed since 1 Jan., 1970).

protected datetime StrToTime(string value)

Parameters

  • value - String having "yyyy.mm.dd hh:mi " format.

Returns

  • Value of datetime type as a number of seconds, passed since 01.01.1970. Datetime MinValue in case of error.

TimeToStr

Converts value containing time in seconds that has passed since January 1, 1970, into a string of "yyyy.mm.dd hh:mi" format.

protected string TimeToStr(Object value,
   int mode = (int)(DateTimeFormat.TIME_DATE | DateTimeFormat.TIME_MINUTES))

Parameters

  • value - Positive amount of seconds that have passed since 00:00, January 1, 1970.
  • mode - Optional data output mode can be one or combination of:
    • TIME_DATE gets result as "yyyy.mm.dd"
    • TIME_MINUTES gets result as "hh:mi"
    • TIME_SECONDS gets result as "hh:mi:ss"

Retruns

  • String

Day

Return day number of month according to server time

protected int Day()

Returns

  • day number of month according to server time

DayOfWeek

Return day number of week according to server time

protected int DayOfWeek()

Returns

  • Day number of week according to server time.

DayOfYear

Return day number of year according to server time

protected int DayOfYear()

Returns

  • Day number of year according to server time.

Hour

Return current hour according to server time

protected int Hour()

Returns

  • Current hour according to server time.

Minute

Return current minute according to server time

protected int Minute()

Returns

  • Current minute according to server time.

Month

Return current month number according to server time

protected int Month()

Returns

  • Current month according to server time.

Seconds

Return current second according to server time

protected int Seconds()

Returns

  • Current second according to server time.

TimeCurrent

Return current server time

protected datetime TimeCurrent()

Returns

  • Current server time.

TimeDay

Return day of the month from specified date

protected int TimeDay(datetime date)

Parameters

  • date - specified date

Returns

  • Day of month from specified date

TimeDayOfWeek

Return day of the week from specified date

protected int TimeDayOfWeek(datetime date)

Parameters

  • date - specified date

Returns

  • Day of the week from specified date

TimeDayOfYear

Return day of the year from specified date

protected int TimeDayOfYear(datetime date)

Parameters

  • date - specified date

Returns

  • Day of the year from specified date

TimeHour

Return hour from specified date

protected int TimeHour(datetime time)

Parameters

  • time - specified date

Returns

  • Hour from specified date

TimeLocal

Return local time

protected DateTime TimeLocal()

Returns

  • Local time

TimeMinute

Return minute from specified date

protected int TimeMinute(datetime time)

Parameters

  • time - specified date

Returns

  • Minute from specified date

TimeMonth

Return month from specified date

protected int TimeMonth(datetime time)

Parameters

  • time - specified date

Returns

  • Month from specified date

TimeSeconds

Return second from specified date

protected int TimeSeconds(datetime time)

Parameters

  • time - specified date

Returns

  • Second from specified date

TimeYear

Return year from specified date

protected int TimeYear(datetime time)

Parameters

  • time - specified date

Returns

  • Year from specified date

Year

Return year from from server time

protected int Year()

Returns

  • Year from server time

CompareString

Compare strings and return equality

protected bool CompareString(string s1, string s2, bool ignoreCase = false)

Parameters

  • s1 - first string
  • s2 - second string
  • ignoreCase - ignore case of strings when true.(default = false)

Returns

  • True if the strings are the same, false otherwise

MathAbs

The function returns the absolute value (modulus) of the specified numeric value.

protected double MathAbs(double value)

Parameters

  • value - Numeric value

Returns

  • Value of double type more than or equal to zero.

MathArccos

The function returns the arccosine of x within the range 0 to π in radians.

protected double MathArccos(double x)

Parameters

  • x - The val value between -1 and 1, the arc cosine of which is to be calculated.

Returns

  • Arc cosine of a number in radians. If val is less than -1 or more than 1, the function returns NaN (indeterminate value).

MathArcsin

The function returns the arc sine of x within the range of -π/2 to π/2 radians.

protected double MathArcsin(double x)

Parameters

  • x - The val value between -1 and 1, the arc sine of which is to be calculated.

Returns

  • Arc sine of the val number in radians within the range of -π/2 to π/2 radians. If val is less than -1 or more than 1, the function returns NaN (indeterminate value).

MathArctan

The function returns the arc tangent of x. If x is equal to 0, the function returns 0.

protected double MathArctan(double x)

Parameters

  • x - A number representing a tangent.

Returns

  • returns a value within the range of -π/2 to π/2 radians.

MathCeil

Returns the smallest integral value that is greater than or equal to the specified double-precision floating-point number.

protected double MathCeil(double x)

Parameters

  • x - Numeric value

Returns

  • Numeric value representing the smallest integer that exceeds or equals to x.

MathCos

The function returns the cosine of an angle.

protected double MathCos(double value)

Parameters

  • value - Angle in radians

Returns

  • Value of double type within the range of -1 to 1.

MathExp

The function returns the value of e raised to the power of d.

protected double MathExp(double d)

Parameters

  • d - A number specifying the power.

Returns

  • A number of double type. In case of overflow the function returns INF (infinity), in case of underflow MathExp returns 0.

MathFloor

The function returns integer numeric value closest from below.

protected double MathFloor(double x)

Parameters

  • x - Numeric value

Returns

  • A numeric value representing the largest integer that is less than or equal to val.

MathLog

The function returns a natural logarithm.

protected double MathLog(double x)

Parameters

  • x - Value logarithm of which is to be found.

Returns

  • The natural logarithm of val in case of success. If val is negative, the function returns NaN (undetermined value). If val is equal to 0, the function returns INF (infinity).

MathMax

The function returns the maximal value of two values.

protected double MathMax(double value1, double value2)

Parameters

  • value1 - First numeric value.
  • value2 - Second numeric value.

Returns

  • The largest of the two values.

MathMin

The function returns the minimal value of two values.

protected double MathMin(double value1, double value2)

Parameters

  • value1 - First numeric value.
  • value2 - Second numeric value.

Returns

  • The smallest of the two values.

MathMod

The function returns the real remainder of division of two numbers.

protected double MathMod(double value, double value2)

Parameters

  • value - Dividend value.
  • value2 - Divisor value.

Returns

  • he MathMod function calculates the real remainder f from expression val/y so that val = i * y + f , where i is an integer, f has the same sign as val, and the absolute value of f is less than the absolute value of y.

MathPow

The function raises a base to a specified power.

protected double MathPow(double value, double exponent)

Parameters

  • value - Base.
  • exponent - Exponent value.

Returns

  • Value of base raised to the specified power.

MathRand

Returns a pseudorandom integer within the range of 0 to 32767.

protected int MathRand()

Returns

  • Integer value within the range of 0 to 32767.

MathRound

The function returns a value rounded off to the nearest integer of the specified numeric value.

protected double MathRound(double value)

Parameters

  • value - Numeric value before rounding.

Returns

  • Value rounded till to the nearest integer.

MathSin

Returns the sine of a specified angle.

protected double MathSin(double value)

Parameters

  • value - Angle in radians.

Returns

  • Sine of an angle measured in radians. Returns value within the range of -1 to 1.

MathSqrt

Returns the square root of a number.

protected double MathSqrt(double x)

Parameters

  • x - Positive numeric value.

Returns

  • Square root of value. If value is negative, MathSqrt returns NaN (indeterminate value).

MathSrand

Sets the starting point for generating a series of pseudorandom integers.

protected void MathSrand(int seed)

Parameters

  • seed - Starting number for the sequence of random numbers.

MathTan

The function returns a tangent of a number.

protected double MathTan(double x)

Parameters

  • x - Angle in radians.

Returns

  • Tangent of rad. If rad 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 number.

StringConcatenate

The function returns the string formed by concatenation of parameters transformed into string type.

protected string StringConcatenate(params Object[] values)

Parameters

  • values - an object array, using the comma separator between each element

Returns

  • Returns the string, formed by concatenation of parameters transformed into string type.

StringFind

Search for a substring in a string.

protected int StringFind(string text, string matchedText, int start = 0)

Parameters

  • text - String, in which search is made.
  • matchedText - Searched substring.
  • start - Position in the string from which search is started.

Returns

  • Returns position number in a string, from which the searched substring starts, or -1, if the substring is not found.

StringGetChar

Returns value of a symbol, located in the specified position of a string.

protected int StringGetChar(string text, int pos)

Parameters

  • text - String.
  • pos - Position of a symbol in the string

Returns

  • Chart ASCII code in specified position from string. In case of error return -1

StringLen

Returns the number of symbols in a string.

protected int StringLen(string text)

Parameters

  • text - String to calculate length.

Returns

  • Length of string

StringSetChar

Insert in specified position in string new chart

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

Parameters

  • text - String.
  • pos - Position for inserting
  • value - Char ASCII code

Returns

  • New string.

StringSubstr

Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length.

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

Parameters

  • text - String to extract a substring from.
  • start - Initial position of a substring.
  • length - Length of an extracted substring. If the parameter value is equal or less than 0 or parameter isn't set, the substring will be extracted from the indicated position till the string end.

Returns

  • Copy of a extracted substring, if possible. Otherwise returns an empty string.

StringTrimLeft

The function cuts line feed characters, spaces and tabs in the left part of the string till the first meaningful symbol. The string is modified at place.

protected string StringTrimLeft(string text)

Parameters

  • text - String that will be cut from the left.

Returns

  • A copy of the cut string if possible, otherwise an empty string.

StringTrimeRight

The function cuts line feed characters, spaces and tabs in the right part of the string after the last meaningful symbol. The string is modified at place.

protected string StringTrimRight(string text)

Parameters

  • text - String that will be cut from the right.

Returns

  • A copy of the cut string if possible, otherwise an empty string.

TerminalCompany

Returns the name of company owning the client terminal.

protected string TerminalCompany()

Returns

  • The name of company owning the client terminal.

TerminalName

Returns client terminal name.

protected string TerminalName()

Returns

  • Client terminal name.

TerminalPath

Returns the directory, from which the client terminal was launched.

protected string TerminalPath()

Returns

  • The directory, from which the client terminal was launched.

HideTestIndicators

The function sets a flag hiding indicators called by the Expert Advisor.

protected void HideTestIndicators(bool hide)

Parameters

  • hide - Hiding flag.

Period

Returns timeframe of the current chart.

protected int Period()

Returns

  • Period (timeframe) of the current chart (in minutes).

RefreshRates

Refreshing of data in pre-defined variables and series arrays.

protected bool RefreshRates()

Returns

  • True if the data updated, otherwise false.

Symbol

Returns the name of a symbol of the current chart.

protected string Symbol()

Returns

  • Name of symbol of the current chart.

WindowBarsPerChart

Returns the amount of bars visible on the chart.

protected int WindowBarsPerChart()

Returns

  • The amount of bars visible on the chart. This value may change as the chart is zoomed or scrolled.

WindowExpertName

Returns the name of the executed Expert Advisor, script, custom indicator, or library.

protected string WindowExpertName()

Returns

  • The name of the executed Expert Advisor, script, custom indicator, or library

WindowsFind

Get chart panel number by object name on it

protected int WindowsFind(string name)

Parameters

  • name - object name.

Returns

  • Chart panel number

WindowFirstVisibleBar

Returns index of the first visible bar in the current chart window.

protected int WindowFirstVisibleBar()

Returns

  • Index of the first visible bar number in the current chart window.

WindowHandle

Returns the system handle of the chart window. Not Supported

protected int WindowHandle(string symbol, int timeframe)

WindowIsVisible

Determinate is the panel on chart with specified number currently visible. True in any cases.

protected bool WindowIsVisible(int index)

Returns

  • True.

WindowPriceMax

Get max price on specified chart panel

protected double WindowPriceMax(int index = 0)

Parameters

  • index - Panel index.

Returns

  • Max price on specified chart panel

WindowPriceMin

Get min price on specified chart panel

protected double WindowPriceMin(int index = 0)

Parameters

  • index - Panel index.

Returns

  • Min price on specified chart panel

WindowRedraw

Force redraw chart

protected void WindowRedraw()

WindowScreenShot

Create and save chart screenshot in specified file

protected bool WindowScreenShot(string filename, int size_x, int size_y, int start_bar = -1, int chart_scale = 0,
int chart_mode = -1)

Parameters

  • filename - Screen shot file name.
  • size_x - Screen shot width in pixels.
  • size_y - Screen shot height in pixels.
  • start_bar - ndex of the first visible bar in the screen shot. If 0 value is set, the current first visible bar will be shot. If no value or negative value has been set, the end-of-chart screen shot will be produced, indent being taken into consideration.
  • chart_scale - Horizontal chart scale for screen shot. Can be in the range from 0 to 5. If no value or negative value has been set, the current chart scale will be used.
  • chart_mode - Chart displaying mode. It can take the following values:
    • CHART_BAR (0 is a sequence of bars)
    • CHART_CANDLE (1 is a sequence of candlesticks)
    • CHART_LINE (2 is a close prices line)
    • If no value or negative value has been set, the chart will be shown in its current mode.

Returns

  • Returns true if succeed, otherwise false.

WindowsTotal

Get total panels count

protected int WindowsTotal()

Returns

  • Total panels count
Clone this wiki locally