HaasScript Reference¶
Complete reference documentation for HaasScript, the Lua-based scripting language for automated cryptocurrency trading on Haasonline TradeServer.
Overview¶
HaasScript is a Lua-based scripting language that enables you to create custom trading strategies and indicators. Scripts are executed on each price tick or time interval, allowing you to:
- Access real-time and historical price data
- Calculate technical indicators (RSI, MACD, Bollinger Bands, etc.)
- Generate trading signals (long, short, exit)
- Manage positions and orders
- Implement risk management (stop loss, take profit)
- Create custom visualizations and charts
Type System¶
Core Data Types¶
HaasNumberCollection
The primary data type for numeric operations in HaasScript. Represents both single numbers and arrays of numbers (time series data).
local prices = ClosePrices() -- Returns HaasNumberCollection
local rsi = RSI(prices, 14) -- Returns HaasNumberCollection
-- Access first value
local currentRsi = rsi.Value
-- Access array of values
local rsiHistory = rsi.Values
HaasSignal
Represents trading signals (long, short, exit). Generated by signal helper commands or managed trading actions.
HaasEnum
Enumeration type for constants (MA types, signal types, order types, etc.).
Primitive Types
number- Lua number (floating point)string- Text databoolean- true/false values
Execution Model¶
HaasScript bots execute in two phases:
1. Initialization Phase¶
Runs once when the bot starts. Use this phase to:
- Define input fields with Input() commands
- Set default configuration
- Initialize variables
2. Update Phase¶
Runs on each price tick or configured interval. Use this phase to: - Fetch latest price data - Calculate indicators - Generate trading signals - Manage positions
Example Script:
-- Simple RSI strategy
local period = Input("period", 14) -- Initialization
local prices = ClosePrices() -- Update phase
local rsi = RSI(prices, period)
if rsi.Value < 30 then
DoLong() -- Buy signal
elseif rsi.Value > 70 then
DoShort() -- Sell signal
end
Common Patterns¶
Getting Price Data¶
local closePrices = ClosePrices()
local highPrices = HighPrices()
local lowPrices = LowPrices()
local volume = GetVolume()
Technical Indicators¶
-- RSI (Relative Strength Index)
local rsi = RSI(ClosePrices(), 14)
-- MACD
local macd = MACD(ClosePrices(), 12, 26, 9)
local macdValue = macd.Value
local signalLine = macd.Signal
-- Moving Averages
local sma = SMA(ClosePrices(), 20)
local ema = EMA(ClosePrices(), 20)
Managed Trading (Recommended)¶
-- Simple long/short signals
if buyCondition then
DoLong() -- Enter long position
elseif sellCondition then
DoShort() -- Enter short position
end
-- Exit position
if exitCondition then
DoExitPosition()
end
-- Easy risk management
StopLoss(2.0) -- 2% stop loss
TakeProfit(5.0) -- 5% take profit
TrailingStopLoss(3.0) -- 3% trailing stop
Working with Arrays¶
local prices = ClosePrices()
-- Get specific index (0 = most recent)
local currentPrice = ArrayIndex(prices, 0)
local previousPrice = ArrayIndex(prices, 1)
-- Filter
local highPrices = FilterAbove(prices, 100)
Memory and State¶
Command Index¶
HaasScript provides 579 functions organized into 6 logical domains:
Advanced Features¶
| Category | Functions |
|---|---|
| Charting | 30 |
| Custom Commands Helpers | 8 |
| Input Fields | 23 |
| Input Settings | 6 |
| MAchine Learning | 2 |
| Settings | 24 |
| Social Media | 5 |
98 functions total — View full documentation →
Data & Prices¶
| Category | Functions |
|---|---|
| Price Data | 16 |
| Price Market Information | 12 |
| Profit Information | 6 |
| Time Information | 19 |
| Wallet | 10 |
63 functions total — View full documentation →
Constants¶
| Category | Enumerations |
|---|---|
| Enumerations Array filter Types | 4 |
| Enumerations Candle Pattern | 65 |
| Enumerations Charting | 31 |
| Enumerations Color | 20 |
| Enumerations Data Types | 12 |
| Enumerations Margin Mode | 2 |
| Enumerations Moving Averages | 9 |
| Enumerations Order Types | 9 |
| Enumerations Parameter Type | 9 |
| Enumerations Position | 3 |
| Enumerations Position Mode | 2 |
| Enumerations Signal | 9 |
| Enumerations Signal Types | 7 |
| Enumerations Source Price Types | 8 |
| Enumerations Trading | 3 |
| Enumerations Trading LR | 4 |
197 enumerations total — View full documentation →
Helpers & Utilities¶
| Category | Functions |
|---|---|
| Array Helpers | 22 |
| Equations | 15 |
| Flow Control | 5 |
| Mathematical | 49 |
| Memory Helpers | 11 |
| Miscellaneous | 9 |
| String Helpers | 10 |
121 functions total — View full documentation →
Technical Analysis¶
| Category | Functions |
|---|---|
| Easy Indicators | 50 |
| Technical Analysis | 98 |
| Technical Analysis Helpers | 9 |
157 functions total — View full documentation →
Trading & Positions¶
| Category | Functions |
|---|---|
| Easy Insurances | 14 |
| Easy Safeties | 19 |
| Order Handling | 8 |
| Order Information | 8 |
| Position Information | 14 |
| Position Prices | 11 |
| Signal Helpers | 24 |
| Trade Actions (Managed) | 5 |
| Trade Actions (Unmanaged) | 8 |
| Trade Bot | 4 |
| Trade Market Information | 25 |
140 functions total — View full documentation →
Best Practices¶
Performance¶
- Minimize API calls - Cache price data and indicator results
- Use appropriate periods - Longer indicator periods (1-450) are supported
- Avoid complex loops - Scripts timeout after 2 minutes
Risk Management¶
- Always use stop losses - Protect against unexpected moves
- Test thoroughly - Use backtesting before live trading
- Start small - Test with small position sizes
Debugging¶
- Use Log() commands - Output values for debugging
- Check execution logs - Review bot logs for errors
- Enable debug mode - Get detailed execution traces
Additional Resources¶
- Full Command Reference: See the domain pages for detailed documentation of every command
- Online Documentation: https://help.haasonline.com/haasscript/general/
- Community: Haasonline Discord
This documentation is auto-generated from the HaasScript codebase. To regenerate, run: