• No se han encontrado resultados

B.- LAS NOTIFICACIONES EN EL PROCEDIMIENTO ADMINISTRATIVO

I've got a lot of messages asking me "How to deal with currency pairs which are different than the current chart currency (The chart that hosts the expert advisor)? For example, how to make an expert advisor that can open Buy position of GBPUSD or USDCHF while the expert advisor is hosted on EURUSD chart?" Good question, Huh?

To reply these related questions we have to start with studding the Timeseries Access functions.

The Timeseries Access functions are a set of functions that enables us to access the price date of any chart (currency and timeframe) regardless of the chart that hosts the expert advisor.

iBars

Syntax:

int iBars( string symbol, int timeframe)

Description:

The iBars function returns the number of Bars of the specified chart, you specify the chart by the symbol name and the timeframe.

Note: If the chart of the symbol and timeframe you are trying to get its price data is not opened,

MetaTrader will try to connect to the server to retrieve the request price data. In this case and with the all of the Timeseries access functions you have to check the the last was the error # 4066 -

ERR_HISTORY_WILL_UPDATED (which means the requested data is under updating) to be sure that the price data is up-to-date. And retry your request for the price data.

Note: If you want to get the number of bars of the current chart (symbol and timeframe) use Bars function.

Parameters: string symbol:

The symbol (currency pair) of the chart you want to get its bars number. Use NULL if you want to use current symbol.

int timeframe:

The timeframe (in integers, ex: 1,5,30,60 etc) of the chart you want to get its bars number. Use 0 if you want to use current timeframe.

Note: You can use the integer representation of the timeframe (period in minutes) or you can use the timeframes constants:

= ! ; *

= ! ;2 2 2 *

= ! ; 2 2 2 *

= ! ;& & & *

= ! 4 3 * = ! / "/ / 3 * = ! ! // ! ( = ! A 9 A @ ( = ! ; /&" ; 3 ( - . * 3 3

Example:

Print("Bar count on the 'EUROUSD' symbol with PERIOD_H1 is",iBars("EUROUSD",PERIOD_H1));

iBarShift:

Syntax:

int iBarShift( string symbol, int timeframe, datetime time, bool exact=false)

Description:

The iBarShift function takes the open time of the bar for a specified symbol and timeframe and searches for this bar and returns it if found otherwise it returns -1.

If you want the iBarShift function to return the nearest bar to the given open time set the exact parameter to true.

Parameters: string symbol:

The symbol (currency pair) of the chart you want to get its bars number. Use NULL if you want to use current symbol.

int timeframe:

The timeframe (in integers, ex: 1,5,30,60 etc) of the chart you want to get its bars number. Use 0 if you want to use current timeframe.

datetime time:

The open time of the bar you want to search for bool exact:

The search mode, use exact =false (default) and and the function will return -1 if the open time not found. And use exact =true and the function will return the nearest bar to the given open time.

Example:

datetime some_time=D'2004.03.21 12:00';

int shift=iBarShift("EUROUSD",PERIOD_M1,some_time);

iClose:

Syntax:

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

Description:

The iClose function returns the Close price for the given bar (the shift parameter is the bar number) of the given symbol and timeframe. The function returns 0 if the history data not loaded.

Note: It's very important (and always error's source) to know that the current bar is 0 and the previous bar is 1 etc.

Note: If you want to get the Close price (of a bar) of the current chart (symbol and timeframe) use Close[int shift] function.

Parameters: string symbol:

The symbol (currency pair) of the chart you want to get its bars number. Use NULL if you want to use current symbol.

int timeframe:

The timeframe (in integers, ex: 1,5,30,60 etc) of the chart you want to get its bars number. Use 0 if you want to use current timeframe.

int shift:

The index of the bar you want to get its Close price.

Example:

Print("Current Close price for USDCHF H1: ",iClose("USDCHF",PERIOD_H1,i));

iHigh:

Syntax:

Description:

The iHigh function returns the High price for the given bar (the shift parameter is the bar number) of the given symbol and timeframe. The function returns 0 if the history data not loaded.

Note: If you want to get the High price (of a bar) of the current chart (symbol and timeframe) use High[int shift] function.

Parameters: string symbol:

The symbol (currency pair) of the chart you want to get its bars number. Use NULL if you want to use current symbol.

int timeframe:

The timeframe (in integers, ex: 1,5,30,60 etc) of the chart you want to get its bars number. Use 0 if you want to use current timeframe.

int shift:

The index of the bar you want to get its High price.

Example:

Print("Current High price for USDCHF H1: ",iHigh("USDCHF",PERIOD_H1,i));

iLow:

Syntax:

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

Description:

The iLow function returns the Low price for the given bar (the shift parameter is the bar number) of the given symbol and timeframe. The function returns 0 if the history data not loaded.

Note: If you want to get the Low price (of a bar) of the current chart (symbol and timeframe) use Low[int shift] function.

Parameters: string symbol:

The symbol (currency pair) of the chart you want to get its bars number. Use NULL if you want to use current symbol.

int timeframe:

The timeframe (in integers, ex: 1,5,30,60 etc) of the chart you want to get its bars number. Use 0 if you want to use current timeframe.

int shift:

