Buy The Dips - MA200 Optimised is a mean-reversion strategy that measures short-term percentage price changes alongside a simple moving average trend filter.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
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
33 lines of Pine Script v4 from Buy The Dips - MA200 Optimised.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
Buy The Dips - MA200 Optimised.pine
//@version=4
strategy("Buy The Dips - MA200 Optimised", overlay=false)
//Moving average
MAinp = input(defval = 100, title = "MA", type = input.integer, minval = 1, step = 1)
MA=sma(close, MAinp)
//Percent change
inp_lkb = input(1, title='Lookback Period')
perc_change(lkb) =>
overall_change = ((close[0] - close[lkb]) / close[lkb]) * 100
// Call the function
overall = perc_change(inp_lkb)
// === INPUT BACKTEST RANGE ===
fromMonth = input(defval = 1, title = "From Month", type = input.integer, minval = 1, maxval = 12)
fromDay = input(defval = 1, title = "From Day", type = input.integer, minval = 1, maxval = 31)
fromYear = input(defval = 2020, title = "From Year", type = input.integer, minval = 1970)
thruMonth = input(defval = 1, title = "Thru Month", type = input.integer, minval = 1, maxval = 12)
thruDay = input(defval = 1, title = "Thru Day", type = input.integer, minval = 1, maxval = 31)
thruYear = input(defval = 2112, title = "Thru Year", type = input.integer, minval = 1970)
showDate = input(defval = true, title = "Show Date Range", type = input.bool)
start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start window
finish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function "within window of time"
//Entry/Exit
strategy.entry(id="long", long = true, when = window() and overall<-3 and close > MA)
strategy.close(id="long", when = window() and overall>1)
bgcolor(color = showDate and window() ? color.gray : na, transp = 90)
plot(overall, color=color.black, title='Overall Percentage Change', linewidth=3)
band1 = hline(1, "Upper Band", color=#C0C0C0)
band0 = hline(-2, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")
hline(0, title='Center Line', color=color.orange, linestyle=hline.style_solid, linewidth=2)
Expand (41 lines)
Overview
Buy The Dips - MA200 Optimised opens long positions when price experiences a steep drop exceeding three percent while remaining above the moving average baseline. Trades are exited once percentage momentum rebounds above one percent. The script plots the price change percentage in a separate oscillator pane. It includes configurable backtest date ranges but lacks a defined stop loss.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
MA
int
100
MAinp
Lookback Period
int
1
inp_lkb
From Month
int
1
fromMonth
From Day
int
1
fromDay
From Year
int
2020
fromYear
Thru Month
int
1
thruMonth
Thru Day
int
1
thruDay
Thru Year
int
2112
thruYear
Show Date Range
bool
true
showDate
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 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
MACD + Divergences [Alorse] is a momentum strategy that calculates the MACD oscillator and identifies regular and hidden divergences using pivot high and low points. It filters trade signals with dual Exponential Moving Averages (EMA 150 and 600) to ensure tra
This strategy calculates the Moving Average Convergence Divergence indicator and plots the MACD line, signal line, and histogram in a separate pane. It enters long positions when the MACD line crosses above the signal line and enters short positions when it cr
This strategy combines an EMA ribbon with MACD confirmation and plots in a separate pane. It enters when ribbon alignment, optional MACD zero or signal crosses, volume, smart-money, and multi-timeframe filters agree, then exits with percentage stop loss and ta
This strategy combines Bollinger Bands, Bollinger Band Width, and the Relative Strength Index (RSI) for mean-reversion trades. It enters long when price crosses below the lower band with oversold RSI, or when band width contracts under low volatility. Short en
This strategy evaluates the dynamic relationship between price and a chosen moving average across six diagnostic dimensions: trend, respect, extension, compression, acceleration, and exhaustion. It plots a normalized relationship oscillator bounded between -10