Three-Channel Contract Breakout Teaching Strategy (Static / Bollinger Bands / ATR)
Three-Channel Contract Breakout Teaching Strategy (Static / Bollinger Bands / ATR)
Notice: This strategy is provided only for learning, code review and functional testing. Breakout signals can fail, and contract leverage magnifies both gains and losses. Before production use, verify the exchange's position mode, minimum order size and contract rules through backtesting and small live trades.
1. Core Idea: Define Price Boundaries in Three Ways
The strategy provides three channel methods: a static channel, Bollinger Bands and an ATR channel. All three methods first calculate resistance and support from earlier bars, then check whether the close of a completed bar has moved beyond either boundary.
The static channel uses the highest high and lowest low of the previous N bars. Bollinger Bands use the mean closing price as the center and add or subtract a selected multiple of standard deviation. The ATR channel also uses the mean close as its center, but its width is based on Average True Range and a selected multiplier.
The static channel reflects an established high-low range. Bollinger Bands adjust to price dispersion, while the ATR channel adjusts to true trading range. Only one channel is active at a time, and the interface displays the parameters related to that channel.
2. Breakout Signals and Entry
The strategy uses the bar period selected on the FMZ bot or backtest page and evaluates signals only after a bar has closed. The signal bar itself is excluded from the channel calculation so that the breakout condition is not changed by the same price move being evaluated.
The strategy opens a long position when a completed bar closes above resistance and opens a short position when it closes below support. It uses the swap cryptocurrency perpetual contract, submits quantity in contracts, and applies the configured leverage through SetMarginLevel() before trading.
Select channel → Calculate resistance and support → Wait for bar close → Break above to go long / break below to go short
The strategy manages one position in one direction. If an existing position is detected at startup without a matching strategy record, the strategy will not take over or close it automatically.
3. Position Management and Exit
At entry, the strategy records the actual average position price and the boundary that was broken. A long position is closed when a completed bar moves back below the recorded resistance line. A short position is closed when a completed bar moves back above the recorded support line.
The fixed stop-loss is calculated from the average entry price and checked through market polling. A long position is closed when price falls by the configured percentage, while a short position is closed when price rises by that percentage. Setting the stop-loss to zero disables this exit condition.
Persistent state stores the position direction, entry price, breakout line and latest processed bar time. The chart displays candlesticks, the active channel's resistance, support and center lines, together with long entry, short entry, long exit and short exit markers. Labels are placed outside the upper or lower wick, while tooltips preserve the actual entry or trigger price.
4. Main Parameters
| Parameter | Default | Purpose |
|---|---|---|
| Channel type | Static channel | Selects the static, Bollinger or ATR channel |
| Static period | 20 | Uses the highest high and lowest low of the previous 20 completed bars |
| Bollinger period | 20 | Calculates the mean close and standard deviation |
| Standard-deviation multiplier | 2 | Sets Bollinger width to two standard deviations |
| ATR channel period | 20 | Calculates the ATR center and Average True Range |
| ATR multiplier | 2 | Sets ATR channel width to two Average True Ranges |
| Order size | 1 contract | Contract quantity submitted for each entry |
| Leverage | 1x | Available values depend on the exchange and instrument |
| Fixed stop-loss | 3% | Calculated from average entry price; zero disables it |
Only the parameters for the selected channel are displayed. The bar period is configured on the FMZ bot or backtest page rather than duplicated as a strategy parameter.
5. Validation Status
The current version has passed JavaScript syntax checks and offline tests covering all three channel calculations, the parameter-filter structure, chart series and marker placement outside candle wicks. The base version has generated channel lines and trade markers in an FMZ backtest chart; the latest enlarged labels and outside-wick layout still require another backtest run to confirm their final appearance. It implements two-way perpetual-contract entry and exit, fixed stop-loss handling, persistent state and chart visualization for FMZ.
A complete small-size live entry-to-exit cycle has not yet been completed on a specified exchange. Market-order support, position mode, minimum contract quantity, partial fills, API error recovery and contract multipliers still require live validation. A channel breakout does not guarantee trend continuation, and ranging markets may produce repeated false breakouts and stop-losses.
- 1