📰 Latest: HaasOnline Academy Is Back — Structured Education for Smarter Trade Bots
Account
Getting Started

Case Sensitivity

Case Sensitivity

Understanding case sensitivity is crucial for writing functional HaasScript code. HaasScript treats uppercase and lowercase letters as distinct characters, which affects variables, functions, and commands.

HaasScript is Case-Sensitive

HaasScript distinguishes between uppercase and lowercase letters. This means:

local myVariable = 10
local MyVariable = 20
local MYVARIABLE = 30

-- These are THREE DIFFERENT variables
Log(myVariable)   -- Outputs: 10
Log(MyVariable)   -- Outputs: 20
Log(MYVARIABLE)   -- Outputs: 30

Commands and Functions

All HaasScript commands and built-in functions use specific capitalization. You must match the exact casing.

Correct vs Incorrect

-- Correct: Exact capitalization
local rsi = RSI(ClosePrices(), 14)
local sma = SMA(ClosePrices(), 20)
local ema = EMA(ClosePrices(), 20)

-- Incorrect: Wrong capitalization causes errors
local rsi = rsi(ClosePrices(), 14)      -- Error: rsi is not defined
local sma = sma(ClosePrices(), 20)      -- Error: sma is not defined
local ema = ema(ClosePrices(), 20)      -- Error: ema is not defined

Trading Functions

-- Correct capitalization
DoLong("Entry signal")
DoShort("Exit signal")
DoExitPosition("Close position")

-- Incorrect
dolong("Entry signal")      -- Error: function not found
Doshort("Exit signal")      -- Error: function not found
doexitposition("Close")     -- Error: function not found

Risk Management Functions

-- Correct
StopLoss(2.0)
TakeProfit(5.0)
TrailingStopLoss(1.5)

-- Incorrect
stoploss(2.0)           -- Error
takeprofit(5.0)         -- Error
trailingstoploss(1.5)   -- Error

Signal Constants

HaasScript signal constants use PascalCase (first letter uppercase, subsequent words capitalized):

-- Correct signal constants
SignalLong
SignalShort
SignalExitLong
SignalExitShort
SignalExitPosition
SignalNone

-- Incorrect
signalLong        -- Error
signallong        -- Error
SIGNAL_LONG       -- Error
signallong        -- Error

Data Type Names

HaasScript type names use PascalCase:

-- Correct
NumberType
ListNumberType
StringType
BoolDataType
EnumType

-- Incorrect
numberType       -- Error
listnumberType   -- Error
string_type      -- Error

Variable Naming Conventions

While HaasScript is case-sensitive, you should follow consistent naming conventions:

camelCase for Variables

-- Recommended: camelCase (first letter lowercase)
local closePrices = ClosePrices()
local rsiValue = RSI(ClosePrices(), 14)
local stopLossPercentage = 2.0

-- Also valid but less common
local ClosePrices = ClosePrices()  -- Very bad! Overwrites built-in function!
local RSIValue = RSI(ClosePrices(), 14)

PascalCase for Custom Commands

-- Custom commands typically use PascalCase
DefineCommand("MyCustomIndicator", "Description here")
DefineCommand("CalculateEntrySignal", "Entry signal calculator")

Common Case Sensitivity Mistakes

Mixing Up Similar Variable Names

-- Confusing: Variables differ only by case
local price = CurrentPrice()
local Price = CurrentPrice()
local PRICE = CurrentPrice()

-- Better: Use descriptive, distinct names
local currentPrice = CurrentPrice()
local entryPrice = CurrentPrice()
local targetPrice = CurrentPrice()

Inconsistent Command Capitalization

-- Error: Inconsistent capitalization
local rsi = RSI(ClosePrices(), 14)
local sma = Sma(ClosePrices(), 20)  -- Error: should be SMA
local ema = EmA(ClosePrices(), 20)  -- Error: should be EMA

-- Correct: Consistent capitalization
local rsi = RSI(ClosePrices(), 14)
local sma = SMA(ClosePrices(), 20)
local ema = EMA(ClosePrices(), 20)

Wrong Signal Constants

-- Error: Wrong case
if signal == signallong then  -- Error
    DoLong()
end

-- Correct: Proper capitalization
if signal == SignalLong then
    DoLong()
end

String Literals

Strings in quotes are case-sensitive:

