Bollinger Bands
Bollinger Bands consist of a moving average and two deviation bands that measure market volatility.
Role in the strategy
| Slot | Available | Role |
|---|---|---|
| Entry Point | Yes | Enters at the upper or lower band. |
| Entry Rule | Yes | Filters entries by the bar open or proposed entry price relative to the bands. |
| Exit Point | Yes | Exits at the upper or lower band. |
| Exit Rule | Yes | Triggers exits by the bar open position relative to the bands. |
As a point indicator the bands are the pending order levels; as a rule the indicator filters entries (AND) or triggers exits (OR). See Indicators for the slot semantics.
As an exit point it places a resting order the bar reaches, so it allows no exit rules: Exit Rules are available only behind Bar Open or Bar Close.
Logic rules
- Entry Point: Enter long at Upper Band, Enter long at Lower Band.
- Exit Point: Exit long at Upper Band, Exit long at Lower Band.
- Rule slots:
| Rule | Long order price | Short order price |
|---|---|---|
| Enter/Exit long at Upper Band | Upper Band | Lower Band |
| Enter/Exit long at Lower Band | Lower Band | Upper Band |
- Entry Rule / Exit Rule:
| Rule | Long signal is 1 when | Short signal is 1 when |
|---|---|---|
| The bar opens above Upper Band | bar open is above the upper band | bar open is below the lower band |
| The bar opens below Lower Band | bar open is below the lower band | bar open is above the upper band |
| The bar opens below Upper Band after opening above it | bar open fell back below the upper band | bar open rose back above the lower band |
| The bar opens above Upper Band after opening below it | bar open rose above the upper band | bar open fell below the lower band |
| The bar opens below Lower Band after opening above it | bar open fell below the lower band | bar open rose above the upper band |
| The bar opens above Lower Band after opening below it | bar open rose above the lower band | bar open fell below the upper band |
| The bar closes above Upper Band | bar close is above the upper band | bar close is below the lower band |
| The bar closes below Lower Band | bar close is below the lower band | bar close is above the upper band |
| The bar closes below Upper Band after closing above it | bar close fell back below the upper band | bar close rose back above the lower band |
| The bar closes above Upper Band after closing below it | bar close rose above the upper band | bar close fell below the lower band |
| The bar closes below Lower Band after closing above it | bar close fell below the lower band | bar close rose above the upper band |
| The bar closes above Lower Band after closing below it | bar close rose above the lower band | bar close fell below the upper band |
The six The bar closes rules are exit-only (Exit Rules): they compare the close of the bar the rule reads with the band of that same bar. Behind a Bar Open exit the read bar is the last completed bar; behind a Bar Close exit it is the bar being closed. The open family keeps its own reference — the bar open at the execution moment against the band of the read bar — so the wording, not the slot, says which bar a rule judges.
Entry-only rules are The position opens above/below Upper Band and The position opens above/below Lower Band. The rule text describes the long order; shorts reverse the inequality and compare with the opposite band (for example, above Upper Band checks the lower band for a short). These rules compare the proposed order price to the raw band using a strict half-point dead zone.
Parameters
| Parameter | Type | Default | Range | Purpose |
|---|---|---|---|---|
| Apply to | select | Close | Open, High, Low, Close, Median, Typical, Weighted | Price series the bands are calculated from |
| Period | number | 20 | 2 to 1000 | Bars of the moving average and the deviation |
| Deviation | number | 2 | 1 to 5 | Standard deviation multiplier for the bands |
Calculation
tech.Bands in engine/indicator-engine/tech.ts computes the three lines:
- Middle Band: simple moving average of the selected price over the Period.
- Upper Band: middle band plus Deviation standard deviations.
- Lower Band: middle band minus Deviation standard deviations.
The three lines are drawn on the main price chart.
Backtesting
- Rules are evaluated on the previous (closed) bar with the standard dead zone when the governing point executes at the bar open (a Bar Open entry, or a point evaluated at the bar opening). When the point executes at the bar close (a Bar Close exit), its rules read the current bar instead: the backtester evaluates them on the completed bar, and the exported EA re-evaluates them at the Bar Close event (the near-final bar). A The bar closes rule always reads the close and the band of the same bar, so the open-price relaxation never shortens it.
- As an entry point, the pending orders sit at the band levels; the long and short levels differ, so both orders can be placed and the intrabar interpolation decides which side fills first when both levels are inside the bar.
- Scenario selection follows the entry/exit pairing in the Indicators index: IndicatorOpen, IndicatorClose, IndicatorIndicator, or OpenIndicator.
- As a rule the indicator contributes only long/short signals — it never changes the order price.