Vaanam Script Overview
Vaanam Script is a programming language for writing trading strategies that run inside the Vaanam backtester. Where the rule builder lets you express "enter when RSI < 30" by filling in fields, Vaanam Script lets you write the full logic of a strategy as code — loops, conditions, persistent state, custom indicators, multi-symbol rules, and precise control over how and when orders fill.
If you've used TradingView's Pine Script, you'll feel at home: same series-based model, similar ergonomics. The block structure is Python-style (indentation and colons).
A complete strategy
//@version=1
strategy("RSI Mean Reversion", timeframe="1D")
length = input.int(14, "RSI Length")
rsi = ta.rsi(close, length)
if position.size == 0 and rsi < 30:
strategy.enter_long(size_pct=100)
if position.size > 0 and rsi > 70:
strategy.close_all()
That's a full, runnable strategy: buy when RSI drops below 30, sell when it rises above 70.
When to use Vaanam Script
Use the rule builder for straightforward entry/exit conditions you can express as a few comparisons.
Reach for Vaanam Script when you need:
- Custom logic — indicators computed from primitives, multi-step conditions, loops over recent bars.
- Persistent state — trailing stops, "bars since entry", one-trade-per-day gates.
- Precise fills — choose whether an order fills at the next open, this bar's close, etc.
- Fixed (non-compounding) sizing — always trade a fixed dollar amount or share count.
- Multi-timeframe — reference a higher timeframe (e.g. the weekly trend) from a daily strategy, with no look-ahead.
- Per-symbol rules — different logic for different tickers in one strategy.
How a script runs
- You choose a universe of tickers (one symbol, a basket, or a whole index) and a timeframe.
- The backtester runs your script once per ticker, bar by bar, in chronological order.
- On each bar, your code sees the latest
close/open/high/low/volumeand can read indicators, check the currentposition, and queue orders withstrategy.enter_long/close_all/ etc. - The backtester fills those orders, tracks your shared cash and positions, and produces the same results view (equity curve, trades, metrics) as the rule builder.
Because the script runs per ticker, close always means "the current ticker's
close." To apply different rules to different symbols in one script, branch on
syminfo.ticker.
Next steps
- Language Reference — syntax: variables, control flow, operators, functions.
- Built-in Namespaces — every built-in:
ta,strategy,position,input,time,math,external,htf,syminfo. - Examples — complete strategies you can adapt.