Lesson 4 - Access to the bars

Examples step by step how to make your own automated strategy or user indicator
Message
Author
User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

Lesson 4 - Access to the bars

#1 Postby Terranin » Sat Jul 26, 2008 10:44 am

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
Last edited by Terranin on Mon Jan 26, 2009 3:54 pm, edited 6 times in total.
Hasta la vista
Mike

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

#2 Postby Terranin » Sat Jul 26, 2008 11:21 am

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 ...
Hasta la vista

Mike

west
Posts: 5
Joined: Sun Dec 01, 2013 12:45 am

Re: Lesson 4 - Access to the bars

#3 Postby west » Mon May 26, 2014 2:02 am

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 ?

FX Helper
Posts: 957
Joined: Mon Apr 01, 2013 3:55 am

Re: Lesson 4 - Access to the bars

#4 Postby FX Helper » Mon May 26, 2014 3:55 am

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.

west
Posts: 5
Joined: Sun Dec 01, 2013 12:45 am

Re: Lesson 4 - Access to the bars

#5 Postby west » Mon May 26, 2014 5:50 am

Hello,

I got it.
Thanks for quick response.


Return to “Programming lessons”

Who is online

Users browsing this forum: No registered users and 1 guest