| function MACross(p1, p2) |
This line declares the study to the
VBScript interpreter
|
| 'example Moving Averages\MACross(3,5) = 100*(MA3 - MA5)/(MA3
+ MA5) |
This line tells UA how to describe the
study in the righ-click menu of the expression memo box.
|
| dim ma1, ma2, indicator, TargetPosition |
This line declares four
variables. "ma1" and "ma2" will be the first and second moving
average. "indicator" will hold the relative
difference. "TargetPosition" represents how the indicator value
should be traded.
|
| if(getNumDays()<max(p1,p2)) then exit function |
This says that if there aren't enough
data of data available, then the study won't report anything.
This will be a blank area at the beginning of the graph in the chart.
|
| ma1 = MAOfField(p1,4) |
We compute the first moving average
using a standard function.
|
| ma2 = MAOfField(p2,4) |
We compute the second moving average
using a standard function. |
| UA.SharePriceScale = 0 |
This tells UA that the indicator is not
a price, and should not share the chart's price scale. Without
this the price graph would shift up, and the indicator would be plotted
as a zero-line since the prices are approx 300 and the indicator is
approx 0.5.
|
| indicator = 100*(ma1 - ma2)/(ma1 + ma2) |
This defined the indicator, a relative
difference between them. |
| if indicator<0 then |
The system tries to be short if the
indicator is negative and long if the indicator is positive, and out of
the market if the indicator ever were zero. (Zero being highly
unlikely.)
|
| TargetPosition = -1 |
|
| elseif indicator>0 then |
|
| TargetPosition = +1 |
|
| else |
|
| TargetPosition = 0 |
|
| end if |
|
| StandardOrderGenerator(TargetPosition) |
We can call a standard function which
just puts in the market orders for the next day to change the current
Position (1=long, -1=short, or 0=neutral) to the TargetPosition. |
| MACross = indicator |
This tells the VBScript interpreter the
that return value of the study is indicator. |
| end function |
This tells the VBScript interpreter
that the study is done. |