//@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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
EMA Length (Long)
int
200
emaLength
EMA Source
source
close
emaSource
RSI Length
int
14
rsiLength
RSI Oversold Level
int
30
rsiOversold
RSI Overbought Level
int
70
rsiOverbought
Take Profit (%)
float
10.0
takeProfitPercent
Stop Loss (%)
float
5.0
stopLossPercent
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.
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
This strategy combines a Simple Moving Average (SMA) and the Relative Strength Index (RSI) to generate long trading signals. It enters a long position when price closes above the SMA filter while RSI drops below the oversold threshold. The strategy exits the p
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
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
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
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