Page 1 of 1

Lesson 4 - Access to the bars

Posted: Sat Jul 26, 2008 10:44 am
by Terranin
To make trading decisions you need to get an information about current price and previous prices for different timeframes.

Right after entering to the GetSingleTick function you have next functions to get information about currency that changed:

Bid() - Current Bid price for the currency that changed

Ask() - Current Ask price for the currency that changed

Symbol() - Currency name ('EURUSD', 'USDCAD', etc)

Digits() - Digits after point in price (2 for USDJPY, 4 for EURUSD, ...)

Point() - Minimum point for the price (0.01 for USDJPY, 0.0001 for EURUSD, ...)

Code: Select all

// we can separate our currency with Symbol from others
If Symbol <> 'USDCAD' then
  exit;

...

var
  OrderHande: integer;

// and here we use information about currency name,
// Ask price and Point to place an order
SendInstantOrder(Symbol, op_Buy, 0.1, Ask - 100*Point, Ask + 50*Point, '', 0, OrderHandle);


Forex Tester provides access to information about bars with next functions:

Open(index) - Get an Open value of a bar by its index

High(index) - Get a High value of a bar by its index

Low(index) - Get a Low value of a bar by its index

Close(index) - Get a Close value of a bar by its index

Volume(index) - Get a Volume of a bar by its index

Time(index) - Get a Time of a bar by its index

Bars() - Get number of available bars (defines how big index value you can use to address a bar, it will be 0..Bars() - 1 range for an index)

Important: All these functions are valid only after SetCurrencyAndTimeframe procedure call. This procedure defines currency and timeframe for current moment.

Code: Select all

SetCurrencyAndTimeframe('USDJPY', PERIOD_M15);

if (Close(0) > Close(1)) and ((Close(1) > Close(2)) then
  ... // 'USDJPY' is growing on period M15

SetCurrencyAndTimeframe('EURAUD', PERIOD_H1);

if (HourOf(Time(0)) = 10) then
  ... // open some order at 10 a.m.


How to enumerate bars. Bars are numbered from right to left and from 0 to Bars - 1. So the last bar has index 0, when the new bar created it receives index 0 and previous bar gets index 1 and so on.

Image

Image

Image

Posted: Sat Jul 26, 2008 11:21 am
by Terranin
There is another set of functions that do not require previous call of SetCurrencyAndTimeframe:

iOpen(Symbol, Timeframe, index) - Get an Open value of a bar by its Symbol, Timeframe and index.

iHigh(Symbol, Timeframe, index) - Get a High value of a bar by its Symbol, Timeframe and index.

iLow(Symbol, Timeframe, index) - Get a Low value of a bar by its Symbol, Timeframe and index.

iClose(Symbol, Timeframe, index) - Get a Close value of a bar by its Symbol, Timeframe and index.

iVolume(Symbol, Timeframe, index) - Get a Volume of a bar by its Symbol, Timeframe and index.

iTime(Symbol, Timeframe, index) - Get a Time of a bar by its Symbol, Timeframe and index.

iBars(Symbol, Timeframe) - Get number of available bars for selected Symbol and Timeframe (defines how big index value you can use to address a bar, it will be 0..iBars(Symbol, Timeframe) - 1 range for an index)

These functions do the same job like functions described above, just they do not require call of SetCurrencyAndTimeframe and could be used in some expressions with mixed currencies and timeframes:

Code: Select all

if (iClose('USDJPY', PERIOD_M15, 0) > iClose('USDJPY', PERIOD_M15, 1)) and (iClose('EURUSD', PERIOD_H4, 0) > iClose('EURUSD', PERIOD_H4, 1)) then
  ... // it is possible that these two currencies are growing together ...

Re: Lesson 4 - Access to the bars

Posted: Mon May 26, 2014 2:02 am
by west
Hi! Terranin,

Many thanks for your nice lecture.
I have one question.
Index number of the left bar of middle chart is 34 and that of the bottom is 35.
Could you show me the reason why index number of those isn't 33 ?

Re: Lesson 4 - Access to the bars

Posted: Mon May 26, 2014 3:55 am
by FX Helper
Hello,

We mean, that the bar with index=33 on first screenshot is the bar with index=34 on second screenshot and it is the bar with index=35 on third screenshot. Sorry for the inaccurate screenshots.

Re: Lesson 4 - Access to the bars

Posted: Mon May 26, 2014 5:50 am
by west
Hello,

I got it.
Thanks for quick response.