HaasScript

From Haasonline Software Wiki
Jump to: navigation, search

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


About

Sometimes there are people who like to go behind the trade-bot its capabilities. People who like to do more advanced things and to support this we added HaasScript. HaasScript is especially designed to make scripting for crypto trading easier.

HaasScript is the successor of C# Scripting and the Local API.

Supported methods

The overview shown below here is just a global representation of the scripting capabilities. The real documentation is added inside our scripting editor.

Basics

-- Comment line

Log(12)               -- Logging a test or variable in the compile view

Getting price data

-- Getting price data
p = GetPrices()       -- Get Closing prices
p = GetClosePrices()  -- Get Closing prices
p = GetHighPrices()   -- Get High prices
p = GetLowPrices()    -- Get Low prices
p = GetOpenPrices()   -- Get Open prices
p = GetAskPrices()    -- Get Ask prices
p = GetBidPrices()    -- Get Bid prices
p = GetVolumes()      -- Get volume data

p = GetOC()           -- Get (Open + Close)/2 prices
p = GetHL()           -- Get (High + Low)/2 prices
p = GetHLC()          -- Get (High + Low + Close)/3 prices
p = GetOHLC()         -- Get (Open + High + Low + Close)/4 prices

Input fields

-- Input field (returns the set value)
v = Input("myid","Length",30,1,999)     
-- the text on the settings is "Length" 
-- the default value is 30
-- the minimum value is 1
-- the maximum value is 999

Charting

Plot("My line", pr, 0, Green)    
-- the line is named "My line"
-- the value is pr
-- the chart is 0, meaning on the candles, use 1, 2 or 3 for extra charts
-- the color is green, we support the following colors;
--   Purple
--   Green
--   Gold
--   Red
--   Blue
--   Orange
--   SkyBlue
--   Yellow
--   White
--   Gray
--   DarkGray

Memory

Save("mykey",123)                    -- Store a value of the last calculation
Load("mykey")                        -- Load a value of the last calculation

Logic

-- Sample script (for indicators and safeties) how to generate a trading signal
if (pr > 2537) then
    LongBuy()
else
    ShortSell()
end

-- NOTE: Also supports "or" and "and", for example: if (pr < 6500 or pr == 6800) then...

Basic calculations

h = GetHigh(p,10)                   -- Get the highest price, based on the last 10 prices
l = GetLow(p,20)                    -- Get the lowest price, based on the last 20 prices
pp = Offset(p,5)                    -- Returns the same array with the the first 5 prices removed

pp = Compress(p)                    -- Compresses 2 prices into 1
res = TimeVal(2)                    -- Checks if the current time is dividable by 2 minutes (return true or false)
t = TIME()                          -- Returns current time in unix format

Array calculations

res = AddArr(a,b)                   -- Merge 2 arrays (a+b)
res = SubArr(a,b)                   -- Substract 2 arrays (a-b)
res = MulArr(a,b)                   -- Multiple 2 arrays (a*b)
res = DivArr(a,b)                   -- Divide 2 arrays (a/b)

Technical analysis

x = AROON(h,l,30)                   -- Returns an array with the Aroon values of length 30
x = AROONOSC(h,l,30)                -- Returns an array with the Aroon-Oscillator values of length 30
x = ATR(h,l,c,30)                   -- Returns an array with the Average True Range values of length 30
x = BOP(o,h,l,c)                    -- Returns an array with the Balance of Power values of length 30
x = CCI(h, l, c, 30)
x = CMO(p,30)                       -- Returns an array with the Chande Momentum Oscillator values of length 30
x = EMA(p,30)                       -- Returns an array with the Exponential Moving Average values of length 30
x = DEMA(p,30)                      -- Returns an array with the Double EMA values of length 30
x = DX(h, l, c, 30)
x = KAMA(p,30)                      -- Returns an array with the Kaufman's Adjusted Moving Average values of length 30
x = MAMA(p,30,10)                   -- Returns an array with the Mother of Adaptive MAs values of short length 30 and long length 10
x = MACD(c, 12, 26, 9)              -- Returns an array of an array with x[0] = MACD, x[1] = signal line, x[2] = histogram (MACD - signal)
x = MOMENTUM(c, 30)
x = NATR(h, l, c, 30)
x = OBV(c, v)
x = POC(p,30)                       -- Returns an array with the Point-of-Control values of length 30
x = ROC(p,30)                       -- Returns an array with the Rate-of-Change values of length 30
x = ROCALT(p,30)                    -- Returns an array with the ROCALT values of length 30
x = ROCP(p,30)                      -- Returns an array with the ROC percentage values of length 30
x = ROCR(p,30)                      -- Returns an array with the ROCR values of length 30
x = RSI(p,14)                       -- Returns an array with the Relative Strength Index values of length 30
x = SMA(p,50)                       -- Returns an array with the Simple Moving Average values using last 50 values from p series
x = STDDEV(c, 30)
x = STOCH(h, l, c, 3, 5, 10)        -- Returns an array of arrays with x[0] = D and x[1] = D-slow 
x = TEMA(p,30)                      -- Returns an array with the TEMA values of length 30
x = TRANGE(h, l, c)
x = TRIMA(p,30)                     -- Returns an array with the TRIMA values of length 30
x = TYPPRICE(h, l, c)
x = ULTOSC(h, l, c, 10, 15, 20)
x = VARIANCE(c, 20)

Bot data: Indicators, Safeties and Insurances

LastBuyPrice()                      -- Returns the bot its last buying price (spot trading only)
LastSellPrice()                     -- Returns the bot its last selling price (spot trading only)

LastGoLongPrice()                   -- Returns the bot its last go long price (margin and leverage trading only)
LastExitLongPrice()                 -- Returns the bot its last exit long price (margin and leverage trading only)
LastGoShortPrice()                  -- Returns the bot its last go short price (margin and leverage trading only)
LastExitShortPrice()                -- Returns the bot its last exit short price (margin and leverage trading only)

BotPosition()                       -- Returns the bot its current position ()
TradeAmount()                       -- Returns the bot its trade-amount
Interval()                          -- Returns the update interval (indicator only)

Signal production: Indicators and Safeties

ShortSell()                         -- Signal a sell/short
BuyLong()                           -- Signal a buy/long 
ExitPosition()                      -- Signal a exit position (works only for margin and leverage)

Signal production: Insurances

AllowTrade()                        -- Approves of a trade
DisallowTrade()                     -- Block a trade

Example Trading Indicators

Example Script-bots