DSL Grammar
Overview
Vaanam DSL (Domain Specific Language) is a powerful query language designed for financial data analysis, backtesting, and screening. It provides a natural way to express complex trading conditions using technical indicators, price data, and logical operations.
The Vaanam DSL is a declarative language for expressing market conditions, not a programming language.
Expression Types
The DSL supports two main expression types:
- Logical Expressions: Boolean conditions using AND/OR operators
- Mathematical Expressions: Arithmetic operations and comparisons
Operators
Logical Operators
AND- Logical AND operationOR- Logical OR operation
Comparison Operators
<- Less than>- Greater than<=- Less than or equal to>=- Greater than or equal to==- Equal to!=- Not equal to
Arithmetic Operators
+- Addition-- Subtraction*- Multiplication/- Division%- Modulo
Grouping
()- Parentheses for grouping expressions
Data Types
Numbers
- Integer:
14,20,100 - Decimal:
0.02,2.5,30.0
Identifiers
Technical indicators, price data, and special variables follow specific naming conventions.
Asset Data Structure
All data references follow the pattern: ASSET_[SYMBOL]_[CATEGORY]_[INDICATOR]_[PARAMETERS]
Asset Categories
Basic Price Data
ASSET_STOCK_OPEN- Opening priceASSET_STOCK_HIGH- High priceASSET_STOCK_LOW- Low priceASSET_STOCK_CLOSE- Closing priceASSET_STOCK_VOLUME- Trading volume
Technical Indicators
Format: ASSET_STOCK_TECH_[INDICATOR]_[PARAMETERS]
Supported Technical Indicators
Moving Averages
-
SMA (Simple Moving Average)
- Format:
ASSET_STOCK_TECH_SMA_[PRICE_TYPE]_[PERIOD] - Example:
ASSET_STOCK_TECH_SMA_C_20(20-period SMA of closing price)
- Format:
-
EMA (Exponential Moving Average)
- Format:
ASSET_STOCK_TECH_EMA_[PRICE_TYPE]_[PERIOD] - Example:
ASSET_STOCK_TECH_EMA_C_50(50-period EMA of closing price)
- Format:
-
WMA (Weighted Moving Average)
- Format:
ASSET_STOCK_TECH_WMA_[PRICE_TYPE]_[PERIOD] - Example:
ASSET_STOCK_TECH_WMA_C_10(10-period WMA of closing price)
- Format:
-
HMA (Hull Moving Average)
- Format:
ASSET_STOCK_TECH_HMA_[PRICE_TYPE]_[PERIOD] - Example:
ASSET_STOCK_TECH_HMA_C_20(20-period HMA of closing price)
- Format:
-
DEMA (Double Exponential Moving Average)
- Format:
ASSET_STOCK_TECH_DEMA_[PRICE_TYPE]_[PERIOD] - Example:
ASSET_STOCK_TECH_DEMA_C_20(20-period DEMA of closing price)
- Format:
-
TEMA (Triple Exponential Moving Average)
- Format:
ASSET_STOCK_TECH_TEMA_[PRICE_TYPE]_[PERIOD] - Example:
ASSET_STOCK_TECH_TEMA_C_20(20-period TEMA of closing price)
- Format:
-
T3 (T3 Moving Average)
- Format:
ASSET_STOCK_TECH_T3_[PRICE_TYPE]_[PERIOD]_[VFACTOR] - Example:
ASSET_STOCK_TECH_T3_C_20_0.7(20-period T3 with volume factor 0.7) - The vfactor parameter controls smoothing (default 0.7)
- Format:
Oscillators
-
RSI (Relative Strength Index)
- Format:
ASSET_STOCK_TECH_RSI_[PRICE_TYPE]_[PERIOD] - Example:
ASSET_STOCK_TECH_RSI_C_14(14-period RSI)
- Format:
-
STOCH (Stochastic Oscillator)
- Format:
ASSET_STOCK_TECH_STOCH_[FASTK]_[SLOWK]_[SLOWD]_[LINE] - Example:
ASSET_STOCK_TECH_STOCH_14_3_3_K(Stochastic %K line) - Lines:
KorD
- Format:
-
CCI (Commodity Channel Index)
- Format:
ASSET_STOCK_TECH_CCI_[PERIOD] - Example:
ASSET_STOCK_TECH_CCI_20
- Format:
-
MFI (Money Flow Index)
- Format:
ASSET_STOCK_TECH_MFI_[PERIOD] - Example:
ASSET_STOCK_TECH_MFI_14
- Format:
Volatility Indicators
-
ATR (Average True Range)
- Format:
ASSET_STOCK_TECH_ATR_[PERIOD] - Example:
ASSET_STOCK_TECH_ATR_14
- Format:
-
BBANDS (Bollinger Bands)
- Format:
ASSET_STOCK_TECH_BBANDS_[PERIOD]_[DEVIATION]_[BAND] - Example:
ASSET_STOCK_TECH_BBANDS_20_2.0_UPPER - Bands:
UPPER,MIDDLE,LOWER
- Format:
-
STDEV (Standard Deviation)
- Format:
ASSET_STOCK_TECH_STDEV_[PRICE_TYPE]_[PERIOD] - Example:
ASSET_STOCK_TECH_STDEV_C_20
- Format:
Trend Indicators
-
ADX (Average Directional Index)
- Format:
ASSET_STOCK_TECH_ADX_[PERIOD] - Example:
ASSET_STOCK_TECH_ADX_14
- Format:
-
ADXR (ADX Rating)
- Format:
ASSET_STOCK_TECH_ADXR_[PERIOD] - Example:
ASSET_STOCK_TECH_ADXR_14
- Format:
-
AROON (Aroon Indicator)
- Format:
ASSET_STOCK_TECH_AROON_[PERIOD]_[LINE] - Example:
ASSET_STOCK_TECH_AROON_14_UP - Lines:
UPorDOWN
- Format:
-
SAR (Parabolic SAR)
- Format:
ASSET_STOCK_TECH_SAR_[ACCELERATION]_[MAXIMUM] - Example:
ASSET_STOCK_TECH_SAR_0.02_0.2
- Format:
MACD (Moving Average Convergence Divergence)
- Format:
ASSET_STOCK_TECH_MACD_[FAST]_[SLOW]_[SIGNAL]_[LINE] - Example:
ASSET_STOCK_TECH_MACD_12_26_9_MACD - Lines:
MACD,SIGNAL,HIST
Volume Indicators
-
OBV (On-Balance Volume)
- Format:
ASSET_STOCK_TECH_OBV_[PERIOD] - Example:
ASSET_STOCK_TECH_OBV_10
- Format:
-
ADOSC (Chaikin A/D Oscillator)
- Format:
ASSET_STOCK_TECH_ADOSC_[FAST]_[SLOW] - Example:
ASSET_STOCK_TECH_ADOSC_3_10
- Format:
Other Indicators
-
ROC (Rate of Change)
- Format:
ASSET_STOCK_TECH_ROC_[PRICE_TYPE]_[PERIOD] - Example:
ASSET_STOCK_TECH_ROC_C_10
- Format:
-
BOP (Balance of Power)
- Format:
ASSET_STOCK_TECH_BOP - Example:
ASSET_STOCK_TECH_BOP(no parameters required)
- Format:
-
PIVOTHIGH (Pivot High Detection)
- Format:
ASSET_STOCK_TECH_PIVOTHIGH_[LEFT_BARS]_[RIGHT_BARS] - Example:
ASSET_STOCK_TECH_PIVOTHIGH_5_2(5 bars left, 2 bars right) - Returns the high price at pivot points, NaN otherwise
- Format:
-
PIVOTLOW (Pivot Low Detection)
- Format:
ASSET_STOCK_TECH_PIVOTLOW_[LEFT_BARS]_[RIGHT_BARS] - Example:
ASSET_STOCK_TECH_PIVOTLOW_5_2(5 bars left, 2 bars right) - Returns the low price at pivot points, NaN otherwise
- Format:
-
VCEIL (Ceiling Function)
- Format:
ASSET_STOCK_TECH_VCEIL_[PERIOD] - Example:
ASSET_STOCK_TECH_VCEIL_14
- Format:
-
DONCHIAN (Donchian Channels)
- Format:
ASSET_STOCK_TECH_DONCHIAN_[PERIOD]_[BAND] - Example:
ASSET_STOCK_TECH_DONCHIAN_20_UPPER - Bands:
UPPER,MIDDLE,LOWER
- Format:
Price Type Codes
O- Open priceH- High priceL- Low priceC- Close priceV- Volume
Historical Data Modifiers
Previous Values
- PREV_[N]_ - Access data from N periods ago
- Example:
PREV_1_ASSET_STOCK_CLOSE(Previous day's closing price) - Example:
PREV_5_ASSET_STOCK_TECH_RSI_C_14(RSI from 5 periods ago)
- Example:
Statistical Functions
-
HIGH_[N]_ - Highest value over N periods
- Example:
HIGH_20_ASSET_STOCK_CLOSE(Highest close in last 20 periods) - Example:
HIGH_252_ASSET_STOCK_CLOSE(52-week high on daily timeframe)
- Example:
-
LOW_[N]_ - Lowest value over N periods
- Example:
LOW_20_ASSET_STOCK_CLOSE(Lowest close in last 20 periods)
- Example:
-
AVG_[N]_ - Average value over N periods
- Example:
AVG_10_ASSET_STOCK_VOLUME(Average volume over 10 periods) - Example:
AVG_20_ASSET_STOCK_VOLUME(20-day average volume)
- Example:
Consecutive Condition
- CONSECUTIVE_[N]_ - Requires a condition to be true for N consecutive bars
- Example:
CONSECUTIVE_3_ASSET_STOCK_TECH_RSI_C_14 < 30(RSI has been below 30 for 3 bars in a row) - Example:
CONSECUTIVE_5_ASSET_STOCK_CLOSE > ASSET_STOCK_TECH_SMA_C_50(Price above 50-SMA for 5 consecutive bars)
- Example:
Intraday Reference
- INTRA_[N]_ - References the Nth intraday candle
- Example:
INTRA_1_ASSET_STOCK_CLOSE(Close price of the first intraday candle) - Only meaningful on intraday timeframes (Pro plan required)
- Example:
Today's Session High / Low
Reference the session's running high or low up to the current bar. Useful for Opening Range Breakout (ORB) strategies.
- TODAY_HIGH_[OPERAND] — running max of the operand for the current day
- Example:
ASSET_STOCK_CLOSE > TODAY_HIGH_ASSET_STOCK_HIGH(breakout above today's highest high)
- Example:
- TODAY_LOW_[OPERAND] — running min of the operand for the current day
- Example:
ASSET_STOCK_CLOSE < TODAY_LOW_ASSET_STOCK_LOW(breakdown below today's lowest low)
- Example:
Once the regular market session starts (9:30 AM ET), pre-market bars are excluded from the calculation.
Entry-Time References
-
ENTRY_ - Captures the value of any indicator at the time a trade was opened
- Example:
ENTRY_ASSET_STOCK_TECH_ATR_14(ATR value when the trade was entered) - Use case: exit when ATR has changed significantly since entry
- Example:
-
ENTRY_PREV_[N]_ - Value of an indicator N candles before the trade entry
- Example:
ENTRY_PREV_3_ASSET_STOCK_LOW(Low price 3 candles before entry)
- Example:
Chart Pattern Indicators
Pattern indicators return numeric codes and can be used in DSL expressions like any other indicator.
| Pattern | Format | Return Codes |
|---|---|---|
| TRIANGLE | ASSET_STOCK_TECH_TRIANGLE_[BARS] | 0=none, 1=ascending, 2=descending, 3=symmetric |
| HNS (Head & Shoulders) | ASSET_STOCK_TECH_HNS_[BARS] | 0=none, 1=bearish, 2=inverse/bullish |
| DOUBLETOP | ASSET_STOCK_TECH_DOUBLETOP_[BARS] | 0=none, 1=detected |
| DOUBLEBOT | ASSET_STOCK_TECH_DOUBLEBOT_[BARS] | 0=none, 1=detected |
| VCP | ASSET_STOCK_TECH_VCP_[BARS] | 0=none, 1=bullish, 2=bearish |
| STAIRCASE | ASSET_STOCK_TECH_STAIRCASE_[BARS] | 0=none, 1=bullish staircase |
| POWERBASE | ASSET_STOCK_TECH_POWERBASE_[BARS] | 0=none, 1=bullish powerbase |
The [BARS] parameter is the pivot lookback window (e.g., 6, 8, 10).
Example usage:
ASSET_STOCK_TECH_TRIANGLE_6 == 1
Ascending triangle detected with 6-bar pivot lookback
ASSET_STOCK_TECH_HNS_8 == 2 AND ASSET_STOCK_TECH_RSI_C_14 < 40
Inverse head & shoulders with RSI confirmation
Special Variables
Trading Context Variables
BUY_PRICE- Entry price of the current open long position (exit queries only)SELL_PRICE- Entry price of the current open short position (exit queries only)
Important:
BUY_PRICEandSELL_PRICEare only valid in exit conditions. Using them in entry queries will cause an error, since no position is open yet at the time of entry evaluation.
Expression Examples
Simple Conditions
ASSET_STOCK_TECH_RSI_C_14 < 30
RSI below 30 (oversold condition)
ASSET_STOCK_CLOSE > ASSET_STOCK_TECH_SMA_C_20
Price above 20-period moving average
Complex Logical Expressions
ASSET_STOCK_TECH_RSI_C_14 < 30 AND ASSET_STOCK_VOLUME > AVG_10_ASSET_STOCK_VOLUME
RSI oversold AND volume above 10-day average
(ASSET_STOCK_TECH_MACD_12_26_9_MACD > ASSET_STOCK_TECH_MACD_12_26_9_SIGNAL) OR ASSET_STOCK_TECH_STOCH_14_3_3_K > 80
MACD bullish crossover OR Stochastic overbought
Mathematical Expressions
ASSET_STOCK_CLOSE / ASSET_STOCK_TECH_SMA_C_50 > 1.05
Price 5% above 50-day moving average
(ASSET_STOCK_HIGH - ASSET_STOCK_LOW) / ASSET_STOCK_CLOSE > 0.02
Daily range greater than 2% of closing price
Advanced Patterns
ASSET_STOCK_TECH_RSI_C_14 < 30 AND PREV_1_ASSET_STOCK_TECH_RSI_C_14 >= 30
RSI just crossed below 30
ASSET_STOCK_CLOSE > HIGH_20_ASSET_STOCK_CLOSE * 0.98
Price within 2% of 20-day high
Bollinger Bands Strategy
ASSET_STOCK_CLOSE < ASSET_STOCK_TECH_BBANDS_20_2.0_LOWER AND ASSET_STOCK_TECH_RSI_C_14 < 30
Price below lower Bollinger Band AND RSI oversold
Moving Average Crossover
ASSET_STOCK_TECH_SMA_C_10 > ASSET_STOCK_TECH_SMA_C_20 AND PREV_1_ASSET_STOCK_TECH_SMA_C_10 <= PREV_1_ASSET_STOCK_TECH_SMA_C_20
10-day SMA crosses above 20-day SMA
Usage in Trading Strategies
Entry Conditions
Define when to enter a position:
ASSET_STOCK_TECH_RSI_C_14 < 30 AND ASSET_STOCK_CLOSE > ASSET_STOCK_TECH_SMA_C_50
Exit Conditions
Define when to exit a position:
ASSET_STOCK_TECH_RSI_C_14 > 70 OR ASSET_STOCK_CLOSE < ASSET_STOCK_TECH_SMA_C_20
Price Execution
Specify execution prices using basic price data:
- Entry:
ASSET_STOCK_OPEN - Exit:
ASSET_STOCK_CLOSE
Usage in Stock Screening
Filter stocks based on criteria:
ASSET_STOCK_TECH_RSI_C_14 < 30 AND ASSET_STOCK_VOLUME > AVG_20_ASSET_STOCK_VOLUME * 1.5
Best Practices
Performance Optimization
- Use specific periods: Avoid very long lookback periods unless necessary
- Combine conditions efficiently: Group related conditions with AND/OR appropriately
- Limit complexity: Break complex expressions into simpler components
Common Patterns
- Trend Following: Combine price and moving average conditions
- Mean Reversion: Use oscillators like RSI and Bollinger Bands
- Momentum: Incorporate volume and rate of change indicators
- Confirmation: Use multiple indicators to confirm signals
Tips for Writing Expressions
- Ensure sufficient historical data for indicator calculations
- Use appropriate parameter ranges (e.g., RSI periods > 0)
- Group complex conditions with parentheses for clarity
- Test expressions with different market conditions
Important Notes
- Data Requirements: Indicators need sufficient historical data to calculate properly
- Calculation Periods: Some indicators require warm-up periods before producing valid values
- Market Focus: Currently optimized for equity markets and standard technical indicators
© 2026 Vaanam, Inc. All rights reserved.