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:
You useto access the open price of this newly opened bar - simple as that.
You can also use, , and to access data from the bar that was just closed.
Let's reiterate, as this is important:gives you the opening price of the newly opened bar, while , , and are part of the closed bar.
Another thing this strategy is doing is comparing values, using theoperator. 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 eitheror . Very useful for building Signal Condition Statements.
You can also use all common arithmetic operations, such asaddition, subtraction, multiplication, division and more.
Let's say you want to create a strategy which opens a long position whenever the average of theand prices is higher than the price. You can achieve this by using the addition and division operators, and parentheses for grouping, like this:
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 theoperator, like this:
You can use theoperator to combine any two / values. In the code above, both and resolve to / , so this works fine. The result will be if both values are true and if even one of the values is false.
You may also use theoperator to combine conditions. It returns , even if only one of its values is true, and if both are false.
Next, we will look at how we can use theand values of each bar to make our strategy trade during specific time periods.