Type/to search

Three-Channel Contract Breakout Teaching Strategy (Static / Bollinger Bands / ATR)

Common strategy
Created: 2026-09-15 11:07:10
Last modified: a day ago
2
Follow
526
Followers

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

ParameterDefaultPurpose
Channel typeStatic channelSelects the static, Bollinger or ATR channel
Static period20Uses the highest high and lowest low of the previous 20 completed bars
Bollinger period20Calculates the mean close and standard deviation
Standard-deviation multiplier2Sets Bollinger width to two standard deviations
ATR channel period20Calculates the ATR center and Average True Range
ATR multiplier2Sets ATR channel width to two Average True Ranges
Order size1 contractContract quantity submitted for each entry
Leverage1xAvailable values depend on the exchange and instrument
Fixed stop-loss3%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.

Source
JavaScript
/*
三通道合约突破教学策略

适用场景:发明者量化(FMZ)数字货币永续合约实盘/回测。
交易单位:张。
K线周期:直接使用机器人或回测页面选择的周期,因此不重复做成策略参数。

三种通道:
1. 静态通道:前N根K线最高价为压力线,最低价为支撑线。
2. 布林带:前N根收盘价均值 ± 标准差 × 倍数。
3. ATR通道:前N根收盘价均值 ± ATR × 倍数。
Strategy parameters
Strategy parameters
通道类型
静态区间周期 (Optional)
布林带周期 (Optional)
标准差倍数 (Optional)
ATR通道周期 (Optional)
ATR倍数 (Optional)
每次下单张数 (Optional)
杠杆倍数 (Optional)
固定止损(%) (Optional)
Comment
All comments (0)
No data
No data
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)