📰 Latest: HaasOnline Academy Is Back — Structured Education for Smarter Trade Bots
Account
Using Data

Inputs

Inputs

Inputs allow users to configure your HaasScript without modifying code. Inputs appear as configurable fields in the HaasOnline interface, making scripts reusable and adaptable to different markets, strategies, and risk profiles.

Basic Input

The Input() command creates a configurable field. The field type depends on the default value:

-- Number input
local rsiLength = Input("RSI Length", 14)

-- Text input
local strategyName = Input("Strategy Name", "RSI Reversal")

-- Boolean checkbox
local useStopLoss = Input("Use Stop Loss", true)

Without a default value, the input becomes a text field.

Input Parameters

All input commands share common optional parameters:

  • label (required) - The field label text shown to users
  • defaultValue - The default value for the field
  • tooltip - Help text shown when hovering over the field
  • group - Organizes related inputs together
local rsiLength = Input(
    "RSI Length",        -- Label
    14,                   -- Default value
    "Period for RSI calculation",  -- Tooltip
    "Indicators"          -- Group
)

Input Types

Number Input

Numeric inputs for strategy parameters:

local rsiLength = Input("RSI Length", 14)
local rsiOverbought = Input("RSI Overbought", 70)
local stopLossPercent = Input("Stop Loss %", 2.0)
local positionSize = Input("Position Size", 100)

Text Input

Text inputs for labels or identifiers:

local botName = Input("Bot Name", "My Trading Bot")
local logPrefix = Input("Log Prefix", "STRATEGY1")

Boolean Input

Checkbox inputs for toggles:

local useTakeProfit = Input("Use Take Profit", true)
local enableLogging = Input("Enable Logging", false)
local allowShorts = Input("Allow Short Positions", true)

InputOptions - Dropdown

Dropdown inputs with predefined options:

local tradeDirection = InputOptions(
    "Trade Direction",
    "Both",
    {"Long", "Short", "Both"},
    "Select which positions to take"
)

local timeframe = InputOptions(
    "Timeframe",
    "1h",
    {"1m", "5m", "15m", "1h", "4h", "1d"},
    "Chart interval"
)

-- Use in logic
if tradeDirection == "Long" or tradeDirection == "Both" then
    -- Long entry logic
end

InputInterval - Timeframe Dropdown

Dropdown with standard interval options:

local chartInterval = InputInterval("Chart Interval", 60)
local signalInterval = InputInterval("Signal Interval", 5)

Common interval values:

  • 1 = 1 minute
  • 5 = 5 minutes
  • 15 = 15 minutes
  • 60 = 1 hour
  • 1440 = 1 day

InputMarket - Market Selection

Dropdown for market selection based on the connected account:

local market = InputMarket("Market", "BINANCE_BTC_USDT_")

InputButton - Interactive Button

Button that executes a callback when clicked:

local resetStateButton = InputButton(
    "Reset State",
    function()
        Delete('tradeCount')
        Delete('lastTradeTime')
        Log('State reset by user')
    end,
    "Clear all saved trading data"
)

InputGroupHeader - Organize Inputs

Creates visual separators for grouping related inputs:

InputGroupHeader("Indicator Settings")
local rsiLength = Input("RSI Length", 14)
local rsiOverbought = Input("RSI Overbought", 70)
local rsiOversold = Input("RSI Oversold", 30)

InputGroupHeader("Risk Management")
local useStopLoss = Input("Use Stop Loss", true)
local stopLossPercent = Input("Stop Loss %", 2.0)
local useTakeProfit = Input("Use Take Profit", false)

Complete Example: Strategy Configuration

Here's a comprehensive example showing how inputs make a strategy configurable:

-- Strategy Name
InputGroupHeader("Strategy Configuration")
local strategyName = Input("Strategy Name", "RSI Reversal")
local enabled = Input("Enable Strategy", true)

-- Indicator Settings
InputGroupHeader("Indicator Settings")
local rsiLength = Input("RSI Length", 14, "Period for RSI calculation")
local rsiOverbought = Input("RSI Overbought", 70, "RSI level for short entry")
local rsiOversold = Input("RSI Oversold", 30, "RSI level for long entry")
local useBollingerFilter = Input("Use Bollinger Filter", true)
local bbLength = Input("BB Length", 20)
local bbDeviation = Input("BB Deviation", 2.0)

-- Trade Direction
local tradeDirection = InputOptions(
    "Trade Direction",
    "Both",
    {"Long", "Short", "Both"},
    "Which positions to take"
)

