Strategy · Pine Script v6 · On the chart

Buffett-Inspired Value Strategy

by kohld

Calculates a long-term Exponential Moving Average as a baseline for fair value alongside a Relative Strength Index.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code65
Settings7inputs
LicenceMIT
Last update1 year ago7 Sep 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

65 lines of Pine Script v6 from scripts/buffett-inspired-value-strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

buffett-inspired-value-strategy.pine
//@version=6
strategy('Buffett-Inspired Value Strategy', overlay = true)

// --- Input Parameters ---
// Longer Moving Average (as a reference for "Fair Value")
emaLength = input.int(200, 'EMA Length (Long)', minval = 10)
emaSource = input(close, 'EMA Source')

// RSI settings for oversold/overbought conditions
rsiLength = input.int(14, 'RSI Length', minval = 1)
rsiOversold = input.int(30, 'RSI Oversold Level', minval = 1)
rsiOverbought = input.int(70, 'RSI Overbought Level', minval = 1)

// Take Profit and Stop Loss percentages
takeProfitPercent = input.float(10.0, 'Take Profit (%)', minval = 0.1) / 100
stopLossPercent = input.float(5.0, 'Stop Loss (%)', minval = 0.1) / 100

// --- Indicator Calculations ---
emaValue = ta.ema(emaSource, emaLength)
rsiValue = ta.rsi(emaSource, rsiLength)

// --- Plotting Indicators on the Chart ---
plot(emaValue, 'EMA', color = color.blue, linewidth = 2)
plot(rsiValue, 'RSI', color = color.orange, display = display.none) // Do not plot RSI directly on the price chart

hline(rsiOversold, 'RSI Oversold', color = color.green, linestyle = hline.style_dotted, display = display.none)
hline(rsiOverbought, 'RSI Overbought', color = color.red, linestyle = hline.style_dotted, display = display.none)

// --- Strategy Logic ---

// Variables for entry price and Take Profit/Stop Loss Levels
var float entryPrice = na
var float takeProfitPrice = na
var float stopLossPrice = na

// Buy condition: Price is significantly below the EMA and RSI is oversold
buyCondition = close < emaValue * 0.95 and rsiValue < rsiOversold // 5% below EMA as "Margin of Safety"

// If no position is open and the buy condition is met
if buyCondition and strategy.position_size == 0
    strategy.entry('Buy', strategy.long) // Renamed from "Long" to "Buy"
    entryPrice := close // Store the entry price
    takeProfitPrice := close * (1 + takeProfitPercent)
    stopLossPrice := close * (1 - stopLossPercent)

    // --- NEW: Alert for Buy Recommendation ---
    alert('Buffett Strategy: Buy Signal for ' + syminfo.ticker + ' at ' + str.tostring(close), alert.freq_once_per_bar)

// Selling / Position Management
if strategy.position_size > 0
    // Take Profit
    strategy.exit('Sell (Profit)', from_entry = 'Buy', limit = takeProfitPrice) // Renamed from "Take Profit" to "Sell (Profit)"

    // Stop Loss
    strategy.exit('Sell (Loss)', from_entry = 'Buy', stop = stopLossPrice) // Renamed from "Stop Loss" to "Sell (Loss)"

// Optional: Exit on strong overbought RSI - might be aggressive, Buffett would typically hold
// Uncomment if you want to test this
// if rsiValue > rsiOverbought
//     strategy.close("Buy", comment="RSI Overbought") // Renamed from "Long" to "Buy"


// Plotting Entry/Exit points (optional, for visual confirmation)
plotshape(buyCondition and strategy.position_size == 0, style = shape.triangleup, location = location.belowbar, color = color.green, size = size.small, title = 'Buy Signal')
plotshape(strategy.position_size > 0 and (close >= takeProfitPrice or close <= stopLossPrice), style = shape.triangledown, location = location.abovebar, color = color.red, size = size.small, title = 'Sell Signal')

Overview

Generates long entry signals when the close price trades at least five percent below the moving average while the RSI is oversold. Exits trades using percentage-based take profit and stop loss levels. Settings allow customization of indicator lengths, RSI thresholds, and exit percentage targets. Draws the baseline average and entry or exit shapes on the price chart.

Details

Published by

kohld on GitHub

Draws

On the price chart

Markets

Stocks, Crypto

Timeframes

H4 and above

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinescripttradingtrading-strategiestradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
EMA Length (Long)int200emaLength
EMA SourcesourcecloseemaSource
RSI Lengthint14rsiLength
RSI Oversold Levelint30rsiOversold
RSI Overbought Levelint70rsiOverbought
Take Profit (%)float10.0takeProfitPercent
Stop Loss (%)float5.0stopLossPercent
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

106 stars

This trend-following strategy identifies buying opportunities during bullish pullbacks on the price chart. It defines a bull market when the 50-period simple moving average trades above the 200-period moving average. Long entries trigger when the RSI drops bel

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of Buy The Dips in Bull Market
4 stars

This strategy trades pullbacks in the direction of a moving-average trend and draws on the price chart. An uptrend requires the 50-period EMA above the 200-period EMA with price above the slower average, and a downtrend is the reverse. It enters long or short

Strategy v6 TrendOscillators & momentum
Updated 2 days ago · None stated GitHub repository of AG Trend-Pullback Optimized
4 stars

This strategy executes mean-reversion trades based on RSI overbought and oversold levels directly on the price chart. It generates long signals when the RSI crosses back above the oversold boundary and short signals when it crosses below the overbought boundar

Strategy v5 Mean reversionOscillators & momentum
Updated 11 months ago · Custom licence GitHub repository of RSI Mean Reversion Strategy [Lab]
3 stars

The Buy/Sell Position Strategy combines a long-term Exponential Moving Average (EMA) with a short-term Relative Strength Index (RSI) to capture pullbacks in an uptrend. It enters a long position on the price chart when the price is above the EMA filter and the

Strategy v5 TrendOscillators & momentum
Updated 4 months ago · None stated GitHub repository of Buy/Sell Position Strategy

PineForge - Relay Enum Regime

by pineforge-4pass
1 stars

This strategy executes trades based on one of two selectable regimes: trend-following or mean reversion. In trend mode, it enters long positions on a bullish EMA crossover and exits on a bearish crossover. In reversion mode, it buys when the RSI dips below an

Strategy v6 TrendMean reversion
Updated 7 days ago · Apache-2.0 GitHub repository of PineForge - Relay Enum Regime

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers