Strategies

## Strategies

A script declared with `strategy("Title", ...)` places simulated orders with `strategy.entry`, `strategy.exit`,
`strategy.close`, `strategy.close_all`, `strategy.order`, `strategy.cancel` and reads its position and results with
`strategy.position_size`, `strategy.equity`, `strategy.closedtrades.*` and the other strategy values.
- Orders given on a bar are placed at its close and fill from the next bar: market orders at its open, stops and
  limits when its range reaches them. Inside one bar the worse case counts: a stop before a target, and a target
  of an entry that filled inside the bar waits for the next bar. The script on the next bar sees the fills.
- `strategy.entry` reverses an opposite position and keeps at most `pyramiding` entries in one direction;
  calling it again with the same id replaces a waiting order. `strategy.exit` puts a stop and / or target on an
  entry's position (prices with stop= / limit=, ticks from the fill with loss= / profit=); call it every bar to
  move them. A trailing stop: `trail_offset` ticks behind the best price, starting at `trail_price` or
  `trail_points` ticks in profit (at once with neither); it works from the bar after it starts. `qty` or
  `qty_percent` close part of the position (an exit is used up once one of its orders fills).
- `strategy.entry` with both `stop` and `limit` is a stop-limit order. Entries with the same `oca_name` are
  one-cancels-all: the first to fill cancels the others (a buy stop and a sell stop around a range).
- One position per symbol: a trade runs from flat to flat (`strategy.opentrades.*(0)` describes it).
  `default_qty_value` is contracts, or with `default_qty_type=strategy.percent_of_equity` / `strategy.cash` a
  percent of equity / dollars turned into whole contracts at the close price. Commission is dollars per contract
  per side, slippage in ticks. `process_orders_on_close=true` fills market orders at the close of their bar.

```lynt
strategy("MA cross", overlay=true, commission_value=2.5, slippage=1)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
    strategy.entry("Short", strategy.short)
strategy.exit("Exit L", "Long", profit=40, loss=20)
strategy.exit("Exit S", "Short", profit=40, loss=20)
plot(fast)
plot(slow)
```