-- Risk Management
InputGroupHeader("Risk Management")
local useStopLoss = Input("Use Stop Loss", true)
local stopLossPercent = Input("Stop Loss %", 2.0)
local useTakeProfit = Input("Use Take Profit", false)
local takeProfitPercent = Input("Take Profit %", 4.0)
local positionSize = Input("Position Size", 100, "Position size in base currency")

-- Cooldown Settings
local useCooldown = Input("Use Cooldown", true)
local cooldownMinutes = Input("Cooldown Minutes", 60)

-- Trading Logic
if enabled then
    local closePrices = ClosePrices()
    local rsi = RSI(closePrices, rsiLength)
    local posDirection = GetPositionDirection()

    -- Apply Bollinger filter if enabled
    local bbPass = true
    if useBollingerFilter then
        local bb = BBANDS(closePrices, bbLength, bbDeviation, bbDeviation)
        bbPass = closePrices[1] < bb[1]  -- Price below lower band
    end

    -- Long entry
    if (tradeDirection == "Long" or tradeDirection == "Both") then
        if rsi < rsiOversold and bbPass and posDirection != PositionLong then
            -- Check cooldown
            local lastTradeTime = Load('lastTradeTime')
            local cooldownPassed = not useCooldown or lastTradeTime == nil or
                Time() >= lastTradeTime + cooldownMinutes * 60

            if cooldownPassed then
                DoLong(positionSize)
                if useStopLoss then
                    StopLoss(stopLossPercent)
                end
                if useTakeProfit then
                    TakeProfit(takeProfitPercent)
                end
                Save('lastTradeTime', Time())
            end
        end
    end

    -- Short entry
    if (tradeDirection == "Short" or tradeDirection == "Both") then
        if rsi > rsiOverbought and bbPass and posDirection != PositionShort then
            local lastTradeTime = Load('lastTradeTime')
            local cooldownPassed = not useCooldown or lastTradeTime == nil or
                Time() >= lastTradeTime + cooldownMinutes * 60

            if cooldownPassed then
                DoShort(positionSize)
                if useStopLoss then
                    StopLoss(stopLossPercent)
                end
                if useTakeProfit then
                    TakeProfit(takeProfitPercent)
                end
                Save('lastTradeTime', Time())
            end
        end
    end
end

Input Best Practices

Organize inputs with groups:

InputGroupHeader("Core Settings")
InputGroupHeader("Indicators")
InputGroupHeader("Risk Management")

Provide helpful tooltips:

local rsiLength = Input(
    "RSI Length",
    14,
    "Typical values: 14 (default), 9 for faster, 21 for slower signals",
    "Indicators"
)

Use sensible defaults:

  • Start with commonly used values
  • Balance between flexibility and simplicity
  • Consider risk when setting default percentages

Validate input ranges:

local stopLossPercent = Input("Stop Loss %", 2.0)
if stopLossPercent <= 0 or stopLossPercent > 100 then
    Log('Warning: Stop loss outside reasonable range')
end

Document your inputs:

-- === INPUT PARAMETER DOCUMENTATION ===
-- rsiLength: RSI period (default 14)
-- rsiOverbought: RSI level for short signals (default 70)
-- rsiOversold: RSI level for long signals (default 30)
-- useStopLoss: Enable stop loss (default true)
-- stopLossPercent: Stop loss percentage (default 2.0)

Input vs Variables

Understand the difference between inputs and variables:

-- Input: User-configurable, persists across restarts
local rsiLength = Input("RSI Length", 14)

-- Variable: Internal, reset each update
local rsi = RSI(ClosePrices(), rsiLength)

-- Saved variable: Persists across updates
local tradeCount = Load('tradeCount', 0)

Inputs are read-only at runtime. Users change them through the UI, not by modifying code.

Common Mistakes

Using inputs for values that change at runtime:

-- Wrong: Inputs shouldn't change during execution
local currentPrice = Input("Current Price", 0)  -- Don't do this

-- Correct: Use variables for runtime values
local currentPrice = CurrentPrice()

Not using tooltips:

-- Poor user experience
local rsiLength = Input("RSI Length", 14)

-- Better: Users understand what the parameter does
local rsiLength = Input("RSI Length", 14, "Period for RSI calculation (14 is standard)")

Too many inputs without grouping:

-- Hard to navigate
local p1 = Input("Param1", 1)
local p2 = Input("Param2", 2)
-- ... 20 more inputs

-- Organized
InputGroupHeader("Strategy Settings")
local p1 = Input("Param1", 1)
local p2 = Input("Param2", 2)
InputGroupHeader("Risk Management")
local p3 = Input("Param3", 3)