BLAZESCRIPT / LANGUAGE DOCUMENTATION
Getting Started with BlazeScript
BlazeScript is the trading strategy scripting language used in Cipher AI by TestAlgo. Use it to define entry signals, exit rules, indicators and chart visuals. It uses Python-like syntax and platform-provided functions and data.
Getting started
A project uses entry_logic.ta, exit_logic.ta and canvas.ta. Entry logic defines a signal and registers an Entry call. Exit logic can use entry variables and registers Exit. Canvas code can use entry and exit variables to draw results. The examples below reproduce the current website examples without modifying their syntax.
entry_logic.ta
# --- entry_logic.ta ---
# Pythonic execution. No imports required.
fast_ema = EMA(close, 9)
slow_ema = EMA(close, 21)
# Simple crossing over strategy
long_condition = crossover(fast_ema, slow_ema)
# Keyword vars for action, string for order_type
Entry(index=1, logic=long_condition, timeframe="5m", script=banknifty_spot, action=Buy, order_type="MARKET")exit_logic.ta
# --- exit_logic.ta ---
# Variables declared in entry_logic (fast_ema, slow_ema) are natively accessible here.
# Multiple Exit Conditions
stop_loss = open_pnl < -500
take_profit = open_pnl > 1500
trend_reversal = crossunder(fast_ema, slow_ema)
# Combine logic
exit_signal = stop_loss | take_profit | trend_reversal
# Top-level exit call
Exit(index=1, logic=exit_signal, exit_type="MARKET")canvas.ta
# --- canvas.ta ---
# Variables from entry & exit logic flow directly into canvas scope.
# Paint the chart background green while Fast EMA is above Slow EMA
debug_paint_background(fast_ema > slow_ema, frame=0, color="rgba(0, 255, 0, 0.1)")
# Draw standard indicators on the main chart (frame=0)
draw(fast_ema, title="Fast 9 EMA", frame=0, color="blue")
draw(slow_ema, title="Slow 21 EMA", frame=0, color="orange")
# Display trade execution visuals natively
marker_trades(frame=0, show_pnl=True, show_signal_line=True)Common mistakes and documentation limits
- Check a function name, capitalization and argument list against this reference before generating code. A grouped reference entry may describe multiple names.
- Resolve missing names using the built-in variable reference or the strategy setup. Instrument names such as RELIANCE and banknifty_spot are example context, not user-defined strings.
- The source examples are inconsistent about Entry timeframe: the introductory project uses "5m", while library examples use numbers such as 5 and 15. Confirm the accepted format in your installed Cipher AI runtime; this page does not silently choose a format.
- Some snippets are partial demonstrations with inputs defined elsewhere. Do not present every snippet as a standalone program.
- The current website reference does not provide a compiler error-code catalog or a version compatibility matrix. Do not invent error codes or claim examples were executed merely because they appear here.