Give the study a name of your choice. The only limitation is that the name can’t be already in use by a different study.
For example I will use ABC_PowerLanguage Lesson 01 as name and then click OK again. The name will be what you use later to add the study to the chart, so it helps when it displays the purpose of the study. I like using the ABC_ prefix to label the studies that I have worked on for myself or the website for example. For other work I will use different labels. This makes it easier to find something when I have to look up a study.
Every study can have inputs that you can assign a default value to. For example you can use an input for the length of a moving average. The inputs for indicators and signals can be changed when you load the study on a chart. So it makes sense to have some inputs to allow a more user friendly study.
When you declare an input by giving it a name and initialize it by assigning a default value, you also define the type of the input. There can be three different types:
- a Numeric input
- a String input
- a Boolean input i.e. a true/false input
To declare an input you use the keyword “Inputs” (or “Input” they are the same) followed by “:” and then the input name and the default value in brackets. You can declare several inputs and separate them with a comma.
This is how the three different input types could look with a valid name and a default value:
Try it out yourself. Type the three inputs and when you are done, hit Compile (or F3).
The Build tab in the bottom window will now display something like this:
It displays the name of the study and the start and end time for the compilation. The message indicates that you have just successfully compiled your first PowerLanguage indicator for Multicharts. Congratulations.
If you receive an error message, this means there is something wrong with your code. Compare your code to the code screenshot again and check for differences. This might be something simple like a missing comma or a bracket not closed.
You can use the inputs in the code later, but the value of it can’t change within the code. This is where variables come into play.
Variables are used to store numerical, string, or logical (true/false) values. The value stored in a variable can be referenced throughout a script by the variable’s name and can be modified by the script at any time. Variables must be declared before use.
Your code can use variables to work with data. They are used to store a value and as the name suggest the value can vary. It can be changed (it is variable, hence the name) while your study runs. The value can be numerical, string or logical (true/false).
Just like the inputs the variables in PowerLanguage can have the same three types:
- a Numeric variable
- a String variable
- a Boolean variable i.e. a variable storing true/false data
You also set the type by initializing the variable when you assign a default value to it.
Additionally you can specify the update basis (during the bar or at the end of the bar) and the data number for each variable when you declare it. This is something I will cover in detail in a future lesson, so don’t worry about that at the moment.
Let’s add some variables to your code now. Type in the three variables you see on the screenshot and press Compile (or