Skip to content
TradequixDocsOpen the terminal
OverviewStart here, search, progress
  • Introduction
  • Quickstart
  • How a script runs
  • Types and qualifiers
  • Operators, conditionals and loops
  • Functions and methods
  • Objects and enums
  • Arrays, matrices and maps
  • Strings and colours
  • Time and sessions
  • Bar states
  • Plotting
  • Inputs
  • Technical analysis
  • Drawings and tables
  • Multiple timeframes
  • Strategies
  • Alerts in scripts
  • Repainting
  • The Pine editor
  • Indicator settings
  • Coming from TradingView
  • The data
  • Publish and sell
  • Catalogue and community
  • Your dashboard and earnings
  • Errors and debugging
  • Limits
  • Coverage
  • Built-in catalogue
  • Cookbook
  • Write Pine with AI
  • FAQ
  • Glossary
  • Cheat sheet
  • Function reference
  • Will it run here?
  • Error index

Write

Strategies

Turn signals into simulated trades with strategy(), read the backtest panel, and understand what each metric does and does not tell you.

View as MarkdownOpen in ClaudeOpen in ChatGPT

An indicator draws. A strategy also places simulated orders, and Tradequix shows the resulting backtest: trades on the chart and a results panel with profit, drawdown and win rate.

Declare strategy(...) instead of indicator(...), then use strategy.entry, strategy.close and strategy.exit.

RunnableEMA cross with stops
1//@version=62strategy("EMA cross with stops", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)3fast = ta.ema(close, 12)4slow = ta.ema(close, 26)5atr = ta.atr(14)6plot(fast, "Fast", color = color.teal)7plot(slow, "Slow", color = color.red)8if ta.crossover(fast, slow)9 strategy.entry("Long", strategy.long)10if ta.crossunder(fast, slow)11 strategy.entry("Short", strategy.short)12strategy.exit("Long exit", "Long", stop = close - 2 * atr, limit = close + 3 * atr)13strategy.exit("Short exit", "Short", stop = close + 2 * atr, limit = close - 3 * atr)

Orders#

CallDoes
strategy.entry(id, direction)Opens or adds to a position; an opposite entry reverses it
strategy.close(id)Closes the position opened by entry id at market
strategy.close_all()Closes everything
strategy.exit(id, from_entry, stop, limit)Attaches a stop loss and/or take profit to an entry
strategy.order(...)A raw order, without entry's reversal logic

Orders fill on the next bar's open by default, which is how a real order placed at the close would behave.

Settings that change results#

Arguments to strategy() that matter most: initial_capital, default_qty_type and default_qty_value (position size), pyramiding (how many entries may stack), commission_type / commission_value, and slippage. Leave commission at zero and a scalping strategy will look far better than it is.

Reading the results panel#

MetricMeaning
Net profitThe result of closed trades
ReturnNet profit as a percentage of initial capital
Max drawdownThe largest fall from a peak in equity, in money and percent
TradesHow many trades closed
Win rateThe share of closed trades that made money
Gross +/−Total won and total lost, separately
Sharpe / SortinoRisk-adjusted return, computed from monthly returns

Each trade's entry and exit is also drawn on the chart, so you can see where the strategy acted.

Note

Sharpe and Sortino show 0 until there is enough monthly history to compute them. On a 5-second or 1-minute chart that can mean never. Read 0 as "not enough data", not "no edge".

Before you trust a backtest#

  • Run it on more than one pair and more than one timeframe.
  • Add commission and slippage that match how you would actually trade.
  • Check it does not use future data. A strategy that reads close and enters on the same bar's close, or uses request.security with lookahead on the current bar, can look perfect and never work live.
  • History on a short timeframe is short. A great result over 300 bars of 5-second data is a few minutes of market.
PreviousMultiple timeframesNext Alerts in scripts

On this page

  • Orders
  • Settings that change results
  • Reading the results panel
  • Before you trust a backtest

Use with AI

View as MarkdownOpen in ClaudeOpen in ChatGPT