Take a look at this strategy:
The time constraints for entering and exiting are the same and written twice - this is bad for readability and prone to errors - if you wanted to switch out Tuesday for Wednesday, you would have to do it in two places.
We can use a variable to solve this problem.
Variables are named values. We initialize them using thedefinition operator. We put the name of the variable on the left-hand side of the definition operator and a value on the right-hand side. Once we've done this, we can refer to this value by a name, instead of copy-pasting it each time we need it.
Here's an example:
Let's rewrite our strategy using a variable for the time constraints:
Looks much cleaner, right?
Variables are essential for writing QuantScript. In fact, we've been using variables all along the way -, , , , , and are all variables. The only difference is they're built-in - you don't give them a value yourself, you just use them.
Well, there is something else that's different about them - they can travel through time.