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.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.