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.
Script de código aberto
No verdadeiro espirito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam entendê-lo e verificá-lo. Parabéns ao autor Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações e regida pelas Regras da Casa.
Aviso legal
As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.
Script de código aberto
No verdadeiro espirito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam entendê-lo e verificá-lo. Parabéns ao autor Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações e regida pelas Regras da Casa.
Aviso legal
As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.