Pine Script v4 · Strategy
Oscilator candles - momentum strategy
A Pine Script v4 strategy built on MACD (open, 3) and SMA or EMA or HMA or RMA or VWMA or WMA (source, 100). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.01% commission. 12 settings; defaults include Oscliator Type stoch, Length 100 and Shortlength 3.
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 Oscilator candles - momentum strategy repaint?
- Yes
- At least one pattern in the source can repaint: higher-timeframe data.
- How did Oscilator candles - momentum strategy do on BTCUSDT 1D with default settings?
- +107.97%
- From 26 Jan 2024 to 21 Oct 2026, over 8 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Oscilator candles - momentum strategy be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does Oscilator candles - momentum strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Oscilator candles - momentum strategy run in Zeal Terminal?
- Yes
- It compiles in 25 ms and runs 1,000 bars in 74 ms, in the browser.
BTCUSDT · 1D · default settings
- TrailingStop
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +107.97%
- $107,973.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 8
- 4 won · 4 lost
- Profitable
- 50.0%
- of closed trades
- Profit factor
- 2.56
- gross profit ÷ gross loss
- Max drawdown
- 18.24%
- −$38,755.70
One run with the author's default settings, $100,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.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
8 settings have no label
In the settings dialog length (line 6), shortlength (line 7), longlength (line 8), showSupertrend (line 9), AtrLength (line 11), AtrMult (line 12), wicks (line 13), colorByPreviousClose (line 14) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 125, 126, 127, 128. The upgraded version below moves each call inside an if block.
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames rsi → ta.rsi, tsi → ta.tsi, stoch → ta.stoch, cci → ta.cci, cog → ta.cog, cmo → ta.cmo, mfi → ta.mfi, macd → ta.macd, sma → ta.sma, ema → ta.ema, hma → ta.hma, rma → ta.rma, vwma → ta.vwma, wma → ta.wma, max → math.max, min → math.min, security → request.security, tostring → str.tostring, round → math.round.
- 4 strategy calls use the when = argument (line 125, 126, 127, 128). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 8 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 17: input(type = input.time) → input.time()
- Line 18: input(type = input.time) → input.time()
- Line 21: rsi → ta.rsi
- Line 22: rsi → ta.rsi
- Line 23: rsi → ta.rsi
45 more edits
- Line 24: rsi → ta.rsi
- Line 26: tsi → ta.tsi
- Line 27: tsi → ta.tsi
- Line 28: tsi → ta.tsi
- Line 29: tsi → ta.tsi
- Line 31: stoch → ta.stoch
- Line 32: stoch → ta.stoch
- Line 33: stoch → ta.stoch
- Line 34: stoch → ta.stoch
- Line 36: cci → ta.cci
- Line 37: cci → ta.cci
- Line 38: cci → ta.cci
- Line 39: cci → ta.cci
- Line 41: cog → ta.cog
- Line 42: cog → ta.cog
- Line 43: cog → ta.cog
- Line 44: cog → ta.cog
- Line 46: cmo → ta.cmo
- Line 47: cmo → ta.cmo
- Line 48: cmo → ta.cmo
- Line 49: cmo → ta.cmo
- Line 51: mfi → ta.mfi
- Line 52: mfi → ta.mfi
- Line 53: mfi → ta.mfi
- Line 54: mfi → ta.mfi
- Line 56: macd → ta.macd
- Line 57: macd → ta.macd
- Line 58: macd → ta.macd
- Line 59: macd → ta.macd
- Line 66: sma → ta.sma
- Line 68: ema → ta.ema
- Line 70: hma → ta.hma
- Line 72: rma → ta.rma
- Line 74: vwma → ta.vwma
- Line 76: wma → ta.wma
- Line 79: max → math.max
- Line 79: min → math.min
- Line 85: max → math.max
- Line 89: min → math.min
- Line 98: security → request.security
- Line 110: tostring → str.tostring
- Line 110: round → math.round
- Line 111: tostring → str.tostring
- Line 111: round → math.round
- Line 111: min → math.min
⋯// © HeWhoMustNotBeNamed-//@version=4+//@version=5strategy("Oscilator candles - strategy", overlay=false, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)⋯tradeDirection = strategy.direction.long-i_startTime = input(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Backtest Start Time", type = input.time)+i_startTime = input.time(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Backtest Start Time")-i_endTime = input(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "Backtest End Time", type = input.time)+i_endTime = input.time(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "Backtest End Time")inDateRange = time >= i_startTime and time <= i_endTimef_getOscilatorValues(oscilatorType, length, shortlength, longlength)=>- oOpen = rsi(open, length)+ oOpen = ta.rsi(open, length)- oClose = rsi(close, length)+ oClose = ta.rsi(close, length)- oHigh = rsi(high, length)+ oHigh = ta.rsi(high, length)- oLow = rsi(low, length)+ oLow = ta.rsi(low, length) if(oscilatorType == "tsi")- oOpen := tsi(open, shortlength, longlength)+ oOpen := ta.tsi(open, shortlength, longlength)- oClose := tsi(close, shortlength, longlength)+ oClose := ta.tsi(close, shortlength, longlength)- oHigh := tsi(high, shortlength, longlength)+ oHigh := ta.tsi(high, shortlength, longlength)- oLow := tsi(low, shortlength, longlength)+ oLow := ta.tsi(low, shortlength, longlength) if(oscilatorType == "stoch")- oOpen := stoch(open, high, low, length)+ oOpen := ta.stoch(open, high, low, length)- oClose := stoch(close, high, low, length)+ oClose := ta.stoch(close, high, low, length)- oHigh := stoch(high, high, low, length)+ oHigh := ta.stoch(high, high, low, length)- oLow := stoch(low, high, low, length)+ oLow := ta.stoch(low, high, low, length) if(oscilatorType == "cci")- oOpen := cci(open, length)+ oOpen := ta.cci(open, length)- oClose := cci(close, length)+ oClose := ta.cci(close, length)- oHigh := cci(high, length)+ oHigh := ta.cci(high, length)- oLow := cci(low, length)+ oLow := ta.cci(low, length) if(oscilatorType == "cog")- oOpen := cog(open, length)+ oOpen := ta.cog(open, length)- oClose := cog(close, length)+ oClose := ta.cog(close, length)- oHigh := cog(high, length)+ oHigh := ta.cog(high, length)- oLow := cog(low, length)+ oLow := ta.cog(low, length) if(oscilatorType == "cmo")- oOpen := cmo(open, length)+ oOpen := ta.cmo(open, length)- oClose := cmo(close, length)+ oClose := ta.cmo(close, length)- oHigh := cmo(high, length)+ oHigh := ta.cmo(high, length)- oLow := cmo(low, length)+ oLow := ta.cmo(low, length) if(oscilatorType == "mfi")- oOpen := mfi(open, length)+ oOpen := ta.mfi(open, length)- oClose := mfi(close, length)+ oClose := ta.mfi(close, length)- oHigh := mfi(high, length)+ oHigh := ta.mfi(high, length)- oLow := mfi(low, length)+ oLow := ta.mfi(low, length) if(oscilatorType == "macd")- [macdLineOpen, signalLineOpen, histLineOpen] = macd(open, shortlength, longlength, length)+ [macdLineOpen, signalLineOpen, histLineOpen] = ta.macd(open, shortlength, longlength, length)- [macdLineClose, signalLineClose, histLineClose] = macd(close, shortlength, longlength, length)+ [macdLineClose, signalLineClose, histLineClose] = ta.macd(close, shortlength, longlength, length)- [macdLineHigh, signalLineHigh, histLineHigh] = macd(high, shortlength, longlength, length)+ [macdLineHigh, signalLineHigh, histLineHigh] = ta.macd(high, shortlength, longlength, length)- [macdLineLow, signalLineLow, histLineLow] = macd(low, shortlength, longlength, length)+ [macdLineLow, signalLineLow, histLineLow] = ta.macd(low, shortlength, longlength, length) oOpen := macdLineOpen⋯f_getMovingAverage(source, MAType, length)=>- ma = sma(source, length)+ ma = ta.sma(source, length) if(MAType == "ema")- ma := ema(source,length)+ ma := ta.ema(source,length) if(MAType == "hma")- ma := hma(source,length)+ ma := ta.hma(source,length) if(MAType == "rma")- ma := rma(source,length)+ ma := ta.rma(source,length) if(MAType == "vwma")- ma := vwma(source,length)+ ma := ta.vwma(source,length) if(MAType == "wma")- ma := wma(source,length)+ ma := ta.wma(source,length) maf_getSupertrend(oOpen, oClose, oHigh, oLow, AtrMAType, AtrLength, AtrMult, wicks)=>- truerange = max(oHigh, oClose[1]) - min(oLow, oClose[1])+ truerange = math.max(oHigh, oClose[1]) - math.min(oLow, oClose[1]) ⋯ longStopPrev = nz(longStop[1], longStop)- longStop := (wicks ? oLow[1] : oClose[1]) > longStopPrev ? max(longStop, longStopPrev) : longStop+ longStop := (wicks ? oLow[1] : oClose[1]) > longStopPrev ? math.max(longStop, longStopPrev) : longStop ⋯ shortStopPrev = nz(shortStop[1], shortStop)- shortStop := (wicks ? oHigh[1] : oClose[1]) < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop+ shortStop := (wicks ? oHigh[1] : oClose[1]) < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop ⋯ [dir, trailingStop]-f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_off)+f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_off)f_multiple_resolution(HTFMultiplier) => ⋯ target_Res_In_Min <= 0.751 ? "30S" :- target_Res_In_Min <= 1440 ? tostring(round(target_Res_In_Min)) :+ target_Res_In_Min <= 1440 ? str.tostring(math.round(target_Res_In_Min)) :- tostring(round(min(target_Res_In_Min / 1440, 365))) + "D"+ str.tostring(math.round(math.min(target_Res_In_Min / 1440, 365))) + "D" ⋯Same 8 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.string()
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.bool()
- Line 10: input() → input.string()
8 more edits
- Line 11: input() → input.int()
- Line 12: input() → input.int()
- Line 13: input() → input.bool()
- Line 14: input() → input.bool()
- Line 125: when = buyCondition and inDateRange → if block
- Line 126: when = sellCondition and inDateRange → if block
- Line 127: when = exitBuyConditin → if block
- Line 128: when = exitSellCondition → if block
⋯strategy("Oscilator candles - strategy", overlay=false, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)-oscilatorType = input(title="Oscliator Type", defval="stoch", options=["rsi", "stoch", "cog", "macd", "tsi", "cci", "cmo", "mfi"])+oscilatorType = input.string(title="Oscliator Type", defval="stoch", options=["rsi", "stoch", "cog", "macd", "tsi", "cci", "cmo", "mfi"])-length = input(100, step=10)+length = input.int(100, step=10)-shortlength = input(3)+shortlength = input.int(3)-longlength = input(9)+longlength = input.int(9)-showSupertrend = input(true)+showSupertrend = input.bool(true)-AtrMAType = input(title="Moving Average Type", defval="rma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])+AtrMAType = input.string(title="Moving Average Type", defval="rma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])-AtrLength = input(30)+AtrLength = input.int(30)-AtrMult = input(4)+AtrMult = input.int(4)-wicks = input(true)+wicks = input.bool(true)-colorByPreviousClose = input(true)+colorByPreviousClose = input.bool(true)// tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])⋯strategy.risk.allow_entry_in(tradeDirection)-strategy.entry("Buy", strategy.long, when=buyCondition and inDateRange, oca_name="oca", oca_type=strategy.oca.cancel)+if buyCondition and inDateRange+ strategy.entry("Buy", strategy.long, oca_name="oca", oca_type=strategy.oca.cancel)-strategy.entry("Sell", strategy.short, when=sellCondition and inDateRange, oca_name="oca", oca_type=strategy.oca.cancel)+if sellCondition and inDateRange+ strategy.entry("Sell", strategy.short, oca_name="oca", oca_type=strategy.oca.cancel)-strategy.close("Buy", when = exitBuyConditin)+if exitBuyConditin+ strategy.close("Buy")-strategy.close( "Sell", when = exitSellCondition)+if exitSellCondition+ strategy.close( "Sell")Does it run in Pine Script v6?
Yes
Same 8 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © HeWhoMustNotBeNamed-//@version=5+//@version=6strategy("Oscilator candles - strategy", overlay=false, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Oscliator Type | stoch | string · options ["rsi", "stoch", "cog", "macd", "tsi", "cci", "cmo", "mfi"] | oOpen oClose oHigh oLow line 25 line 30 line 35 line 40 line 45 line 50 line 55 |
| Length (no label in the script) | 100 | int · step 10 | oOpen oClose oHigh oLow macdLineOpen signalLineOpen histLineOpen macdLineClose signalLineClose histLineClose macdLineHigh signalLineHigh histLineHigh macdLineLow signalLineLow histLineLow ma |
| Shortlength (no label in the script) | 3 | int | oOpen oClose oHigh oLow macdLineOpen signalLineOpen histLineOpen macdLineClose signalLineClose histLineClose macdLineHigh signalLineHigh histLineHigh macdLineLow signalLineLow histLineLow |
| Longlength (no label in the script) | 9 | int | oOpen oClose oHigh oLow macdLineOpen signalLineOpen histLineOpen macdLineClose signalLineClose histLineClose macdLineHigh signalLineHigh histLineHigh macdLineLow signalLineLow histLineLow |
| Show Supertrend (no label in the script) | true | bool | TrailingStop |
| Moving Average Type | rma | string · options ["ema", "sma", "hma", "rma", "vwma", "wma"] | averagetruerange dir trailingStop |
| ATR Length (no label in the script) | 30 | int | averagetruerange dir trailingStop |
| ATR Mult (no label in the script) | 4 | int | atr dir trailingStop |
| Wicks (no label in the script) | true | bool | longStop shortStop dir trailingStop |
| Color By Previous Close (no label in the script) | true | bool | candleColor |
| Backtest Start Time | timestamp("01 Jan 2010 00:00 +0000") | time | inDateRange |
| Backtest End Time | timestamp("01 Jan 2099 00:00 +0000") | time | inDateRange |
What it calculates
- MACD (
macd,ta.macdin v5)open, Shortlength (3), Longlength (9), Length (100)macdLineOpen · line 56 - MACD (
macd,ta.macdin v5)open, Shortlength (3), Longlength (9), Length (100)signalLineOpen · line 56 - MACD (
macd,ta.macdin v5)open, Shortlength (3), Longlength (9), Length (100)histLineOpen · line 56 - MACD (
macd,ta.macdin v5)close, Shortlength (3), Longlength (9), Length (100)macdLineClose · line 57 - MACD (
macd,ta.macdin v5)close, Shortlength (3), Longlength (9), Length (100)signalLineClose · line 57 - MACD (
macd,ta.macdin v5)close, Shortlength (3), Longlength (9), Length (100)histLineClose · line 57 - MACD (
macd,ta.macdin v5)high, Shortlength (3), Longlength (9), Length (100)macdLineHigh · line 58 - MACD (
macd,ta.macdin v5)high, Shortlength (3), Longlength (9), Length (100)signalLineHigh · line 58 - MACD (
macd,ta.macdin v5)high, Shortlength (3), Longlength (9), Length (100)histLineHigh · line 58 - MACD (
macd,ta.macdin v5)low, Shortlength (3), Longlength (9), Length (100)macdLineLow · line 59 - MACD (
macd,ta.macdin v5)low, Shortlength (3), Longlength (9), Length (100)signalLineLow · line 59 - MACD (
macd,ta.macdin v5)low, Shortlength (3), Longlength (9), Length (100)histLineLow · line 59 - SMA / EMA / HMA / RMA / VWMA / WMA (
sma,ta.smain v5)source, Length (100)ma · line 66
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Buy long | buyCondition and inDateRange | On | 125 |
| Open Sell short | sellCondition and inDateRange | On | 126 |
| Close Buy | exitBuyConditindir == -1 | On | 127 |
| Close Sell | exitSellConditiondir == 1 | On | 128 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- CheckHigher-timeframe data1 security call(s) use lookahead_on (line 98). Without a [1] offset this reads future bars in history.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +108.0% | +102.5% | 8 | 50% | 2.56 | 18.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −14.8% | +5.5% | 9 | 44% | 0.45 | 26.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +129.8% | +9.8% | 8 | 63% | 2.55 | 32.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −20.9% | +8.4% | 10 | 30% | 0.50 | 34.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +98.9% | +16.7% | 9 | 44% | 3.14 | 24.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −10.7% | +21.5% | 8 | 38% | 0.65 | 32.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +5.3% | +148.3% | 10 | 20% | 1.05 | 49.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +22.3% | +17.1% | 9 | 56% | 3.25 | 7.2% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 1 | 0% | −$4,482.86 |
| Sideways market | 6 | 50% | $100,806.00 |
| Falling market | 1 | 100% | $11,670.50 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
31.4%
The 95th percentile of the worst drawdown when the same 8 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 16.6% to 31.4%; the tick is what actually happened, 16.6%. Order luck alone moves it this much.
All 8 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 27 Jan 2024 41,823.50 | 15 Jun 2024 66,044.00 | 140 | $57,879.60 |
| long | 16 Jul 2024 64,724.10 | 5 Aug 2024 58,161.00 | 20 | −$16,037.40 |
| long | 21 Sep 2024 63,201.10 | 14 Jan 2025 94,536.10 | 115 | $70,282.90 |
| long | 3 Mar 2025 94,270.00 | 11 Mar 2025 78,595.90 | 8 | −$35,305.10 |
| long | 23 Apr 2025 93,443.00 | 2 Aug 2025 113,298.00 | 101 | $37,528.10 |
| long | 12 Aug 2025 118,686.00 | 19 Aug 2025 116,227.00 | 7 | −$4,482.86 |
| long | 3 Oct 2025 120,529.00 | 11 Oct 2025 112,774.00 | 8 | −$13,542.00 |
| long | 5 Mar 2026 72,666.80 | 19 May 2026 77,001.90 | 75 | $11,670.50 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Oscilator candles - momentum strategy this page | — | v4 strategy | +108.0% | 8 | 18.2% |
| Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST by TraderHalai | sma ema hma vwma rma | v5 strategy | +1.3% | 113 | 5.6% |
| High-Low Channel Multi averages Crypto Swing strategy by exlux99 | sma ema wma rma vwma | v4 strategy | No trades on this market | ||
| Ultra Moving Average Rating Trend Strategy by exlux99 | ema wma sma rma vwma hma | v5 strategy | +2.8% | 5 | 2.4% |
| VCP pivot buy by perrycc007 | sma ema rma vwma wma | v4 strategy | does not run in Zeal Terminal | ||
| Multi Trend Cross Strategy Template by TradeAutomation | ema hma rma sma vwma wma | v5 strategy | +33.0% | 3 | 7.3% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 25 ms | With a workaround 1,000 bars in 74 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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. PineTS runs Pine Script v5 and v6 only.
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/// © HeWhoMustNotBeNamed//@version=4strategy("Oscilator candles - strategy", overlay=false, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)oscilatorType = input(title="Oscliator Type", defval="stoch", options=["rsi", "stoch", "cog", "macd", "tsi", "cci", "cmo", "mfi"])length = input(100, step=10)shortlength = input(3)longlength = input(9)showSupertrend = input(true)AtrMAType = input(title="Moving Average Type", defval="rma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])AtrLength = input(30)AtrMult = input(4)wicks = input(true)colorByPreviousClose = input(true)// tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])tradeDirection = strategy.direction.longi_startTime = input(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Backtest Start Time", type = input.time)i_endTime = input(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "Backtest End Time", type = input.time)inDateRange = time >= i_startTime and time <= i_endTimef_getOscilatorValues(oscilatorType, length, shortlength, longlength)=> oOpen = rsi(open, length) oClose = rsi(close, length) oHigh = rsi(high, length) oLow = rsi(low, length) if(oscilatorType == "tsi") oOpen := tsi(open, shortlength, longlength) oClose := tsi(close, shortlength, longlength) oHigh := tsi(high, shortlength, longlength) oLow := tsi(low, shortlength, longlength) if(oscilatorType == "stoch") oOpen := stoch(open, high, low, length) oClose := stoch(close, high, low, length) oHigh := stoch(high, high, low, length) oLow := stoch(low, high, low, length) if(oscilatorType == "cci") oOpen := cci(open, length) oClose := cci(close, length) oHigh := cci(high, length) oLow := cci(low, length) if(oscilatorType == "cog") oOpen := cog(open, length) oClose := cog(close, length) oHigh := cog(high, length) oLow := cog(low, length) if(oscilatorType == "cmo") oOpen := cmo(open, length) oClose := cmo(close, length) oHigh := cmo(high, length) oLow := cmo(low, length) if(oscilatorType == "mfi") oOpen := mfi(open, length) oClose := mfi(close, length) oHigh := mfi(high, length) oLow := mfi(low, length) if(oscilatorType == "macd") [macdLineOpen, signalLineOpen, histLineOpen] = macd(open, shortlength, longlength, length) [macdLineClose, signalLineClose, histLineClose] = macd(close, shortlength, longlength, length) [macdLineHigh, signalLineHigh, histLineHigh] = macd(high, shortlength, longlength, length) [macdLineLow, signalLineLow, histLineLow] = macd(low, shortlength, longlength, length) oOpen := macdLineOpen oClose := macdLineClose oHigh := macdLineHigh oLow := macdLineLow [oOpen, oClose, oHigh, oLow]f_getMovingAverage(source, MAType, length)=> ma = sma(source, length) if(MAType == "ema") ma := ema(source,length) if(MAType == "hma") ma := hma(source,length) if(MAType == "rma") ma := rma(source,length) if(MAType == "vwma") ma := vwma(source,length) if(MAType == "wma") ma := wma(source,length) maf_getSupertrend(oOpen, oClose, oHigh, oLow, AtrMAType, AtrLength, AtrMult, wicks)=> truerange = max(oHigh, oClose[1]) - min(oLow, oClose[1]) averagetruerange = f_getMovingAverage(truerange, AtrMAType, AtrLength) atr = averagetruerange * AtrMult longStop = oClose - atr longStopPrev = nz(longStop[1], longStop) longStop := (wicks ? oLow[1] : oClose[1]) > longStopPrev ? max(longStop, longStopPrev) : longStop shortStop = oClose + atr shortStopPrev = nz(shortStop[1], shortStop) shortStop := (wicks ? oHigh[1] : oClose[1]) < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop dir = 1 dir := nz(dir[1], dir) dir := dir == -1 and (wicks ? oHigh : oClose) > shortStopPrev ? 1 : dir == 1 and (wicks ? oLow : oClose) < longStopPrev ? -1 : dir trailingStop = dir == 1? longStop : shortStop [dir, trailingStop]f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_off)f_multiple_resolution(HTFMultiplier) => target_Res_In_Min = timeframe.multiplier * HTFMultiplier * ( timeframe.isseconds ? 1. / 60. : timeframe.isminutes ? 1. : timeframe.isdaily ? 1440. : timeframe.isweekly ? 7. * 24. * 60. : timeframe.ismonthly ? 30.417 * 24. * 60. : na) target_Res_In_Min <= 0.0417 ? "1S" : target_Res_In_Min <= 0.167 ? "5S" : target_Res_In_Min <= 0.376 ? "15S" : target_Res_In_Min <= 0.751 ? "30S" : target_Res_In_Min <= 1440 ? tostring(round(target_Res_In_Min)) : tostring(round(min(target_Res_In_Min / 1440, 365))) + "D" [oOpen, oClose, oHigh, oLow] = f_getOscilatorValues(oscilatorType, length, shortlength, longlength)[dir, trailingStop] = f_getSupertrend(oOpen, oClose, oHigh, oLow, AtrMAType, AtrLength, AtrMult, wicks)candleColor = colorByPreviousClose ? (oClose[1] < oClose ? color.green : oClose[1] > oClose ? color.red : color.silver) : (oOpen < oClose ? color.green : oOpen > oClose ? color.red : color.silver)plotcandle(oOpen, oHigh, oLow, oClose, 'Oscilator Candles', color = candleColor)plot(showSupertrend?trailingStop:na, title="TrailingStop", style=plot.style_linebr, linewidth=1, color= dir == 1 ? color.green : color.red)buyCondition = dir == 1exitBuyConditin = dir == -1sellCondition = dir == -1exitSellCondition = dir == 1strategy.risk.allow_entry_in(tradeDirection)strategy.entry("Buy", strategy.long, when=buyCondition and inDateRange, oca_name="oca", oca_type=strategy.oca.cancel)strategy.entry("Sell", strategy.short, when=sellCondition and inDateRange, oca_name="oca", oca_type=strategy.oca.cancel)strategy.close("Buy", when = exitBuyConditin)strategy.close( "Sell", when = exitSellCondition)