> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Strategies and backtesting

> Declaring a strategy, the arguments that set its account, sizing and costs, and what a strategy does and does not do.

A strategy declares itself with `strategy(...)` instead of `indicator(...)` and places orders with the `strategy.*` functions. The orders are simulated: a built-in broker emulator fills them against the chart's bars on a simulated account. Nothing is sent to a real broker.

> [!WARNING]
>
> GoCharting is a charting and analytics tool. This is not investment advice. Trading and investing carry a high risk of loss and are not suitable for everyone. You can lose some or all of your money.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
strategy("Average cross", overlay=true, initial_capital=10000, default_qty_value=2, commission_value=0.1)
fast = talib.sma(close, 10)
slow = talib.sma(close, 30)
if talib.crossover(fast, slow) {
    strategy.entry("Long", strategy.long)
}
if talib.crossunder(fast, slow) {
    strategy.close("Long")
}
plot(fast, title="Fast")
plot(slow, title="Slow")
```

The script runs once per bar; order calls may sit in `if`, loops and functions. See [Orders and positions](https://gocharting.com/docs/scripting/strategies/orders-and-positions.md) for fills and [Reading a strategy's results](https://gocharting.com/docs/scripting/strategies/strategy-results.md) for the account variables. In an `indicator()` script the order calls and `strategy.*` variables compile but do nothing.

## The declaration

`strategy(title, ...)` is called once at the top level; only `title` is required and every argument is `const`. The display arguments (`shorttitle`, `overlay`, `format`, `precision`, `scale`, `max_*_count`, `behind_chart`) are those of `indicator()`. The account arguments:

| Argument | Default | Meaning |
| - | - | - |
| `initial_capital` | 1000000 | Starting equity. |
| `default_qty_type` | `strategy.fixed` | `default_qty_value` as units (`strategy.fixed`), or as money (`"cash"`) or percent of equity (`"percent_of_equity"`) divided by a price. `strategy.cash` does not exist; the strings compile, but the price is the order's `limit` or `stop`, so an order with neither and no `qty` stops the script: `Invalid order quantity`. Use `strategy.fixed`, or pass `qty`. |
| `default_qty_value` | 1 | Size of an order with no `qty`. |
| `commission_type` | `strategy.commission_percent` | Or `strategy.commission_cash_per_order`, `strategy.commission_cash_per_contract`. |
| `commission_value` | 0 | Charged when a trade opens and when it closes; as a percent, 0.1 is 0.1%. |
| `pyramiding` | 1 | Open entries allowed in one direction. |
| `process_orders_on_close` | false | Also fill orders at the close of the bar that placed them. |
| `calc_on_order_fills` | false | Run the script again within the bar after an order fills. |
| `calc_on_every_tick` | false | On a forming realtime bar, run on every tick, not at the close. |

These values are not checked (`pyramiding=0` compiles). There is no slippage, margin or currency argument.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.