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.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.