Pine Script v4 · Strategy
Swing Stock Market Multi MA Correlation
A Pine Script v4 strategy with no technical-analysis calculation. 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. 11 settings; defaults include Ma1 type SMMA (RMA), Ma1 length 20 and Ma2 type EMA.
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 Swing Stock Market Multi MA Correlation repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Swing Stock Market Multi MA Correlation 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 Swing Stock Market Multi MA Correlation 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.
- Does Swing Stock Market Multi MA Correlation use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Swing Stock Market Multi MA Correlation run in Zeal Terminal?
- Yes
- It compiles in 12 ms and runs 1,000 bars in 51 ms, in the browser.
BTCUSDT · 1D · default settings
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs TVC:SPX 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, $1,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
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
6 settings have no label
In the settings dialog ma1_type (line 24), ma1_length (line 26), ma2_type (line 28), ma2_length (line 30), ma3_type (line 32), ma3_length (line 34) 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 43, 44, 47, 48. 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 security → request.security, heikinashi → ticker.heikinashi, sma → ta.sma, ema → ta.ema, rma → ta.rma, wma → ta.wma, vwma → ta.vwma.
- 4 strategy calls use the when = argument (line 43, 44, 47, 48). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
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 11: security → request.security
- Line 11: heikinashi → ticker.heikinashi
- Line 11: security → request.security
- Line 11: security → request.security
- Line 12: security → request.security
19 more edits
- Line 12: heikinashi → ticker.heikinashi
- Line 12: security → request.security
- Line 12: security → request.security
- Line 13: security → request.security
- Line 13: heikinashi → ticker.heikinashi
- Line 13: security → request.security
- Line 13: security → request.security
- Line 14: security → request.security
- Line 14: heikinashi → ticker.heikinashi
- Line 14: security → request.security
- Line 14: security → request.security
- Line 16: type is reserved in v5: renamed type_
- Line 17: sma → ta.sma
- Line 18: ema → ta.ema
- Line 19: rma → ta.rma
- Line 20: wma → ta.wma
- Line 21: vwma → ta.vwma
- Line 43: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
- Line 47: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
⋯// © exlux99-//@version=4+//@version=5strategy(title = "Multi MA Correlation Stocks", overlay = true,initial_capital = 1000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent,commission_value=0.01)⋯// === BASE FUNCTIONS ===-haClose = useha ? security(heikinashi(syminfo.tickerid), timeframe.period, close) : usesp500 ? security(("TVC:SPX"), timeframe.period, close) : usenasdaq ? security(("TVC:NDX"), timeframe.period, close) :close+haClose = useha ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close) : usesp500 ? request.security(("TVC:SPX"), timeframe.period, close) : usenasdaq ? request.security(("TVC:NDX"), timeframe.period, close) :close-haOpen = useha ? security(heikinashi(syminfo.tickerid), timeframe.period, open) : usesp500 ? security(("TVC:SPX"), timeframe.period, open) : usenasdaq ? security(("TVC:NDX"), timeframe.period, open) :open+haOpen = useha ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open) : usesp500 ? request.security(("TVC:SPX"), timeframe.period, open) : usenasdaq ? request.security(("TVC:NDX"), timeframe.period, open) :open-haHigh = useha ? security(heikinashi(syminfo.tickerid), timeframe.period, high) : usesp500 ? security(("TVC:SPX"), timeframe.period, high) : usenasdaq ? security(("TVC:NDX"), timeframe.period, high) :high+haHigh = useha ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high) : usesp500 ? request.security(("TVC:SPX"), timeframe.period, high) : usenasdaq ? request.security(("TVC:NDX"), timeframe.period, high) :high-haLow = useha ? security(heikinashi(syminfo.tickerid), timeframe.period, low) : usesp500 ? security(("TVC:SPX"), timeframe.period, low) : usenasdaq ? security(("TVC:NDX"), timeframe.period, low) :low+haLow = useha ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low) : usesp500 ? request.security(("TVC:SPX"), timeframe.period, low) : usenasdaq ? request.security(("TVC:NDX"), timeframe.period, low) :lowaverage = (haClose+haOpen+haHigh+haLow)/4-ma(source, length, type) =>+ma(source, length, type_) =>- type == "SMA" ? sma(source, length) : + type_ == "SMA" ? ta.sma(source, length) : - type == "EMA" ? ema(source, length) :+ type_ == "EMA" ? ta.ema(source, length) :- type == "SMMA (RMA)" ? rma(source, length) : + type_ == "SMMA (RMA)" ? ta.rma(source, length) : - type == "WMA" ? wma(source, length) :+ type_ == "WMA" ? ta.wma(source, length) :- type == "VWMA" ? vwma(source, length) :+ type_ == "VWMA" ? ta.vwma(source, length) : na⋯if(longEntry)- strategy.entry("long",1,when=long)+ strategy.entry("long",strategy.long,when=long) strategy.close("long",when=longexit)⋯if(shortEntry)- strategy.entry("short",0,when=short)+ strategy.entry("short",strategy.short,when=short) strategy.close("short",when=shortexit)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 24: input() → input.string()
- Line 26: input() → input.int()
- Line 28: input() → input.string()
9 more edits
- Line 30: input() → input.int()
- Line 32: input() → input.string()
- Line 34: input() → input.int()
- Line 40: input() → input.bool()
- Line 41: input() → input.bool()
- Line 43: when = long → if block
- Line 44: when = longexit → if block
- Line 47: when = short → if block
- Line 48: when = shortexit → if block
⋯strategy(title = "Multi MA Correlation Stocks", overlay = true,initial_capital = 1000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent,commission_value=0.01)-useha = input(false, title="Use Heikin Ashi Candles in Algo Calculations")+useha = input.bool(false, title="Use Heikin Ashi Candles in Algo Calculations")-usesp500 = input(true, title="Use SP500 Candles in Algo Calculations")+usesp500 = input.bool(true, title="Use SP500 Candles in Algo Calculations")-usenasdaq = input(false, title="Use Nasdaq Candles in Algo Calculations")+usenasdaq = input.bool(false, title="Use Nasdaq Candles in Algo Calculations")//⋯ -ma1_type = input("SMMA (RMA)" , "" , inline="MA #1", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])+ma1_type = input.string("SMMA (RMA)" , "" , inline="MA #1", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])ma1_source = average-ma1_length = input(20 , "" , inline="MA #1", minval=1)+ma1_length = input.int(20 , "" , inline="MA #1", minval=1)ma1 = ma(ma1_source, ma1_length, ma1_type)-ma2_type = input("EMA" , "" , inline="MA #2", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])+ma2_type = input.string("EMA" , "" , inline="MA #2", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])ma2_source = average-ma2_length = input(50 , "" , inline="MA #2", minval=1)+ma2_length = input.int(50 , "" , inline="MA #2", minval=1)ma2 = ma(ma2_source, ma2_length, ma2_type)-ma3_type = input("WMA" , "" , inline="MA #3", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])+ma3_type = input.string("WMA" , "" , inline="MA #3", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])ma3_source = average-ma3_length = input(100 , "" , inline="MA #3", minval=1)+ma3_length = input.int(100 , "" , inline="MA #3", minval=1)ma3 = ma(ma3_source, ma3_length, ma3_type)⋯shortexit=ma1>ma2 and ma2>ma3-longEntry=input(true, title="Long Entries ?")+longEntry=input.bool(true, title="Long Entries ?")-shortEntry=input(true, title="Short Entries ?")+shortEntry=input.bool(true, title="Short Entries ?")if(longEntry)- strategy.entry("long",strategy.long,when=long)+ if long+ strategy.entry("long",strategy.long)- strategy.close("long",when=longexit)+ if longexit+ strategy.close("long") if(shortEntry)- strategy.entry("short",strategy.short,when=short)+ if short+ strategy.entry("short",strategy.short)- strategy.close("short",when=shortexit)+ if shortexit+ strategy.close("short")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.
⋯// © exlux99-//@version=5+//@version=6strategy(title = "Multi MA Correlation Stocks", overlay = true,initial_capital = 1000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent,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 |
|---|---|---|---|
| Use Heikin Ashi Candles in Algo Calculations | false | bool | haClose haOpen haHigh haLow |
| Use SP500 Candles in Algo Calculations | true | bool | haClose haOpen haHigh haLow |
| Use Nasdaq Candles in Algo Calculations | false | bool | haClose haOpen haHigh haLow |
| Ma1 type (no label in the script) | SMMA (RMA) | string · options ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"] | ma1 |
| Ma1 length (no label in the script) | 20 | int · min 1 | ma1 |
| Ma2 type (no label in the script) | EMA | string · options ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"] | ma2 |
| Ma2 length (no label in the script) | 50 | int · min 1 | ma2 |
| Ma3 type (no label in the script) | WMA | string · options ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"] | ma3 |
| Ma3 length (no label in the script) | 100 | int · min 1 | ma3 |
| Long Entries ? | true | bool | entry long close long line 42 |
| Short Entries ? | true | bool | entry short close short line 46 |
What it calculates
No technical-analysis calculation: the script works on prices and settings directly.
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 long long | longma1>ma2 and ma2>ma3 | On | 43 |
| Close long | longexitma1<ma2 and ma2<ma3 | On | 44 |
| Open short short | shortma1<ma2 and ma2<ma3 | On | 47 |
| Close short | shortexitma1>ma2 and ma2>ma3 | On | 48 |
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.
- ClearHigher-timeframe data12 security call(s), none with lookahead on.
- 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
Not run on other markets: the script requests TVC:SPX D, and that data is not available here (not a Binance spot market). Its results would rest on empty values.
Similar scripts
No other indicator or strategy here shares enough of its calculations.
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 12 ms | With a workaround 1,000 bars in 51 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 43, 47) so the engine trades the way the script says. 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/// © exlux99//@version=4strategy(title = "Multi MA Correlation Stocks", overlay = true,initial_capital = 1000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent,commission_value=0.01)useha = input(false, title="Use Heikin Ashi Candles in Algo Calculations")usesp500 = input(true, title="Use SP500 Candles in Algo Calculations")usenasdaq = input(false, title="Use Nasdaq Candles in Algo Calculations")//// === /INPUTS ===// === BASE FUNCTIONS ===haClose = useha ? security(heikinashi(syminfo.tickerid), timeframe.period, close) : usesp500 ? security(("TVC:SPX"), timeframe.period, close) : usenasdaq ? security(("TVC:NDX"), timeframe.period, close) :closehaOpen = useha ? security(heikinashi(syminfo.tickerid), timeframe.period, open) : usesp500 ? security(("TVC:SPX"), timeframe.period, open) : usenasdaq ? security(("TVC:NDX"), timeframe.period, open) :openhaHigh = useha ? security(heikinashi(syminfo.tickerid), timeframe.period, high) : usesp500 ? security(("TVC:SPX"), timeframe.period, high) : usenasdaq ? security(("TVC:NDX"), timeframe.period, high) :highhaLow = useha ? security(heikinashi(syminfo.tickerid), timeframe.period, low) : usesp500 ? security(("TVC:SPX"), timeframe.period, low) : usenasdaq ? security(("TVC:NDX"), timeframe.period, low) :lowaverage = (haClose+haOpen+haHigh+haLow)/4ma(source, length, type) => type == "SMA" ? sma(source, length) : type == "EMA" ? ema(source, length) : type == "SMMA (RMA)" ? rma(source, length) : type == "WMA" ? wma(source, length) : type == "VWMA" ? vwma(source, length) : na ma1_type = input("SMMA (RMA)" , "" , inline="MA #1", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])ma1_source = averagema1_length = input(20 , "" , inline="MA #1", minval=1)ma1 = ma(ma1_source, ma1_length, ma1_type)ma2_type = input("EMA" , "" , inline="MA #2", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])ma2_source = averagema2_length = input(50 , "" , inline="MA #2", minval=1)ma2 = ma(ma2_source, ma2_length, ma2_type)ma3_type = input("WMA" , "" , inline="MA #3", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])ma3_source = averagema3_length = input(100 , "" , inline="MA #3", minval=1)ma3 = ma(ma3_source, ma3_length, ma3_type)long= ma1>ma2 and ma2>ma3short=ma1<ma2 and ma2<ma3longexit=ma1<ma2 and ma2<ma3shortexit=ma1>ma2 and ma2>ma3longEntry=input(true, title="Long Entries ?")shortEntry=input(true, title="Short Entries ?")if(longEntry) strategy.entry("long",1,when=long) strategy.close("long",when=longexit) if(shortEntry) strategy.entry("short",0,when=short) strategy.close("short",when=shortexit)