local message = "Hello"
local MESSAGE = "HELLO"
local Message = "Hello"

-- These are DIFFERENT strings
Log(message)  -- Outputs: Hello
Log(MESSAGE)  -- Outputs: HELLO
Log(Message)  -- Outputs: Hello

This matters when comparing string values:

local signal = "Long"

-- This condition is FALSE (case mismatch)
if signal == "long" then
    DoLong()
end

-- This condition is TRUE (exact match)
if signal == "Long" then
    DoLong()
end

Input Field Labels

Input field labels are strings and are case-sensitive:

local rsiPeriod = Input("RSI Period", 14)
local rsiPeriod2 = Input("rsi period", 14)
local rsiPeriod3 = Input("RSI PERIOD", 14)

-- These create THREE DIFFERENT input fields due to different casing

However, HaasScript can handle multiple input fields with the same label without issues:

-- This works fine - three separate input fields
local rsiPeriod = Input("RSI Period", 7)
local rsiPeriod2 = Input("RSI Period", 14)
local rsiPeriod3 = Input("RSI Period", 21)

-- Each variable gets its correct value
-- The underlying system distinguishes between them automatically

While this won't break anything, it can be confusing. Consider using descriptive labels when you have multiple similar inputs:

-- Clearer: Different labels for different purposes
local fastRsiPeriod = Input("Fast RSI Period", 7)
local slowRsiPeriod = Input("Slow RSI Period", 14)
local signalRsiPeriod = Input("Signal RSI Period", 21)

Best Practices

1. Use Consistent Naming

-- Good: Consistent camelCase
local closePrices = ClosePrices()
local rsiValue = RSI(ClosePrices(), 14)
local macdSignal = MACD(ClosePrices(), 12, 26, 9)

-- Avoid: Inconsistent capitalization
local closePrices = ClosePrices()
local RSIValue = RSI(ClosePrices(), 14)
local MacdSignal = MACD(ClosePrices(), 12, 26, 9)

2. Match Command Names Exactly

-- Always use exact command capitalization
RSI()
SMA()
EMA()
DoLong()
DoShort()
StopLoss()
TakeProfit()

-- Never use variations - unless you defined them yourself
rsi()
sma()
ema()
dolong()
doshort()
stoploss()
takeprofit()

3. Be Careful with String Comparisons

-- Good: Use exact string matching
local signal = "Long"
if signal == "Long" then
    DoLong()
end

-- Better: Use signal constants when viable
local signal = SignalLong
if signal == SignalLong then
    DoLong()
end

4. Avoid Confusing Variable Names

-- Bad: Too similar, easy to confuse
local price = 100
local Price = 200
local PRICE = 300

-- Good: Distinct, descriptive names
local entryPrice = 100
local exitPrice = 200
local targetPrice = 300

Troubleshooting Case Sensitivity Errors

"Function not found" or "Command not found"

If you get these errors, check the capitalization:

-- Error: Unknown references: rsi
local rsi = rsi(ClosePrices(), 14)

-- Fix: Use correct capitalization
local rsi = RSI(ClosePrices(), 14)

"Variable not defined" or "Variable is nil"

-- Error: Unknown references: MyValue
local myValue = 10
Log(MyValue)  -- Wrong case!

-- Fix: Use exact variable name
local myValue = 10
Log(myValue)

Unexpected behavior with strings

-- Problem: String comparison fails
local market = "BTC_USDT"
if market == "btc_usdt" then  -- This will be false
    DoLong()
end

-- Fix: Match case exactly
local market = "BTC_USDT"
if market == "BTC_USDT" then
    DoLong()
end

Quick Reference

Category Convention Example
Variables camelCase local myValue = 10
Built-in Commands PascalCase RSI(), SMA(), DoLong()
Custom Commands PascalCase MyCustomCommand()
Signal Constants PascalCase SignalLong, SignalShort
Data Types PascalCase NumberType, EnumType
Strings Exact match "Long""long"

Summary

  • HaasScript is case-sensitive - uppercase and lowercase are different
  • Match exact command names - RSI() not rsi()
  • Use consistent naming conventions - camelCase for variables, PascalCase for commands
  • Be careful with string comparisons - "Long""long"
  • Avoid confusing variable names - Don't use names that differ only by case

Following these rules will prevent common errors and make your code more readable and maintainable.