# Write a strategy you can read out loud.

> A strategy is a set of rules that buy, sell and look after trades. In AlgoBarsX a whole strategy fits on one screen, and anyone on your team can read it.

Source: https://algobarsx.com/strategies/

## A full strategy. Twelve lines.

This one buys when a fast average crosses above a slow one. It risks 1% of the account. It sets a stop and a target. It closes on the opposite cross.

- The risk, the stop and the target sit on the order line
- The compiler checks names and units before anything runs
- The same script is tested, replayed and run live

```algobarsx
strategy "EMA Cross"
    market: EURUSD
    bars: 15m

input fast = 20
input slow = 50

when crosses_above(ema(close, fast), ema(close, slow)):
    buy risk: 1%, stop: 25 pips, target: 2R

when crosses_below(ema(close, fast), ema(close, slow)):
    close_all
```

The compiler reads it back:

> When the EMA of the close over `fast` bars crosses above the EMA of the close over `slow` bars, it buys at market, risking 1% of the balance, with a stop 25 pips from the entry and with a target 2R from the entry.

> When the EMA of the close over `fast` bars crosses below the EMA of the close over `slow` bars, it closes all trades.

## Everything a real strategy needs.

All of it is part of the language. Nothing to install.

- **Size by risk** Say how much you are willing to lose, as a percent or as money. The lot size is worked out for you and rounded down. [Read more](https://algobarsx.com/docs/sizing/)
- **Look after the trade** Move the stop to breakeven. Close part at a level. Trail the rest. Exit after a number of bars. [Read more](https://algobarsx.com/docs/trade-management/)
- **Name your confirmations** List what a setup needs. Ask for all of them, or at least three of five. The report shows which ones earned their place. [Read more](https://algobarsx.com/docs/confirmations/)
- **Setups in steps** Sweep, reclaim, retest. A sequence waits for each step in order and resets if the idea breaks. [Read more](https://algobarsx.com/docs/sequences/)
- **Say when a rule may fire** Every 4th time. At most 2 a day. A 30-minute cooldown. Only in the London session. [Read more](https://algobarsx.com/docs/rules/)
- **Set hard limits** Cap open trades, daily loss and drawdown at the top of the script. When the daily limit is hit, trading stops for the day. [Read more](https://algobarsx.com/docs/guards/)

## Manage a trade after you are in.

Management lines sit under the order they belong to. The plan for the trade is in one place.

```algobarsx
when liquidity_grab.completed from 08:00 to 11:00 Europe/London:
    buy risk: 1%, stop: liquidity_grab.sweep.low - 3 points, target: 2R + 5 pips, tag: "breakout":
        breakeven at: 1R, offset: 2 pips
        partial 30% at: 1.5R
        partial 30% at: 2.5R
        trail by: atr(14), after: 2R
        exit after: 48 bars
        exit when: crosses_below(close, ema(close, 20))
```


## From idea to a running strategy.

1. **Write it, or describe it** Type the rules. Or write your idea in plain English and press Convert to AlgoBarsX.
2. **Test it and watch it** Pick the market, the bar size and how far back. Read the report. Watch the test play back trade by trade.
3. **Run it where you choose** Start it on a demo or a live account. You pick the market and the trade size when you start it.

> **About tests.** A test uses past prices. It leaves out spread, fees, swaps and slippage, so real results will differ. When one bar hits both your stop and your target and the data cannot show which came first, the test counts the stop. A good test does not mean you will make money.

## Learn by example.

- [EMA Cross](https://algobarsx.com/docs/ex-01-ema-cross/)
- [Six-Confirmation Momentum](https://algobarsx.com/docs/ex-02-six-confirmation-momentum/)
- [London Open Breakout](https://algobarsx.com/docs/ex-13-london-open-breakout/)
- [Pairs Mean Reversion](https://algobarsx.com/docs/ex-05-pairs-mean-reversion/)
- [Smart Money Pullback](https://algobarsx.com/docs/ex-36-smart-money-pullback/)
- [All examples](https://algobarsx.com/docs/#examples)

## Good questions.

**Do I need to know how to code?** No. The code reads like plain words, it reads itself back in English, and you can type your idea in plain English and press Convert to AlgoBarsX.

**Will live results match a backtest?** No. Tests use past prices and leave out spread, fees, swaps and slippage. Past results do not tell you what will happen next.

**Can one strategy trade more than one market?** Yes. List them under `markets:` in the header. You can also start the same script on a different market when you deploy it.

**Does AlgoBars hold client money?** No. AlgoBars is software, not a broker. It links to accounts at supported brokers. It never holds money and it does not give advice.

## Important

Trading is risky and you can lose money. AlgoBars is software, not a broker or an adviser. Backtests are hypothetical and leave out spread, fees, swaps and slippage. AlgoBarsX is in beta.
