Here concepts relating to intervals are introduced.
Why They Are Needed
As explained in the previous chapters, the output of an algorithm consists of true / false values.
These values are specified for each Open, Threshold and Close.
At Open and Close
At Open and Close, the price is well defined, the open and close price, respectively.
There is only one value of the price to consider.
When checked at Open and Close, all algorithms give a simple true / false output, a boolean value.
Example
Let's consider, for instance, the hypothetical algorithm:
Price greater than Simple Moving Average
that checks whether
Price > SMA
At Close
At Close, we would compare the Close price with the SMA and output true or false according to the result:
True where close > SMA
False where close < SMA
At Open
The same for Open; we would compare the Open price with the SMA and output true or false according to the result:
True where open > SMA
False where open < SMA
At Threshold
The Threshold phase, i.e. the phase between Open and Close, excluded, encompasses all the price values between the low and the high of the price:
[low, high] [1]
It is not a single value like Open and Close, but a whole range, or interval.
When checking whether an algorithm is true or false, we need to check all the values in the interval [1].
The result of the check might be different for different values of [1].
In general there might be some values in [1] where the algorithm is satisfied, and others where it is not.
Of course, the algorithm can also be always true or always false in all the interval [1].
Example
In the same example above, the SMA represents the 'threshold' value to use to be compared with price.
There are bars always above the SMA curve, so the algorithm is always true throughout the Threshold phase.
Other bars are always below the SMA curve, so the algorithm is always false throughout the Threshold phase.
In still other cases part of the bar is above the SMA and part is below.
For these days, the algorithm is true for the upper part of the bar, and false for the lower part.
The bar is divided into two intervals, one where the algorithm is true, and the other where the algorithm is false.
Basics of Intervals
Interval
Formally, an interval is a consecutive range of values, between a left endpoint a and a right endpoint b.
In Trading Conceiver an interval is always considered closed, i.e. it includes all its limit points a and b.
It is denoted with square brackets:
[a, b]
It can also be degenerate, when the left and right endpoints coincide:
[a, a]
Union
The union of intervals is the set of all elements of the intervals.
It is denoted by the symbol ∪.
Examples
Example 1 Example 2
──╊━━━╉──────────> ──╊━━━━━━╉───────>
a b a b
∪ ∪
─────────╊━━━╉───> ──────╊━━━━━━╉───>
c d c d
= =
──╊━━━╉──╊━━━╉───> ──╊━━━━━━━━━━╉───>
a b c d a d
Note, in particular, as depicted in the first example, that the union of intervals can give rise to multiple intervals.
In Trading Conceiver this is noteworthy as it can happen when combining elementary algorithms together within the same Tab.
Intersection
The intersection of intervals is the set containing all elements belonging to all the intervals.
It is denoted by the symbol ∩.
Examples
Example 1 Example 2
──╊━━━╉──────────> ──╊━━━━━━╉───────>
a b a b
∩ ∩
─────────╊━━━╉───> ──────╊━━━━━━╉───>
c d c d
= =
─────────────────> ──────╊━━╉───────>
a b c d c b
In the first example, the intersection is the empty set, denoted with ∅.
Complement of an Interval
The complement of an interval I contains all the elements not in I.
Example
I = [1, 2]
Complement of I = (-∞, 1) ∪ (2, +∞)
In Trading Conceiver
In Trading Conceiver, things are simpler.
Intervals Are Always Closed
First of all, in Trading Conceiver an interval is always considered closed.
We don't distinguish between open and closed interval.
The Universe
Moreover, we consider [low, high] as the universe, that is the entire range of possible values.
This implies that each period of the historical file has its own universe.
Examples
Let's suppose we have the values depicted on the right.
Here is a list of intervals with the corresponding complement:
True in a sub-interval of [low, high]. Examples: [low, a], [a, high], [a, b].
True in more than one sub-interval of [low, high]. Example: [low, a] ∪ [b, high]
The algorithm is false in the complement of the interval(s) where it is true.
For instance, if it is true in [low, a], it is false in [a, high]. See the table above.
Boolean Value at Threshold
As said in previous chapters, the output of an algorithm is characterized by a boolean value, true or false.
The precise indication in the case of Threshold is given by the interval where it is true, as explained above.
However, a boolean value is also assigned to the algorithm at Threshold, which 'summarizes' the more complete but also more complex interval framework.
The boolean value of the algorithm in Threshold is set according to the interval(s) where the algorithm is true:
False
The boolean value is set to false if and only if the algorithm is never true throughout [low, high].
True
In all the other cases.
So, if the interval where the algorithm is true is other than the empty set, the boolean value is set to true.
In particular, the boolean value is considered true even if the algorithm is true only in a sub-interval of [low, high].
It is not necessary for it to be valid in all the range of [low, high].
Therefore, the boolean value says if there is at least one value of the interval where the algorithm is true.
The interval says where it is so.
In Tables / Example
In table data both the boolean value of an algorithm and the interval where it is true are reported.
If the interval is missing, it means it is the empty set; consequently the boolean value is false.
If, on the contrary, the interval is present, the boolean value is true.
Elementary trading algorithms
A typical case where an elementary algorithm is true at Threshold is the following.
Let's take the previous algorithm once again:
Price greater than Simple Moving Average
We have the SMA value, i.e. a reference threshold value, and compare it with the price.
In the picture, representing a candlestick, the price is greater than the threshold in the green part, and less than the threshold in the red part.
The algorithm is true in the green interval
[threshold, high]
and false in the red interval
[low, threshold]
The green and the red parts are complement intervals of each other.
The boundary between the two is a 'threshold', i.e. a specific level, which is where the name 'Threshold' comes from.