Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Davin's 10-200MA Pullback on SPY Strategy v2.0

A Pine Script v5 strategy built on SMA (close, 200), EMA (close, 9) and Highest (high, 52). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 10% of equity and pays 0.1 commission. 10 settings; defaults include MA Length 1 200, MA Length 2 10 and MA Length 3 50.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does Davin's 10-200MA Pullback on SPY Strategy v2.0 repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 9 of 9 trades.
How did Davin's 10-200MA Pullback on SPY Strategy v2.0 do on BTCUSDT 1D with default settings?
+6.52%
From 26 Jan 2024 to 21 Oct 2026, over 32 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Davin's 10-200MA Pullback on SPY Strategy v2.0 run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 32 before, 32 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does Davin's 10-200MA Pullback on SPY Strategy v2.0 use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Davin's 10-200MA Pullback on SPY Strategy v2.0 run in Zeal Terminal?
Yes
It compiles in 19 ms and runs 1,000 bars in 45 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (10)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$10,668$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 54) so the engine trades the way the script says.
Net profit
+6.52%
$652.44
Buy and hold
+102.5%
same period
Closed trades
32
22 won · 10 lost
Profitable
68.8%
of closed trades
Profit factor
1.97
gross profit ÷ gross loss
Max drawdown
4.79%
−$523.83

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A long position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Strategy Parameters
MA Length 1Long-term MA 200200int · step 10ma1
MA Length 2Short-term MA 1010int · step 10ma2
MA Length 3MA for crossover signals`50int · step 1ma3
Stop Loss PercentHard stop loss of 10%0.15float · step 0.01stopPrice stopCondition
Exit on lower closeWait for lower close after above 10SMA before exitingtrueboolsellCondition
Buy whenever more than x% drawdownBuy the dip! Whenever x% or more drawdown on SPYtrueboolbuyCondition
Trigger % drop to buy the dip% drop to trigger contrarian Buy the Dip!14int · step 1buyCondition
Include stop condition using MA crossoverSell when crossover of MA2/1 happensfalseboolstopCondition
Time filter
Start filterStart date and time to begintimestamp("01 Jan 2013 13:30 +0000")timef_dateFilter
End filterEnd date and time to stoptimestamp("01 Jan 2099 19:30 +0000")timef_dateFilter

What it calculates

  • SMAclose, MA Length 1 (200)ma1 · line 34
  • SMAclose, MA Length 2 (10)ma2 · line 35
  • SMAclose, MA Length 3 (50)ma3 · line 36
  • EMAclose, 9ma_9 · line 37
  • EMAclose, 20ma_20 · line 38
  • Highesthigh, 52highest52 · line 42

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

closecloseprice datai_ma1MA Length 1setting · 200i_ma2MA Length 2setting · 10i_ma3MA Length 3setting · 50highhighprice dataopenopenprice datai_stopPercentStop Loss Percentsetting · 0.15i_contrarianTriggerTrigger % drop to buy t…setting · 14lowlowprice datatimetimeprice datai_startTimeStart filtersetting · timestamp("01 Jan 2…i_endTimeEnd filtersetting · timestamp("01 Jan 2…ma1SMA→ ma1ma2SMA→ ma2ma3SMA→ ma3ma_9EMA→ ma_9ma_20EMA→ ma_20highest52Highest→ highest52overall_changeoverall_changevaluebuyPricebuyPricevaluestopDistancestopDistancevaluestopPricestopPricevaluebuyConditionbuyConditionconditionsellConditionsellConditionconditionstopConditionstopConditionconditionf_dateFilterf_dateFilterconditionentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeplot:63plotplotplot:64plotplotplot:65plotplotplot:66plotplotplot:67plotplot

Order rules

OrderFires whenBy defaultLine
Open Long longbuyConditionOn54
Close LongsellCondition or stopConditionOn60

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

9/9trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+6.5%+102.5%3269%1.974.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+2.8%+5.5%2259%2.551.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.2%+9.8%4156%0.998.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+3.1%+8.4%1275%2.381.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−1.5%+16.7%4248%0.9511.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+4.1%+21.5%1753%2.171.9%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+3.1%+148.3%3158%1.246.8%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.5%+17.1%1753%1.291.2%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (MA Length 1 200, MA Length 2 10) made +7.6% before 26 Dec 2025 and −1.1% after it, against −1.1% for the defaults. 100% of the 64 combinations made money in-sample and 50% out-of-sample.

Before 26 Dec 2025 · in-sample
MA Length 2 ↓ · MA Length 1 →100120140170200240280340
5+5%+5%+5%+5%+5%+5%+5%+4%
6+4%+4%+4%+5%+5%+6%+6%+3%
7+3%+2%+3%+4%+4%+4%+4%+1%
9+2%+2%+2%+3%+4%+4%+4%+1%
10+6%+5%+5%+6%+8%+8%+7%+4%
12+5%+5%+5%+6%+7%+7%+7%+4%
14+4%+5%+5%+5%+7%+7%+6%+3%
17+4%+4%+4%+4%+5%+5%+5%+2%
From 26 Dec 2025 · out-of-sample
MA Length 2 ↓ · MA Length 1 →100120140170200240280340
5+1%+1%+1%+1%+1%+1%+1%+1%
6+1%+1%+1%+1%+3%+3%+3%+3%
7+1%+1%+1%+1%+3%+3%+3%+3%
9+1%+1%+1%+1%+2%+2%+2%+1%
10−2%−2%−2%−2%−1%−1%−1%−2%
12−1%−1%−2%−2%−1%−1%−1%−2%
14−1%−1%−2%−2%−1%−1%−1%−2%
17−2%−2%−2%−2%−1%−1%−1%−2%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market1182%$489.52
Sideways market1765%$302.28
Falling market450%−$139.36

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

4.3%

The 95th percentile of the worst drawdown when the same 32 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.0% to 4.3%; the tick is what actually happened, 4.1%. Order luck alone moves it this much.

0%5%
All 32 trades
SideEntryExitBarsP&L
long20 Mar 2024 61,937.408 May 2024 62,312.1049$6.05
long9 May 2024 61,193.0020 May 2024 66,274.0011$83.08
long25 Jun 2024 60,293.303 Jul 2024 62,135.508$30.82
long4 Jul 2024 60,208.6024 Jul 2024 65,936.0020$96.26
long5 Aug 2024 58,161.0027 Aug 2024 62,834.0022$82.08
long28 Aug 2024 59,415.0016 Sep 2024 59,132.0019−$4.91
long17 Sep 2024 58,214.0022 Oct 2024 67,377.5035$162.03
long24 Oct 2024 66,668.601 Nov 2024 70,292.008$56.82
long3 Nov 2024 69,374.7018 Nov 2024 89,856.0015$310.35
long26 Nov 2024 93,010.008 Jan 2025 96,954.6043$45.90
long9 Jan 2025 95,060.6020 Jan 2025 101,332.0011$71.69
long27 Jan 2025 102,620.0026 Feb 2025 88,680.4030−$148.61
long27 Feb 2025 84,250.1016 Apr 2025 83,644.0048−$7.77
long5 May 2025 94,277.6013 May 2025 102,791.008$97.38
long18 May 2025 103,127.0024 May 2025 107,318.006$44.23
long29 May 2025 107,782.001 Jul 2025 107,147.0033−$6.44
long2 Jul 2025 105,681.005 Jul 2025 107,984.003$23.79
long20 Jul 2025 117,840.0015 Aug 2025 118,295.0026$4.22
long16 Aug 2025 117,342.007 Sep 2025 110,188.0022−$66.74
long20 Sep 2025 115,632.008 Oct 2025 121,333.0018$53.64
long11 Oct 2025 112,774.0029 Oct 2025 112,898.0018$1.20
long30 Oct 2025 110,021.0015 Nov 2025 94,594.0016−$153.34
long16 Nov 2025 95,596.2019 Jan 2026 93,673.1064−$21.69
long1 Feb 2026 78,741.106 Feb 2026 62,909.905−$216.34
long7 Feb 2026 70,580.3013 Apr 2026 70,741.6065$2.41
long3 Jun 2026 66,760.8018 Jun 2026 64,509.4015−$35.57
long19 Jun 2026 62,958.009 Jul 2026 62,290.0020−$11.16
long10 Jul 2026 63,230.0013 Jul 2026 63,780.003$9.13
long14 Jul 2026 62,334.5017 Jul 2026 63,830.203$25.21
long18 Jul 2026 63,931.7024 Jul 2026 65,099.006$19.23
long31 Aug 2026 77,682.008 Sep 2026 79,112.008$19.42
long9 Sep 2026 78,455.8024 Sep 2026 84,397.6015$80.07

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
Davin's 10-200MA Pullback on SPY Strategy v2.0 this page—v5 strategy+6.5%324.8%
Slight Swing Momentum Strategy. by fzj20020403sma highest emav5 strategy+3.1%70.6%
Forex bot full strategy with risk management by exlux99highest ema smav4 strategy−26.4%1138.9%
LowFinder_PyraMider_V2 by A3Shema sma highestv5 strategy+1.9%150.8%
MACD Long Strat by TheGrindTodayema smav4 strategy+24.0%7920.1%
Stock trending strategy by exlux99ema smav4 strategy+35.3%2114.7%

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 32 before, 32 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯//Recommended tickers: SPY (D), QQQ (D) and big indexes, AAPL (4H)-//@version=5+//@version=6strategy("Davin's 10/200MA Pullback on SPY Strategy v2.0",⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 19 msWith a workaround 1,000 bars in 45 msNot measured
PineTSNot testedNot testedNot measured

Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 54) so the engine trades the way the script says.

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Gold_D_Roger//note: spreading 1 statement over multiple lines needs 1 apce + 1 tab | multi line function is 1 tab//Recommended tickers: SPY (D), QQQ (D) and big indexes, AAPL (4H)//@version=5strategy("Davin's 10/200MA Pullback on SPY Strategy v2.0",     overlay=true,     initial_capital=10000,     default_qty_type=strategy.percent_of_equity,     default_qty_value=10, // 10% of equity on each trade     commission_type=strategy.commission.cash_per_contract,      commission_value=0.1) //Insert your broker's rate, IB is 0.005USD or tiered//Best parameters// SPY D// Stop loss 0.15// commission of 0.005 USD using Interactive brokers// Exit on lower close // Buy more when x% down --> 14%// DO NOT include stop condition using MA crossover// Get User Inputi_ma1           = input.int(title="MA Length 1", defval=200, step=10, group="Strategy Parameters", tooltip="Long-term MA 200")i_ma2           = input.int(title="MA Length 2", defval=10, step=10, group="Strategy Parameters", tooltip="Short-term MA 10")i_ma3           = input.int(title="MA Length 3", defval=50, step=1, group="Strategy Parameters", tooltip="MA for crossover signals`")i_stopPercent   = input.float(title="Stop Loss Percent", defval=0.15, step=0.01, group="Strategy Parameters", tooltip="Hard stop loss of 10%")i_startTime     = input.time(title="Start filter", defval=timestamp("01 Jan 2013 13:30 +0000"), group="Time filter", tooltip="Start date and time to begin")i_endTime       = input.time(title="End filter", defval=timestamp("01 Jan 2099 19:30 +0000"), group="Time filter", tooltip="End date and time to stop")i_lowerClose    = input.bool(title="Exit on lower close", defval=true, group="Strategy Parameters", tooltip="Wait for lower close after above 10SMA before exiting") // optimise exit strat, boolean type creates tickbox type inputsi_contrarianBuyTheDip = input.bool(title="Buy whenever more than x% drawdown", defval=true, group="Strategy Parameters", tooltip="Buy the dip! Whenever x% or more drawdown on SPY")i_contrarianTrigger = input.int(title="Trigger % drop to buy the dip", defval=14, step=1, group="Strategy Parameters", tooltip="% drop to trigger contrarian Buy the Dip!") //14% to be best for SPY 1D//20% best for AMZN 1Di_stopByCrossover_MA2_3 = input.bool(title="Include stop condition using MA crossover", defval=false, group="Strategy Parameters", tooltip="Sell when crossover of MA2/1 happens")// Get indicator valuesma1 = ta.sma(close,i_ma1) //param 1ma2 = ta.sma(close,i_ma2) //param 2ma3 = ta.sma(close,i_ma3) //param 3ma_9 = ta.ema(close,9) //param 2ma_20 = ta.ema(close,20) //param 3// Check filter(s)f_dateFilter = time >+ i_startTime and time <= i_endTime //make sure date entries are within acceptable range// Highest price of the prev 52 days: https://www.tradingcode.net/tradingview/largest-maximum-value/#:~:text=()%20versus%20ta.-,highest(),max()%20and%20ta.highest52 = ta.highest(high,52)overall_change = ((highest52 - close[0]) / highest52) * 100// Check buy/sell conditionsvar float buyPrice = 0 //intialise buyPrice, this will change when we enter a trade ; float = decimal number data type 0.0buyCondition  = (close > ma1 and close < ma2 and strategy.position_size == 0 and f_dateFilter) or (strategy.position_size == 0 and i_contrarianBuyTheDip==true and overall_change > i_contrarianTrigger and f_dateFilter) // higher than 200sma, lower than short term ma (pullback) + avoid pyramiding positionssellCondition = close > ma2 and strategy.position_size > 0 and (not i_lowerClose or close < low[1])  //check if we already in trade + close above 10MA; // third condition: EITHER i_lowerClose not turned on OR closing price has to be < previous candle's LOW [1]stopDistance  = strategy.position_size > 0 ? ((buyPrice - close)/close) : na // check if in trade > calc % drop dist from entry, if not nastopPrice     = strategy.position_size > 0 ? (buyPrice - (buyPrice * i_stopPercent)) : na // calc SL price if in trade, if not, nastopCondition = (strategy.position_size > 0 and stopDistance > i_stopPercent) or (strategy.position_size > 0 and (i_stopByCrossover_MA2_3==true and ma3 < ma1))// Enter positionsif buyCondition     strategy.entry(id="Long", direction=strategy.long) //long only    if buyCondition[1] // if buyCondition is true prev candle    buyPrice := open // entry price = current bar opening price// Exit positionif sellCondition or stopCondition     strategy.close(id="Long", comment = "Exit" + (stopCondition ? "Stop loss=true" : "")) // if condition? "Value for true" : "value for false"    buyPrice := na //reset buyPrice// Plotplot(buyPrice, color=color.lime, style=plot.style_linebr)plot(stopPrice, color=color.red, style=plot.style_linebr, offset = -1)plot(ma1, color=color.blue) //defval=200plot(ma2, color=color.white) //defval=10plot(ma3, color=color.yellow) // defval=50