OPEN-SOURCE SCRIPT
3Bars [TheAlphaGroup]

3Bars Setup (Original by. Larry Williams)
The “3Bars” is a classic setup from Larry Williams, designed to capture short-term reversals within a larger trend. It uses very simple ingredients: moving averages of the highs and lows.
How It Works
Why It’s Interesting
Disclaimer
This script is for educational and research purposes only.
It is not financial advice and does not guarantee profitability.
Always backtest on multiple markets and timeframes, and use proper risk management.
About the Yellow Warning Box
“Caution! This strategy may use look-ahead bias…”
Note: The warning shows because Pine doesn’t “trust” limit orders that are priced with data from completed bars. The current version is already safe (no repaint/look-ahead), but TradingView cannot automatically confirm that.
The “3Bars” is a classic setup from Larry Williams, designed to capture short-term reversals within a larger trend. It uses very simple ingredients: moving averages of the highs and lows.
How It Works
- Bands Calculation
– A short moving average (default = 3) is applied separately to the Highs and to the Lows.
– The average of the Lows forms the [color=lime]lower band[/color].
– The average of the Highs forms the [color=red]upper band[/color]. - Trade Logic
– In an uptrend (price above a longer MA, default = 21 EMA or SMA), the system looks for longs.
• Entry: Buy at the lower band.
• Exit: Sell at the upper band.
– In a downtrend (price below the 21 EMA/SMA), the system looks for shorts.
• Entry: Sell at the upper band.
• Exit: Cover at the lower band. - Safety Net
– If the trade doesn’t hit its band exit, it is force-closed after X bars (default = 7).
– Users can select SMA or EMA for both the bands and the trend filter.
– Direction can be toggled: Long only, Short only, or Both.
Why It’s Interesting
- The method tries to ride the market “channel” between recent highs and lows.
- It doesn’t chase breakouts, it waits for price to pull back into a band before positioning.
- It’s rule-based and mechanical, which makes it easy to test and automate.
Disclaimer
This script is for educational and research purposes only.
It is not financial advice and does not guarantee profitability.
Always backtest on multiple markets and timeframes, and use proper risk management.
About the Yellow Warning Box
“Caution! This strategy may use look-ahead bias…”
Note: The warning shows because Pine doesn’t “trust” limit orders that are priced with data from completed bars. The current version is already safe (no repaint/look-ahead), but TradingView cannot automatically confirm that.
- To silence the warning, you’d need to shift all logic by one more bar ([2]) or use market orders. But that sacrifices realism.
- If you care about accurate band-based fills more than the warning box, it is safe to ignore it.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.