The index of the bar you want to get its Low price. Example:

Print("Current Low price for USDCHF H1: ",iLow("USDCHF",PERIOD_H1,i));

iOpen:

Syntax:

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

Description:

The iOpen function returns the Open price for the given bar (the shift parameter is the bar number) of the given symbol and timeframe. The function returns 0 if the history data not loaded.

Note: If you want to get the Open price (of a bar) of the current chart (symbol and timeframe) use Open[int shift] function.

Parameters: string symbol:

The symbol (currency pair) of the chart you want to get its bars number. Use NULL if you want to use current symbol.

int timeframe:

The timeframe (in integers, ex: 1,5,30,60 etc) of the chart you want to get its bars number. Use 0 if you want to use current timeframe.

The index of the bar you want to get its Open price.

Example:

Print("Current Open price for USDCHF H1: ",iOpen("USDCHF",PERIOD_H1,i));

iTime:

Syntax:

datetime iTime( string symbol, int timeframe, int shift)

Description:

The iTime function returns the Open Time of the given bar (the shift parameter is the bar number) of the given symbol and timeframe.

Note: If you want to get the bar Open Time (of a bar) of the current chart (symbol and timeframe) use Time[int shift] function.

Parameters: string symbol:

The symbol (currency pair) of the chart you want to get its bars number. Use NULL if you want to use current symbol.

int timeframe:

The timeframe (in integers, ex: 1,5,30,60 etc) of the chart you want to get its bars number. Use 0 if you want to use current timeframe.

int shift:

The index of the bar you want to get its Open Time.

Example:

iVolume:

Syntax:

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

Description:

The iVolume function returns the Tick Volume value of the given bar (the shift parameter is the bar number) of the given symbol and timeframe.

Note: Volume is simply the number of shares (or contracts) traded during a specified time frame (e.g., hour, day, week, month, etc).

Note: In MQL if you want to check if the tick is the first tick of the new bar you can check Volume[0] it will be 0 if it's the first tickof the new bar. Example:

//---- go trading only for first tiks of new bar if(Volume[0]>1) return;

Note: If you want to get the Tick Volume value (of a bar) of the current chart (symbol and timeframe) use Volume[int shift] function.

Parameters: string symbol:

The symbol (currency pair) of the chart you want to get its bars number. Use NULL if you want to use current symbol.

int timeframe:

The timeframe (in integers, ex: 1,5,30,60 etc) of the chart you want to get its bars number. Use 0 if you want to use current timeframe.

int shift:

The index of the bar you want to get its Tick Volume value.

Example:

Highest:

Syntax:

int Highest( string symbol, int timeframe, int type, int count=WHOLE_ARRAY, int start=0)

Description:

The Highest function calculate the Highest value of the specified type (Close price, Open price, High price etc) for a specified bars of the given symbol and timeframe.

You use the type parameter to determine the type of the values to be calculated and the parameters count and start determine the bars to be calculated.

Parameters: string symbol:

The symbol (currency pair) of the chart you want to get its bars number. Use NULL if you want to use current symbol.

int timeframe:

The timeframe (in integers, ex: 1,5,30,60 etc) of the chart you want to get its bars number. Use 0 if you want to use current timeframe.

int type:

The type of values (Series array) to be calculated, it can be one of these types:

Constant Value Description MODE_OPEN 0 Open price. MODE_LOW 1 Low price. MODE_HIGH 2 High price. MODE_CLOSE 3 Close price. MODE_VOLUME 4 Volume. MODE_TIME 5 Bar Open time.

int count:

How many bars you want to calculate its Highest value, use this parameter with start parameter to determine the range of bars to be calculated. The default value is WHOLE_ARRAY which means all the bars (values in the series array).

int start:

Example:

double val;

// calculating the highest value in the range from 5 element to 25 element // indicator charts symbol and indicator charts time frame

val=High[Highest(NULL,0,MODE_HIGH,20,4)];

Lowest:

Syntax:

int Lowest( string symbol, int timeframe, int type, int count=WHOLE_ARRAY, int start=0)

Description:

The Lowest function calculate the Lowest value of the specified type (Close price, Open price, High price etc) for a specified bars of the given symbol and timeframe.

You use the type parameter to determine the type of the values to be calculated and the parameters count and start determine the bars to be calculated.

Parameters: string symbol:

The symbol (currency pair) of the chart you want to get its bars number. Use NULL if you want to use current symbol.

int timeframe:

The timeframe (in integers, ex: 1,5,30,60 etc) of the chart you want to get its bars number. Use 0 if you want to use current timeframe.

int type:

The type of values (Series array) to be calculated. int count:

How many bars you want to calculate its Highest value, use this parameter with start parameter to determine the range of bars to be calculated. The default value is WHOLE_ARRAY which means all the bars (values in the series array).

int start:

Example:

double val=Low[Lowest(NULL,0,MODE_LOW,10,10)];

Now we have the tools to access the price data of the other charts, the question is: Is this enough to write our expert advisor that deals with other currency pairs? No!

In the coming lesson we are going to know the most important function needed to write this kind of expert advisors; the MarketInfo() function.

I hope you find it a useful lesson!

Windows functions

Documento similar