Pine Script v3 · Strategy
LegacyMcClellan Oscillator Strategy
A Pine Script v3 strategy built on EMA (rana, 16), SMA (x, length) and Stdev (x, length). It has 5 order rules, 4 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays no commission. 29 settings; defaults include RANA ratio multiplier 1000, Slow Length Sell 20 and Fast Length Sell 9.
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 McClellan Oscillator Strategy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did McClellan Oscillator Strategy do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
- Can McClellan Oscillator Strategy be converted to Pine Script v5?
- Not tested
- The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
- What alerts does McClellan Oscillator Strategy have?
- 2
- McC long ; McC short .
- Does McClellan Oscillator Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
BTCUSDT · 1D · default settings
- 0
- -
- +
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs ADVN.NY D data, not available: not a Binance spot market Needs ADVN.NQ D data, not available: not a Binance spot market Needs ADVN.US D data, not available: not a Binance spot market Needs ADVN.DJ D data, not available: not a Binance spot market Needs ADVN.AX D data, not available: not a Binance spot market Needs ADVN.AM D data, not available: not a Binance spot market Needs DECL.NY D data, not available: not a Binance spot market Needs DECL.NQ D data, not available: not a Binance spot market Needs DECL.US D data, not available: not a Binance spot market Needs DECL.DJ D data, not available: not a Binance spot market Needs DECL.AX D data, not available: not a Binance spot market Needs DECL.AM D data, not available: not a Binance spot market Needs VXX D data, not available: not a Binance spot market Needs VVIX D data, not available: not a Binance spot market Needs MMOH D data, not available: not a Binance spot market Needs MMFI D data, not available: not a Binance spot market Needs SKEW D data, not available: not a Binance spot market Needs VX1! D data, not available: not a Binance spot market Needs VX2! D data, not available: not a Binance spot market Needs VIX D data, not available: not a Binance spot market Needs IWM D data, not available: not a Binance spot market Values that depend on it are empty on this chart.
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. 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
3 settings do nothing
“Exit when oscillator goes under 0?”, “Enter when oscillator goes over 0?”, “Only sell when percent of X stocks is in downtrend” are declared but never read.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
1 setting has no label
In the settings dialog iwmma12 (line 91) shows 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.
Upgrade and export
Written in Pine Script v3. The upgrade to v5 takes 2 steps, 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 security → request.security, ema → ta.ema, sma → ta.sma, stdev → ta.stdev, crossunder → ta.crossunder, crossover → ta.crossover.
- Colours are bare names (white, black, blue, red, green, orange, yellow); v4 spells them color.white, color.black, color.blue, color.red, color.green, color.orange, color.yellow.
v3 → v4
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 3: //@version=3 → //@version=4
- Line 16: resolution → input.resolution
- Line 16: period → timeframe.period
- Line 37: area → plot.style_area
- Line 37: white → color.white
- Line 38: area → plot.style_area
14 more edits
- Line 38: white → color.white
- Line 39: line → plot.style_line
- Line 39: black → color.black
- Line 40: blue → color.blue
- Line 41: red → color.red
- Line 44: green → color.green
- Line 44: red → color.red
- Line 44: white → color.white
- Line 53: blue → color.blue
- Line 54: orange → color.orange
- Line 55: red → color.red
- Line 56: black → color.black
- Line 88: orange → color.orange
- Line 89: yellow → color.yellow
⋯// © sparrow_hawk_737-//@version=3+//@version=4strategy("McClellan Oscillator Strategy", default_qty_type=strategy.percent_of_equity, default_qty_value=100)⋯useCTF=input(false, title="Use Custom Timeframe?"), -tf=useCTF?input("D", type=resolution, title="Custom Timeframe"):period // Recommend NOT enabling this+tf=useCTF?input("D", type=input.resolution, title="Custom Timeframe"):timeframe.period // Recommend NOT enabling thisgaps=barmerge.gaps_off // Recommend leaving this OFF⋯hline(0, title="0")-plot(showOsc?mo<0?mo:0:na, style=area, color=white, title="-")+plot(showOsc?mo<0?mo:0:na, style=plot.style_area, color=color.white, title="-")-plot(showOsc?mo>=0?mo:0:na, style=area, color=white, title="+")+plot(showOsc?mo>=0?mo:0:na, style=plot.style_area, color=color.white, title="+")-plot(showOsc?mo:na, style=line, color=black, title="MO", linewidth=2)+plot(showOsc?mo:na, style=plot.style_line, color=color.black, title="MO", linewidth=2)-plot(showEMAs?e1:na, color=blue, linewidth=2, title="19 EMA")+plot(showEMAs?e1:na, color=color.blue, linewidth=2, title="19 EMA")-plot(showEMAs?e2:na, color=red, linewidth=2, title="39 EMA")+plot(showEMAs?e2:na, color=color.red, linewidth=2, title="39 EMA")short= mo>=100 and mo<mo[1]long= mo<=-100 and mo>mo[1]-bgcolor(long ? green : short ? red : white, transp=75)+bgcolor(long ? color.green : short ? color.red : color.white, transp=75)alertcondition(long and not long[1], "McC long ", "McC long ")⋯mab2 = ema(mo, slowLengthBuy)-plot(mas1, color=blue, linewidth=2, title="39 EMA")+plot(mas1, color=color.blue, linewidth=2, title="39 EMA")-plot(mas2, color=orange, linewidth=2, title="39 EMA")+plot(mas2, color=color.orange, linewidth=2, title="39 EMA")-plot(mab1, color=red, linewidth=2, title="39 EMA")+plot(mab1, color=color.red, linewidth=2, title="39 EMA")-plot(mab2, color=black, linewidth=2, title="39 EMA")+plot(mab2, color=color.black, linewidth=2, title="39 EMA")get_bbr(x, length) => ⋯rysell = roll_yield <= 0.01-plot(roll_yield * 100, color=orange, linewidth=2,title="ROLL YIELD")+plot(roll_yield * 100, color=color.orange, linewidth=2,title="ROLL YIELD")-plot(shape * 10, color=yellow, linewidth=2,title="VIX SHAPE")+plot(shape * 10, color=color.yellow, linewidth=2,title="VIX SHAPE")iwm = security("IWM", "", close)⋯v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 3: //@version=4 → //@version=5
- Line 16: input(type = input.resolution) → input.timeframe()
- Line 28: security → request.security
- Line 28: security → request.security
- Line 28: security → request.security
- Line 28: security → request.security
33 more edits
- Line 28: security → request.security
- Line 28: security → request.security
- Line 29: security → request.security
- Line 29: security → request.security
- Line 29: security → request.security
- Line 29: security → request.security
- Line 29: security → request.security
- Line 29: security → request.security
- Line 34: ema → ta.ema
- Line 34: ema → ta.ema
- Line 34: ema → ta.ema
- Line 34: ema → ta.ema
- Line 44: transp = 75 → color.new(long ? color.green : short ? color.red : color.white, 75)
- Line 49: ema → ta.ema
- Line 50: ema → ta.ema
- Line 51: ema → ta.ema
- Line 52: ema → ta.ema
- Line 59: sma → ta.sma
- Line 60: stdev → ta.stdev
- Line 65: security → request.security
- Line 66: security → request.security
- Line 71: sma → ta.sma
- Line 71: security → request.security
- Line 73: security → request.security
- Line 76: security → request.security
- Line 77: sma → ta.sma
- Line 82: security → request.security
- Line 83: security → request.security
- Line 84: security → request.security
- Line 90: security → request.security
- Line 91: sma → ta.sma
- Line 93: crossunder → ta.crossunder
- Line 98: crossover → ta.crossover
⋯// © sparrow_hawk_737-//@version=4+//@version=5strategy("McClellan Oscillator Strategy", default_qty_type=strategy.percent_of_equity, default_qty_value=100)⋯useCTF=input(false, title="Use Custom Timeframe?"), -tf=useCTF?input("D", type=input.resolution, title="Custom Timeframe"):timeframe.period // Recommend NOT enabling this+tf=useCTF?input.timeframe("D", title="Custom Timeframe"):timeframe.period // Recommend NOT enabling thisgaps=barmerge.gaps_off // Recommend leaving this OFF⋯ai=0.0, di=0.0-adv=use_ny*nz(security("ADVN.NY", tf, src, gaps))+use_nq*nz(security("ADVN.NQ", tf, src, gaps))+use_us*nz(security("ADVN.US", tf, src, gaps))+use_dj*nz(security("ADVN.DJ", tf, src, gaps))+use_ax*nz(security("ADVN.AX", tf, src, gaps))+use_am*nz(security("ADVN.AM", tf, src, gaps))+adv=use_ny*nz(request.security("ADVN.NY", tf, src, gaps))+use_nq*nz(request.security("ADVN.NQ", tf, src, gaps))+use_us*nz(request.security("ADVN.US", tf, src, gaps))+use_dj*nz(request.security("ADVN.DJ", tf, src, gaps))+use_ax*nz(request.security("ADVN.AX", tf, src, gaps))+use_am*nz(request.security("ADVN.AM", tf, src, gaps))-dec=use_ny*nz(security("DECL.NY", tf, src, gaps))+use_nq*nz(security("DECL.NQ", tf, src, gaps))+use_us*nz(security("DECL.US", tf, src, gaps))+use_dj*nz(security("DECL.DJ", tf, src, gaps))+use_ax*nz(security("DECL.AX", tf, src, gaps))+use_am*nz(security("DECL.AM", tf, src, gaps))+dec=use_ny*nz(request.security("DECL.NY", tf, src, gaps))+use_nq*nz(request.security("DECL.NQ", tf, src, gaps))+use_us*nz(request.security("DECL.US", tf, src, gaps))+use_dj*nz(request.security("DECL.DJ", tf, src, gaps))+use_ax*nz(request.security("DECL.AX", tf, src, gaps))+use_am*nz(request.security("DECL.AM", tf, src, gaps))ai:=ai+adv, di:=di+dec⋯mtwol = input(36, "mo2 length")-e1=isRA?ema(rana, moonel):ema(ai-di, moonel),e2=isRA?ema(rana, mtwol):ema(ai-di, mtwol)+e1=isRA?ta.ema(rana, moonel):ta.ema(ai-di, moonel),e2=isRA?ta.ema(rana, mtwol):ta.ema(ai-di, mtwol)mo=e1-e2⋯long= mo<=-100 and mo>mo[1]-bgcolor(long ? color.green : short ? color.red : color.white, transp=75)+bgcolor(color.new(long ? color.green : short ? color.red : color.white, 75))alertcondition(long and not long[1], "McC long ", "McC long ")⋯inpos = strategy.position_size > 0-mas1 = ema(mo, fastLengthSell)+mas1 = ta.ema(mo, fastLengthSell)-mas2 = ema(mo, slowLengthSell)+mas2 = ta.ema(mo, slowLengthSell)-mab1 = ema(mo, fastLengthBuy)+mab1 = ta.ema(mo, fastLengthBuy)-mab2 = ema(mo, slowLengthBuy)+mab2 = ta.ema(mo, slowLengthBuy)plot(mas1, color=color.blue, linewidth=2, title="39 EMA")⋯ mult = 2- basis = sma(x, length)+ basis = ta.sma(x, length)- dev = mult * stdev(x, length)+ dev = mult * ta.stdev(x, length) upper = basis + dev⋯ -vxx = security("VXX", "", close)+vxx = request.security("VXX", "", close)-vvix = security("VVIX", "", close)+vvix = request.security("VVIX", "", close)bbr1 = get_bbr(vvix, input(10, title="vvix bbr length"))⋯// 25 is the max observed so far-mmth = sma(security(input("MMOH", "Percent of stocks above X"), "", close), input(20, "percent of stocks length"))+mmth = ta.sma(request.security(input("MMOH", "Percent of stocks above X"), "", close), input(20, "percent of stocks length"))mmthlow =( ( mmth[0] - mmth[1] ) + ( mmth[1] - mmth[2] ) + ( mmth[2] - mmth[3] ) ) / 3 < 0-mmfi = security("MMFI", "", close)+mmfi = request.security("MMFI", "", close)mmfibbr = get_bbr(mmfi, 100)buy2 = mmfibbr >= 0 and ( mmfibbr[1] <= 0.01)-skew = security("SKEW", "", close)+skew = request.security("SKEW", "", close)-skewma = sma(skew, input(10, "SKEW MA LENGTH"))+skewma = ta.sma(skew, input(10, "SKEW MA LENGTH"))skewpos = ( ( (skewma - skewma[1]) + (skewma[1] - skewma[2]) + (skewma[2] - skewma[3]) ) / 3) > 0⋯extremenegativeskew = (skbbr > skewthresh) or (skbbr[1] > skewthresh)-v1 = security("VX1!", "", close)+v1 = request.security("VX1!", "", close)-v2 = security("VX2!", "", close)+v2 = request.security("VX2!", "", close)-vix = security("VIX", "", close)+vix = request.security("VIX", "", close)roll_yield = (v1 - vix) / vix⋯plot(shape * 10, color=color.yellow, linewidth=2,title="VIX SHAPE")-iwm = security("IWM", "", close)+iwm = request.security("IWM", "", close)-iwmma12 = sma(iwm, input(12))+iwmma12 = ta.sma(iwm, input(12))buy3 = iwm > iwmma12-sell = rysell and mmthlow and ( crossunder(mas1, mas2) or mas1 < mas2 ) and ( bbr1 >= 0.90 or bbr2 >= 0.90 and mas1 < mas1[1]) and not extremenegativeskew and not buy3+sell = rysell and mmthlow and ( ta.crossunder(mas1, mas2) or mas1 < mas2 ) and ( bbr1 >= 0.90 or bbr2 >= 0.90 and mas1 < mas1[1]) and not extremenegativeskew and not buy3preznobuy = ((year - 2004) % 4 == 0 and month == 10 ? dayofmonth < 10 and dayofmonth > 31 : true) ⋯ strategy.entry("extremenegativeskew", strategy.long)-if (preznobuy and ( (crossover(mab1, mab2) or mab1 > mab2)) and strategy.position_size <= 0)+if (preznobuy and ( (ta.crossover(mab1, mab2) or mab1 > mab2)) and strategy.position_size <= 0) strategy.entry("mab cross", strategy.long)⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 5: input() → input.bool()
- Line 6: input() → input.bool()
- Line 7: input() → input.bool()
- Line 8: input() → input.int()
- Line 9: input() → input.bool()
- Line 10: input() → input.bool()
22 more edits
- Line 11: input() → input.int()
- Line 12: input() → input.int()
- Line 13: input() → input.int()
- Line 14: input() → input.int()
- Line 15: input() → input.bool()
- Line 21: input() → input.float()
- Line 22: input() → input.int()
- Line 23: input() → input.float()
- Line 24: input() → input.int()
- Line 25: input() → input.float()
- Line 26: input() → input.int()
- Line 32: input() → input.int()
- Line 33: input() → input.int()
- Line 67: input() → input.int()
- Line 68: input() → input.int()
- Line 69: input() → input.bool()
- Line 71: input() → input.string()
- Line 71: input() → input.int()
- Line 77: input() → input.int()
- Line 79: input() → input.int()
- Line 80: input() → input.float()
- Line 91: input() → input.int()
⋯strategy("McClellan Oscillator Strategy", default_qty_type=strategy.percent_of_equity, default_qty_value=100)-exitWhenOscIsZero = input(false, title="Exit when oscillator goes under 0?")+exitWhenOscIsZero = input.bool(false, title="Exit when oscillator goes under 0?")-enterWhenOscIsZero = input(false, title="Enter when oscillator goes over 0?")+enterWhenOscIsZero = input.bool(false, title="Enter when oscillator goes over 0?")-isRA=input(true, title="Stockcharts version (Ratio Adjusted)?")+isRA=input.bool(true, title="Stockcharts version (Ratio Adjusted)?")-rm=input(defval=1000, title="RANA ratio multiplier")+rm=input.int(defval=1000, title="RANA ratio multiplier")-showEMAs=input(false, title="Show EMAs?")+showEMAs=input.bool(false, title="Show EMAs?")-showOsc=input(true, title="Show Oscillator?")+showOsc=input.bool(true, title="Show Oscillator?")-slowLengthSell = input(20, title="Slow Length Sell")+slowLengthSell = input.int(20, title="Slow Length Sell")-fastLengthSell = input(9, title="Fast Length Sell")+fastLengthSell = input.int(9, title="Fast Length Sell")-slowLengthBuy = input(20, title="Slow Length Buy")+slowLengthBuy = input.int(20, title="Slow Length Buy")-fastLengthBuy = input(9, title="Fast Length Buy")+fastLengthBuy = input.int(9, title="Fast Length Buy")-useCTF=input(false, title="Use Custom Timeframe?"), +useCTF=input.bool(false, title="Use Custom Timeframe?"), tf=useCTF?input.timeframe("D", title="Custom Timeframe"):timeframe.period // Recommend NOT enabling this⋯// varianta cu toate bursele, dar uneori (f rar) cea cu NYSE le da mai devreme.-use_ny=input(100.0,"NYSE %")/100+use_ny=input.float(100.0,"NYSE %")/100-use_nq=input(0,"NASDAQ %")/100+use_nq=input.int(0,"NASDAQ %")/100-use_us=input(100.0,"US %")/100+use_us=input.float(100.0,"US %")/100-use_dj=input(0,"DJ %")/100+use_dj=input.int(0,"DJ %")/100-use_ax=input(100.0,"AX %")/100+use_ax=input.float(100.0,"AX %")/100-use_am=input(0,"AM %")/100+use_am=input.int(0,"AM %")/100ai=0.0, di=0.0⋯rana=rm * (ai-di)/(ai+di)-moonel = input(16, "mo1 length")+moonel = input.int(16, "mo1 length")-mtwol = input(36, "mo2 length")+mtwol = input.int(36, "mo2 length")e1=isRA?ta.ema(rana, moonel):ta.ema(ai-di, moonel),e2=isRA?ta.ema(rana, mtwol):ta.ema(ai-di, mtwol)⋯vvix = request.security("VVIX", "", close)-bbr1 = get_bbr(vvix, input(10, title="vvix bbr length"))+bbr1 = get_bbr(vvix, input.int(10, title="vvix bbr length"))-bbr2 = get_bbr(vxx, input(20,title="vxx bbr length"))+bbr2 = get_bbr(vxx, input.int(20,title="vxx bbr length"))-mmthsell = input(true, "Only sell when percent of X stocks is in downtrend")+mmthsell = input.bool(true, "Only sell when percent of X stocks is in downtrend")// 25 is the max observed so far-mmth = ta.sma(request.security(input("MMOH", "Percent of stocks above X"), "", close), input(20, "percent of stocks length"))+mmth = ta.sma(request.security(input.string("MMOH", "Percent of stocks above X"), "", close), input.int(20, "percent of stocks length"))mmthlow =( ( mmth[0] - mmth[1] ) + ( mmth[1] - mmth[2] ) + ( mmth[2] - mmth[3] ) ) / 3 < 0⋯skew = request.security("SKEW", "", close)-skewma = ta.sma(skew, input(10, "SKEW MA LENGTH"))+skewma = ta.sma(skew, input.int(10, "SKEW MA LENGTH"))skewpos = ( ( (skewma - skewma[1]) + (skewma[1] - skewma[2]) + (skewma[2] - skewma[3]) ) / 3) > 0-skbbr = get_bbr(skew, input(29, "skew bbr length"))+skbbr = get_bbr(skew, input.int(29, "skew bbr length"))-skewthresh = input(1.1, "skew bbr thresh")+skewthresh = input.float(1.1, "skew bbr thresh")extremenegativeskew = (skbbr > skewthresh) or (skbbr[1] > skewthresh)⋯iwm = request.security("IWM", "", close)-iwmma12 = ta.sma(iwm, input(12))+iwmma12 = ta.sma(iwm, input.int(12))buy3 = iwm > iwmma12⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © sparrow_hawk_737-//@version=5+//@version=6strategy("McClellan Oscillator Strategy", default_qty_type=strategy.percent_of_equity, default_qty_value=100)⋯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 |
|---|---|---|---|
| Exit when oscillator goes under 0? | false | bool | unused |
| Enter when oscillator goes over 0? | false | bool | unused |
| Stockcharts version (Ratio Adjusted)? | true | bool | e1 e2 |
| RANA ratio multiplier | 1000 | int | rana |
| Show EMAs? | false | bool | 19 EMA 39 EMA |
| Show Oscillator? | true | bool | - + MO |
| Slow Length Sell | 20 | int | mas2 |
| Fast Length Sell | 9 | int | mas1 |
| Slow Length Buy | 20 | int | mab2 |
| Fast Length Buy | 9 | int | mab1 |
| Use Custom Timeframe? | false | bool | tf |
| Custom Timeframe | D | timeframe (written resolution) | adv dec |
| NYSE % | 100.0 | float | adv dec |
| NASDAQ % | 0 | int | adv dec |
| US % | 100.0 | float | adv dec |
| DJ % | 0 | int | adv dec |
| AX % | 100.0 | float | adv dec |
| AM % | 0 | int | adv dec |
| mo1 length | 16 | int | e1 |
| mo2 length | 36 | int | e2 |
| vvix bbr length | 10 | int | sell |
| vxx bbr length | 20 | int | sell |
| Only sell when percent of X stocks is in downtrend | true | bool | unused |
| Percent of stocks above X | MMOH | string | mmthlow |
| percent of stocks length | 20 | int | mmthlow |
| SKEW MA LENGTH | 10 | int | skewpos |
| skew bbr length | 29 | int | extremenegativeskew |
| skew bbr thresh | 1.1 | float | extremenegativeskew |
| Iwmma12 (no label in the script) | 12 | int | buy3 |
What it calculates
- EMA (
ema,ta.emain v5)rana, mo1 length (16)e1 · line 34 - EMA (
ema,ta.emain v5)rana, mo2 length (36)e2 · line 34 - EMA (
ema,ta.emain v5)mo, Fast Length Sell (9)mas1 · line 49 - EMA (
ema,ta.emain v5)mo, Slow Length Sell (20)mas2 · line 50 - EMA (
ema,ta.emain v5)mo, Fast Length Buy (9)mab1 · line 51 - EMA (
ema,ta.emain v5)mo, Slow Length Buy (20)mab2 · line 52 - SMA (
sma,ta.smain v5)x, lengthbasis · line 59 - Stdev (
stdev,ta.stdevin v5)x, lengthdev · line 60
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.
The script has 70 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open extremenegativeskew long | (preznobuy and extremenegativeskew and strategy.position_size <= 0) | On | 97 |
| Open mab cross long | (preznobuy and ( (crossover(mab1, mab2) or mab1 > mab2)) and strategy.position_size <= 0) | On | 99 |
| Open mmfi + skew bottom long | (preznobuy and (buy2 and skewpos) and strategy.position_size <= 0) | On | 102 |
| Open RUS bottom long | (preznobuy and (buy3 and skewpos) and strategy.position_size <= 0) | On | 105 |
| Close | ((prezsell or sell) and strategy.position_size > 0) | On | 108 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| McC long | alertcondition | McC long | 45 |
| McC short | alertcondition | McC short | 46 |
Does it repaint?
No
No repainting patterns in the source.
- ClearHigher-timeframe data21 security call(s), none with lookahead on.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo calc_on_every_tick. 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
Not run on other markets: the script requests ADVN.NY D, ADVN.NQ D, ADVN.US D, ADVN.DJ D, ADVN.AX D, ADVN.AM D, DECL.NY D, DECL.NQ D, DECL.US D, DECL.DJ D, DECL.AX D, DECL.AM D, VXX D, VVIX D, MMOH D, MMFI D, SKEW D, VX1! D, VX2! D, VIX D, IWM D, and that data is not available here (not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market). Its results would rest on empty values.
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 |
|---|---|---|---|---|---|
| McClellan Oscillator Strategy this page | — | v3 strategy | 0.0% | 0 | 0.0% |
| Volume Weighted Bollinger Bands Strategy by Ankit_1618 | ema sma stdev | v4 strategy | +10.0% | 15 | 27.5% |
| BB21_MA200_Strategy by mohanee | ema sma stdev | v4 strategy | No trades on this market | ||
| Super Breakout day trading by beststockalert | stdev sma ema | v4 strategy | No trades on this market | ||
| Super Auto Breakout Day Trade Volatile stocks by beststockalert | stdev sma ema | v4 strategy | −6.1% | 51 | 29.1% |
| VFI strategy [based on VFI indicator published by UTS] by mohanee | sma stdev ema | v4 strategy | +181.4% | 8 | 154.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 78 ms | With a workaround 1,000 bars in 137 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/// © sparrow_hawk_737//@version=3strategy("McClellan Oscillator Strategy", default_qty_type=strategy.percent_of_equity, default_qty_value=100)exitWhenOscIsZero = input(false, title="Exit when oscillator goes under 0?")enterWhenOscIsZero = input(false, title="Enter when oscillator goes over 0?")isRA=input(true, title="Stockcharts version (Ratio Adjusted)?")rm=input(defval=1000, title="RANA ratio multiplier")showEMAs=input(false, title="Show EMAs?")showOsc=input(true, title="Show Oscillator?")slowLengthSell = input(20, title="Slow Length Sell")fastLengthSell = input(9, title="Fast Length Sell")slowLengthBuy = input(20, title="Slow Length Buy")fastLengthBuy = input(9, title="Fast Length Buy")useCTF=input(false, title="Use Custom Timeframe?"), tf=useCTF?input("D", type=resolution, title="Custom Timeframe"):period // Recommend NOT enabling thisgaps=barmerge.gaps_off // Recommend leaving this OFFsrc=close// Varianta doar cu NYSE sau doar cu NASDAQ da semnale long mai proaste decat// varianta cu toate bursele, dar uneori (f rar) cea cu NYSE le da mai devreme.use_ny=input(100.0,"NYSE %")/100use_nq=input(0,"NASDAQ %")/100use_us=input(100.0,"US %")/100use_dj=input(0,"DJ %")/100use_ax=input(100.0,"AX %")/100use_am=input(0,"AM %")/100ai=0.0, di=0.0adv=use_ny*nz(security("ADVN.NY", tf, src, gaps))+use_nq*nz(security("ADVN.NQ", tf, src, gaps))+use_us*nz(security("ADVN.US", tf, src, gaps))+use_dj*nz(security("ADVN.DJ", tf, src, gaps))+use_ax*nz(security("ADVN.AX", tf, src, gaps))+use_am*nz(security("ADVN.AM", tf, src, gaps))dec=use_ny*nz(security("DECL.NY", tf, src, gaps))+use_nq*nz(security("DECL.NQ", tf, src, gaps))+use_us*nz(security("DECL.US", tf, src, gaps))+use_dj*nz(security("DECL.DJ", tf, src, gaps))+use_ax*nz(security("DECL.AX", tf, src, gaps))+use_am*nz(security("DECL.AM", tf, src, gaps))ai:=ai+adv, di:=di+decrana=rm * (ai-di)/(ai+di)moonel = input(16, "mo1 length")mtwol = input(36, "mo2 length")e1=isRA?ema(rana, moonel):ema(ai-di, moonel),e2=isRA?ema(rana, mtwol):ema(ai-di, mtwol)mo=e1-e2hline(0, title="0")plot(showOsc?mo<0?mo:0:na, style=area, color=white, title="-")plot(showOsc?mo>=0?mo:0:na, style=area, color=white, title="+")plot(showOsc?mo:na, style=line, color=black, title="MO", linewidth=2)plot(showEMAs?e1:na, color=blue, linewidth=2, title="19 EMA")plot(showEMAs?e2:na, color=red, linewidth=2, title="39 EMA")short= mo>=100 and mo<mo[1]long= mo<=-100 and mo>mo[1]bgcolor(long ? green : short ? red : white, transp=75)alertcondition(long and not long[1], "McC long ", "McC long ")alertcondition(short and not short[1], "McC short ", "McC short ")exited = falseinpos = strategy.position_size > 0mas1 = ema(mo, fastLengthSell)mas2 = ema(mo, slowLengthSell)mab1 = ema(mo, fastLengthBuy)mab2 = ema(mo, slowLengthBuy)plot(mas1, color=blue, linewidth=2, title="39 EMA")plot(mas2, color=orange, linewidth=2, title="39 EMA")plot(mab1, color=red, linewidth=2, title="39 EMA")plot(mab2, color=black, linewidth=2, title="39 EMA")get_bbr(x, length) => mult = 2 basis = sma(x, length) dev = mult * stdev(x, length) upper = basis + dev lower = basis - dev (x - lower)/(upper - lower) vxx = security("VXX", "", close)vvix = security("VVIX", "", close)bbr1 = get_bbr(vvix, input(10, title="vvix bbr length"))bbr2 = get_bbr(vxx, input(20,title="vxx bbr length"))mmthsell = input(true, "Only sell when percent of X stocks is in downtrend")// 25 is the max observed so farmmth = sma(security(input("MMOH", "Percent of stocks above X"), "", close), input(20, "percent of stocks length"))mmthlow =( ( mmth[0] - mmth[1] ) + ( mmth[1] - mmth[2] ) + ( mmth[2] - mmth[3] ) ) / 3 < 0mmfi = security("MMFI", "", close)mmfibbr = get_bbr(mmfi, 100)buy2 = mmfibbr >= 0 and ( mmfibbr[1] <= 0.01)skew = security("SKEW", "", close)skewma = sma(skew, input(10, "SKEW MA LENGTH"))skewpos = ( ( (skewma - skewma[1]) + (skewma[1] - skewma[2]) + (skewma[2] - skewma[3]) ) / 3) > 0skbbr = get_bbr(skew, input(29, "skew bbr length"))skewthresh = input(1.1, "skew bbr thresh")extremenegativeskew = (skbbr > skewthresh) or (skbbr[1] > skewthresh)v1 = security("VX1!", "", close)v2 = security("VX2!", "", close)vix = security("VIX", "", close)roll_yield = (v1 - vix) / vixshape = ( v2 - v1 )rysell = roll_yield <= 0.01plot(roll_yield * 100, color=orange, linewidth=2,title="ROLL YIELD")plot(shape * 10, color=yellow, linewidth=2,title="VIX SHAPE")iwm = security("IWM", "", close)iwmma12 = sma(iwm, input(12))buy3 = iwm > iwmma12sell = rysell and mmthlow and ( crossunder(mas1, mas2) or mas1 < mas2 ) and ( bbr1 >= 0.90 or bbr2 >= 0.90 and mas1 < mas1[1]) and not extremenegativeskew and not buy3preznobuy = ((year - 2004) % 4 == 0 and month == 10 ? dayofmonth < 10 and dayofmonth > 31 : true) prezsell = ((year - 2004) % 4 == 0 and month == 10 ? dayofmonth >= 10 and dayofmonth <= 17 : false)if (preznobuy and extremenegativeskew and strategy.position_size <= 0) strategy.entry("extremenegativeskew", strategy.long)if (preznobuy and ( (crossover(mab1, mab2) or mab1 > mab2)) and strategy.position_size <= 0) strategy.entry("mab cross", strategy.long) if (preznobuy and (buy2 and skewpos) and strategy.position_size <= 0) strategy.entry("mmfi + skew bottom", strategy.long) if (preznobuy and (buy3 and skewpos) and strategy.position_size <= 0) strategy.entry("RUS bottom", strategy.long) if ((prezsell or sell) and strategy.position_size > 0) strategy.close_all()