Scripted SMA

The HaasScripting abilities are present inside the Simple license and up.

This is a example script for a Simple Moving Average (SMA) Trading Indicator.

ls = Input("Short Length",6,1,99) -- Inputfield, value 6, range 1-99
ll = Input("Long Length",14,1,99) -- Inputfield, value 14, range 1-99
p = GetPrices() -- Get (closing) price data
short_res = SMA(p, ls) -- SMA short calculation
long_res = SMA(p, ll) -- SMA long calculation
short = short_res[1] -- Reading the last SMA short value
long = long_res[1] -- Reading the last SMA long value
if (short < long) then
ShortSell() -- Signal a sell/short if the short is below the long
else
LongBuy() -- Signal a buy/long if the short is above the long
end