Lesson 4 - Access to the bars
Posted: 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, ...)
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.
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.
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.