Skip to content
kabirsandhu edited this page Jun 1, 2016 · 2 revisions

Timeseries API

The following methods are for working with timeseries

iBars
iBarShift
iClose
iHigh
iHighest
iLow
iLowest
iOpen
iTime
iVolume

iBars

Returns the number of bars on the specified chart.

protected int iBars(string symbol, int timeFrame)

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 ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe.

Returns

  • The number of bars on the specified chart.

Note

  • For the current chart, the information about the amount of bars is in the Bars predefined variable.

Example

Print("Bar count on the 'EURUSD,H1' is ",iBars("EURUSD",PERIOD_H1));

iBarShift

Search for a bar by its time. The function returns the index of the bar which covers the specified time.

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

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 ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe.
  • time - Time value for searching.
  • exact - Return mode when the bar is not found:
    • false - iBarShift returns the nearest
    • true - iBarShift returns -1

Returns

  • Index of the bar which covers the specified time. If there is no bar for the specified time (history "gap"), the function will return -1 or the nearest bar index (depending on exact parameter).

Example

datetime some_time = D'2004.03.21 12:00';
int shift = iBarShift("EURUSD",PERIOD_M1,some_time);
Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);

iClose

Returns Close price value for the bar of specified symbol with timeframe and shift.

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

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 ENUM_TIMEFRAMES 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).

Returns

  • Close price value for the bar of specified symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. To check errors, one has to call the GetLastError() function.

Note

  • For the current chart, the information about close prices is in the Close[] predefined array.

Example

Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,0),", ",  iOpen("USDCHF",PERIOD_H1,0),", ",
                                    iHigh("USDCHF",PERIOD_H1,0),", ",  iLow("USDCHF",PERIOD_H1,0),", ",
                                    iClose("USDCHF",PERIOD_H1,0),", ", iVolume("USDCHF",PERIOD_H1,0));

iHigh

Returns High price value for the bar of specified symbol with timeframe and shift.

protected double iHigh(string symbol, int timeframe, int shift)

Parameter

  • symbol - Symbol the data of which should be used to calculate indicator. null means the current symbol.
  • timeFrame - Timeframe. It can be any of ENUM_TIMEFRAMES 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).

Returns

  • High value for the bar of specified symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. To check errors, one has to call the GetLastError() function.

Note

  • For the current chart, the information about high prices is in the High[] predefined array.

Example

Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,0),", ",  iOpen("USDCHF",PERIOD_H1,0),", ",
                                    iHigh("USDCHF",PERIOD_H1,0),", ",  iLow("USDCHF",PERIOD_H1,0),", ",
                                    iClose("USDCHF",PERIOD_H1,0),", ", iVolume("USDCHF",PERIOD_H1,0));

iHighest

Returns the shift of the maximum value over a specific number of bars depending on type.

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

Parameter

  • symbol - Symbol the data of which should be used to calculate indicator. null means the current symbol.
  • timeFrame - Timeframe. It can be any of ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe.
  • type - Series array identifier. It can be any of the Series array identifier enumeration values.
  • count - Number of bars (in direction from the start bar to the back one) on which the search is carried out.
  • start - Shift showing the bar, relative to the current bar, that the data should be taken from.

Returns

  • The shift of the maximum value over a specific number of bars or -1 if error. To check errors, one has to call the GetLastError() function.

Example

double val;
//--- calculating the highest value on the 20 consecutive bars in the range
//--- from the 4th to the 23rd index inclusive on the current chart
 int val_index=iHighest(null,0,MODE_HIGH,20,4);
 if(val_index!=-1) val=High[val_index];
 else PrintFormat("Error in call iHighest. Error code=%d",GetLastError());

iLow

Returns Low price value for the bar of indicated symbol with timeframe and shift.

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

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 ENUM_TIMEFRAMES 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).

Returns

  • Low price value for the bar of specified symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. To check errors, one has to call the GetLastError() function.

Note

  • For the current chart, the information about low prices is in the Low[] predefined array.

Example

Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,0),", ",  iOpen("USDCHF",PERIOD_H1,0),", ",
                                  iHigh("USDCHF",PERIOD_H1,0),", ",  iLow("USDCHF",PERIOD_H1,0),", ",
                                  iClose("USDCHF",PERIOD_H1,0),", ", iVolume("USDCHF",PERIOD_H1,0));

iLowest

Returns the shift of the lowest value over a specific number of bars depending on type.

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

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 ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe.
  • type - Series array identifier. It can be any of the Series array identifier enumeration values.
  • count - Number of bars (in direction from the start bar to the back one) on which the search is carried out.
  • start - Shift showing the bar, relative to the current bar, that the data should be taken from.

Returns

  • The shift of the lowest value over a specific number of bars or -1 if error. To check errors, one has to call the GetLastError() function.

Example

double val;
//--- calculating the lowest value on the 10 consequtive bars in the range
//--- from the 10th to the 19th index inclusive on the current chart
int val_index=iLowest(NULL,0,MODE_LOW,10,10);
if(val_index!=-1) val=Low[val_index];
else PrintFormat("Error in iLowest. Error code=%d",GetLastError());

iOpen

Returns Open price value for the bar of specified symbol with timeframe and shift.

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

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 ENUM_TIMEFRAMES 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).

Returns

  • Open price value for the bar of specified symbol with timeframe and shift or 0 if error. To check errors, one has to call the GetLastError() function.

Note

  • For the current chart, the information about open prices is in the Open[] predefined array.

Example

Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,0),", ",  iOpen("USDCHF",PERIOD_H1,0),", ",
                                      iHigh("USDCHF",PERIOD_H1,0),", ",  iLow("USDCHF",PERIOD_H1,0),", ",
                                      iClose("USDCHF",PERIOD_H1,0),", ", iVolume("USDCHF",PERIOD_H1,0));

iTime

Returns Time value for the bar of specified symbol with timeframe and shift.

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

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 ENUM_TIMEFRAMES 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).

Returns

  • Time value for the bar of specified symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. To check errors, one has to call the GetLastError() function.

Note

  • For the current chart, the information about open bar times is in the Time[] predefined array.

Example

Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,0),", ",  iOpen("USDCHF",PERIOD_H1,0),", ",
                                    iHigh("USDCHF",PERIOD_H1,0),", ",  iLow("USDCHF",PERIOD_H1,0),", ",
                                    iClose("USDCHF",PERIOD_H1,0),", ", iVolume("USDCHF",PERIOD_H1,0));

iVolume

Returns Tick Volume value for the bar of specified symbol with timeframe and shift.

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

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 ENUM_TIMEFRAMES 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).

Returns

  • Tick volume value for the bar of specified symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. To check errors, one has to call the GetLastError() function.

Note

  • For the current chart, the information about bars tick volumes is in the Volume[] predefined array.

Example

Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,0),", ",  iOpen("USDCHF",PERIOD_H1,0),", ",
                                    iHigh("USDCHF",PERIOD_H1,0),", ",  iLow("USDCHF",PERIOD_H1,0),", ",
                                    iClose("USDCHF",PERIOD_H1,0),", ", iVolume("USDCHF",PERIOD_H1,0));