|
Utilizing Inputs and Variables
An input is a value that is assigned a name. This value remains constant throughout. The value of inputs can be changed without having to modify the code. Inputs also allow you to optimize your strategy.
A variable is usually a word or alpha numeric sequence that is used to store a value. A variable allows you to change it's value as many times as you like when executing your code. There are 3 types of variables which you must know.
- Numeric - the variable will hold a numeric value ( ie. 1.28232 )
- String - the variable will hold a string value ( ie. "MyString" )
- Boolean - the variable will hold a true/false value ( ie. true )
It is useful to name inputs and variables in a manner that describes what value the variable is holding. In the following example we create a simple moving average indicator.
In the sample below we create a simple moving average indicator.
inputs:
MAVGPeriod( 20 ); // The default value is 20
variables:
{ The default value is 0, which implies that it is numeric }
MAVGValue( 0 );
{ code executes on the close of every bar, so our MAVGValue variable will update every bar as well }
MAVGValue=average(close, MAVGPeriod);
// The plot statement is used to plot a value on your chart
Plot1(MAVGValue);
|