Working With Data

Accessing data

Let's look at how you can access the current bar's open price and create a strategy which enters a long position whenever that open price is higher than a certain level:

1 enter long when open > 1.1251

You use

open
to access the open price of this newly opened bar - simple as that.

You can also use

high
,
low
,
close
and
volume
to access data from the bar that was just closed.

Let's reiterate, as this is important:

open
gives you the opening price of the newly opened bar, while
high
,
low
,
close
and
volume
are part of the closed bar.

Comparisons

Another thing this strategy is doing is comparing values, using the

>
operator. You can compare values using
>
greater than,
>=
greater than or equal,
<
less than,
<=
less than or equal,
==
equal and
!=
not equal.

All of these comparisons evaluate to either

true
or
false
. Very useful for building Signal Condition Statements.

You can also use all common arithmetic operations, such as

+
addition,
-
subtraction,
*
multiplication,
/
division and more.

Let's say you want to create a strategy which opens a long position whenever the average of the

high
and
low
prices is higher than the
close
price. You can achieve this by using the
+
addition and
/
division operators, and
()
parentheses for grouping, like this:

1 enter long when (high + low) / 2 > close

Combining conditions

We previously created a strategy which opens a position whenever the open price is higher than some value. What if we want to make sure it's between two values?

To achieve this, we need to combine two conditions, using the

and
operator, like this:

1 enter long when open > 1.1251 and open < 1.13

You can use the

and
operator to combine any two
true
/
false
values. In the code above, both
open > 1.1251
and
open < 1.13
resolve to
true
/
false
, so this works fine. The result will be
true
if both values are true and
false
if even one of the values is false.

You may also use the

or
operator to combine conditions. It returns
true
, even if only one of its values is true, and
false
if both are false.

1 true and true # -> true
2 true and false # -> false
3 false and true # -> false
4 false and false # -> false
5
6 true or true # -> true
7 true or false # -> true
8 false or true # -> true
9 false or false # -> false

Next, we will look at how we can use the

time
and
day
values of each bar to make our strategy trade during specific time periods.