Overview of HaasScript
Overview of HaasScript
HaasScript is a Lua-based scripting language designed specifically for creating automated cryptocurrency trading strategies on HaasOnline's TradeServer platform. It provides over 600 specialized commands that enable you to build, test, and deploy sophisticated trading bots without managing infrastructure or exchange APIs directly.
What You Can Do With HaasScript
HaasScript gives you complete control over your trading logic. You can:
- Execute trades automatically based on technical indicators, price action, or custom conditions
- Access real-time and historical market data from multiple exchanges simultaneously
- Calculate technical indicators including RSI, MACD, Bollinger Bands, and 150+ others
- Manage positions and orders with built-in risk management tools
- Backtest strategies against historical data to validate performance before risking capital
- Create custom indicators and visual charts for analysis
- Implement complex risk management with stop losses, take profits, and trailing stops
Who Should Learn HaasScript
HaasScript is designed for traders who want to automate their strategies without being professional programmers. The language balances accessibility with power:
- No coding experience required - If you understand basic logic (if/then statements), you can write HaasScript
- Lua-based foundation - Uses Lua syntax, which is one of the easiest programming languages to learn
- Trading-focused commands - Every command is purpose-built for cryptocurrency trading scenarios
- Visual or code-based editing - Choose between writing code directly or using a visual node-based editor
How HaasScript Works
HaasScript bots execute in a continuous cycle on each price tick or time interval:
-- Define user-configurable parameters
local rsiPeriod = Input("RSI Period", 14)
local oversoldLevel = Input("Oversold Level", 30)
-- Get market data
local closePrices = ClosePrices()
-- Calculate technical indicator
local rsi = RSI(closePrices, rsiPeriod)
-- Execute trading logic
if rsi < oversoldLevel then
DoLong("RSI oversold condition")
end
When this script runs, it fetches the latest price data, calculates the RSI indicator, and executes a long trade when RSI drops below the threshold. This cycle repeats continuously, allowing your strategy to react to market conditions in real-time.
Managed vs Unmanaged Trading
HaasScript offers two approaches to trade execution:
Managed Trading (Recommended)
HaasOnline handles position management, order validation, and safety checks automatically. You simply generate signals:
-- Simple long/short signals
if buyCondition then
DoLong() -- Enter long position
elseif sellCondition then
DoShort() -- Enter short position
end
-- Built-in risk management
StopLoss(2.0) -- 2% stop loss
TakeProfit(5.0) -- 5% take profit
Unmanaged Trading (Advanced)
You control every aspect of order execution, including prices, amounts, and timing. This requires handling order states, position tracking, and edge cases manually.
Key Features
Extensive Indicator Library
Access 150+ built-in technical indicators without external libraries:
local sma = SMA(ClosePrices(), 20)
local ema = EMA(ClosePrices(), 20)
local rsi = RSI(ClosePrices(), 14)
local macd = MACD(ClosePrices(), 12, 26, 9)
local bb = BBANDS(ClosePrices(), 20, 2, 2)
Multi-Exchange Support
Write once, deploy everywhere. Scripts work across all supported exchanges without modification:
local currentPrice = CurrentPrice()
local accountBalance = Balance()
local baseCurrency = BaseCurrency()
Custom Input Fields
Create configurable parameters without code changes:
local period = Input("Indicator Period", 14)
local threshold = Input("Entry Threshold", 70)
local useTrailing = Input("Use Trailing Stop", true)
Advanced Risk Management
Implement sophisticated position protection:
-- Dynamic stop loss based on ATR
local atr = ATR(HighPrices(), LowPrices(), ClosePrices(), 14)
local closePrices = ClosePrices()
local atrPercentage = (atr / closePrices) * 100
StopLoss(atrPercentage * 2)
-- Trailing stop to protect profits
TrailingStopLoss(1.5)
What You'll Learn in This Course
This fundamentals course covers everything you need to start building automated trading strategies:
- Getting Started - Overview of HaasScript and the platform
- Explore Editor UI - Navigate the script editor and tools
- Variables - Store and manipulate data
- Operators - Perform calculations and comparisons
- Strings - Work with text data
- Built-in Functions - Use HaasScript's extensive function library
- Managing Trades - Execute and manage positions
- Intervals - Control script execution timing
- Using Data - Access and process market data
- Debugging & Troubleshooting - Find and fix errors
By the end of this course, you'll be able to write functional HaasScript strategies, test them with historical data, and deploy them to trade automatically on live markets.