Pine Script v5 · Strategy
VIDYA Trend Strategy
A Pine Script v5 strategy built on SMA (ohlc4, 50). It has 3 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 4% of equity and pays .075% commission. 4 settings; defaults include VIDYA Length 50 and VIDYA Price Source ohlc4.
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 VIDYA Trend Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 14 of 14 trades.
- How did VIDYA Trend Strategy do on BTCUSDT 1D with default settings?
- −7.13%
- From 26 Jan 2024 to 21 Oct 2026, over 194 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does VIDYA Trend Strategy 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: 194 before, 190 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 VIDYA Trend Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does VIDYA Trend Strategy run in Zeal Terminal?
- Yes
- It compiles in 18 ms and runs 1,000 bars in 28 ms, in the browser.
BTCUSDT · 1D · default settings
- VIDYA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −7.13%
- −$71,314.50
- Buy and hold
- +102.5%
- same period
- Closed trades
- 194
- 50 won · 144 lost
- Profitable
- 25.8%
- of closed trades
- Profit factor
- 0.82
- gross profit ÷ gross loss
- Max drawdown
- 30.34%
- −$303,403.00
One run with the author's default settings, $1,000,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
Uses an argument v6 removed
when = on line 24, 25. The upgraded version below moves each call inside an if block.
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 |
|---|---|---|---|
| Date Range | |||
| Start Time | timestamp('01 Jan 2000 08:00') | time | InDateRange |
| End Time | timestamp('01 Jan 2099 00:00') | time | InDateRange |
| Trend Settings | |||
| VIDYA Length | 50 | int · step 5 | valpha VIDYA |
| VIDYA Price Source | ohlc4 | source | vud1 vdd1 VIDYA |
What it calculates
- SMAVIDYA Price Source (ohlc4), VIDYA Length (50)
VIDYA · line 20
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 | VIDYA>VIDYA[1] | On | 24 |
| Close Long | VIDYA<VIDYA[1] | On | 25 |
| Close | (not InDateRange) | On | 27 |
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.
- 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | −7.1% | +102.5% | 194 | 26% | 0.82 | 30.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +2.1% | +5.5% | 220 | 23% | 1.18 | 9.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −20.1% | +9.8% | 183 | 18% | 0.54 | 44.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +24.4% | +8.4% | 121 | 53% | 7.48 | 3.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −57.3% | +16.7% | 224 | 18% | 0.15 | 59.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +15.8% | +21.5% | 204 | 34% | 1.97 | 11.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −9.8% | +148.3% | 202 | 16% | 0.74 | 35.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +7.4% | +17.1% | 202 | 23% | 1.62 | 10.8% | 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 | 61 | 7% | −$188,386.00 |
| Sideways market | 133 | 35% | $117,769.00 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
11.7%
The 95th percentile of the worst drawdown when the same 194 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 5.3% to 11.7%; the tick is what actually happened, 27.7%. Order luck alone moves it this much.
The first 150 of 194 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 16 Mar 2024 65,300.60 | 1 May 2024 58,365.00 | 46 | −$4,302.05 |
| long | 17 Mar 2024 68,393.50 | 1 May 2024 58,365.00 | 45 | −$5,927.38 |
| long | 18 Mar 2024 67,610.00 | 1 May 2024 58,365.00 | 44 | −$5,526.33 |
| long | 19 Mar 2024 61,937.40 | 1 May 2024 58,365.00 | 43 | −$2,341.69 |
| long | 20 Mar 2024 67,840.50 | 1 May 2024 58,365.00 | 42 | −$5,666.86 |
| long | 21 Mar 2024 65,501.30 | 1 May 2024 58,365.00 | 41 | −$4,402.24 |
| long | 22 Mar 2024 63,796.70 | 1 May 2024 58,365.00 | 40 | −$3,431.78 |
| long | 23 Mar 2024 63,990.00 | 1 May 2024 58,365.00 | 39 | −$3,544.11 |
| long | 24 Mar 2024 67,210.00 | 1 May 2024 58,365.00 | 38 | −$5,359.54 |
| long | 25 Mar 2024 69,880.00 | 1 May 2024 58,365.00 | 37 | −$6,792.38 |
| long | 26 Mar 2024 69,988.00 | 1 May 2024 58,365.00 | 36 | −$6,849.19 |
| long | 27 Mar 2024 69,470.00 | 1 May 2024 58,365.00 | 35 | −$6,572.67 |
| long | 28 Mar 2024 70,780.60 | 1 May 2024 58,365.00 | 34 | −$7,273.06 |
| long | 29 Mar 2024 69,850.60 | 1 May 2024 58,365.00 | 33 | −$6,773.35 |
| long | 30 Mar 2024 69,582.20 | 1 May 2024 58,365.00 | 32 | −$6,626.97 |
| long | 31 Mar 2024 71,280.00 | 1 May 2024 58,365.00 | 31 | −$7,551.71 |
| long | 1 Apr 2024 69,649.80 | 1 May 2024 58,365.00 | 30 | −$6,657.52 |
| long | 2 Apr 2024 65,464.00 | 1 May 2024 58,365.00 | 29 | −$4,289.51 |
| long | 3 Apr 2024 65,963.30 | 1 May 2024 58,365.00 | 28 | −$4,577.66 |
| long | 4 Apr 2024 68,487.80 | 1 May 2024 58,365.00 | 27 | −$6,027.57 |
| long | 5 Apr 2024 67,820.60 | 1 May 2024 58,365.00 | 26 | −$5,644.18 |
| long | 6 Apr 2024 68,896.00 | 1 May 2024 58,365.00 | 25 | −$6,264.97 |
| long | 7 Apr 2024 69,360.40 | 1 May 2024 58,365.00 | 24 | −$6,533.88 |
| long | 8 Apr 2024 71,620.00 | 1 May 2024 58,365.00 | 23 | −$7,848.23 |
| long | 9 Apr 2024 69,146.00 | 1 May 2024 58,365.00 | 22 | −$6,399.36 |
| long | 3 May 2024 62,882.00 | 24 Jun 2024 60,293.30 | 52 | −$1,460.19 |
| long | 4 May 2024 63,892.10 | 24 Jun 2024 60,293.30 | 51 | −$1,980.12 |
| long | 5 May 2024 64,012.00 | 24 Jun 2024 60,293.30 | 50 | −$2,040.92 |
| long | 6 May 2024 63,165.20 | 24 Jun 2024 60,293.30 | 49 | −$1,605.86 |
| long | 7 May 2024 62,312.10 | 24 Jun 2024 60,293.30 | 48 | −$1,156.51 |
| long | 8 May 2024 61,193.00 | 24 Jun 2024 60,293.30 | 47 | −$550.86 |
| long | 9 May 2024 63,074.00 | 24 Jun 2024 60,293.30 | 46 | −$1,560.85 |
| long | 10 May 2024 60,800.00 | 24 Jun 2024 60,293.30 | 45 | −$333.33 |
| long | 11 May 2024 60,826.00 | 24 Jun 2024 60,293.30 | 44 | −$347.73 |
| long | 12 May 2024 61,484.00 | 24 Jun 2024 60,293.30 | 43 | −$709.98 |
| long | 13 May 2024 62,940.10 | 24 Jun 2024 60,293.30 | 42 | −$1,495.67 |
| long | 14 May 2024 61,577.50 | 24 Jun 2024 60,293.30 | 41 | −$760.38 |
| long | 15 May 2024 66,206.50 | 24 Jun 2024 60,293.30 | 40 | −$3,199.11 |
| long | 16 May 2024 65,235.20 | 24 Jun 2024 60,293.30 | 39 | −$2,700.09 |
| long | 17 May 2024 67,024.00 | 24 Jun 2024 60,293.30 | 38 | −$3,617.73 |
| long | 18 May 2024 66,915.20 | 24 Jun 2024 60,293.30 | 37 | −$3,562.14 |
| long | 19 May 2024 66,274.00 | 24 Jun 2024 60,293.30 | 36 | −$3,232.50 |
| long | 20 May 2024 71,446.60 | 24 Jun 2024 60,293.30 | 35 | −$5,853.69 |
| long | 21 May 2024 70,148.40 | 24 Jun 2024 60,293.30 | 34 | −$5,201.63 |
| long | 22 May 2024 69,166.60 | 24 Jun 2024 60,293.30 | 33 | −$4,702.27 |
| long | 23 May 2024 67,969.70 | 24 Jun 2024 60,293.30 | 32 | −$4,086.89 |
| long | 24 May 2024 68,550.00 | 24 Jun 2024 60,293.30 | 31 | −$4,386.97 |
| long | 25 May 2024 69,290.60 | 24 Jun 2024 60,293.30 | 30 | −$4,771.05 |
| long | 26 May 2024 68,507.70 | 24 Jun 2024 60,293.30 | 29 | −$4,362.73 |
| long | 27 May 2024 69,436.40 | 24 Jun 2024 60,293.30 | 28 | −$4,849.35 |
| long | 15 Jul 2024 64,724.20 | 3 Aug 2024 60,698.00 | 19 | −$2,005.74 |
| long | 16 Jul 2024 65,044.00 | 3 Aug 2024 60,698.00 | 18 | −$2,151.29 |
| long | 17 Jul 2024 64,088.00 | 3 Aug 2024 60,698.00 | 17 | −$1,710.88 |
| long | 18 Jul 2024 63,987.90 | 3 Aug 2024 60,698.00 | 16 | −$1,663.94 |
| long | 19 Jul 2024 66,660.00 | 3 Aug 2024 60,698.00 | 15 | −$2,878.48 |
| long | 20 Jul 2024 67,140.00 | 3 Aug 2024 60,698.00 | 14 | −$3,088.96 |
| long | 21 Jul 2024 68,165.40 | 3 Aug 2024 60,698.00 | 13 | −$3,533.12 |
| long | 22 Jul 2024 67,532.00 | 3 Aug 2024 60,698.00 | 12 | −$3,258.58 |
| long | 23 Jul 2024 65,936.00 | 3 Aug 2024 60,698.00 | 11 | −$2,548.39 |
| long | 24 Jul 2024 65,376.00 | 3 Aug 2024 60,698.00 | 10 | −$2,293.00 |
| long | 25 Jul 2024 65,800.00 | 3 Aug 2024 60,698.00 | 9 | −$2,487.10 |
| long | 26 Jul 2024 67,908.00 | 3 Aug 2024 60,698.00 | 8 | −$3,435.90 |
| long | 27 Jul 2024 67,896.50 | 3 Aug 2024 60,698.00 | 7 | −$3,430.68 |
| long | 28 Jul 2024 68,249.90 | 3 Aug 2024 60,698.00 | 6 | −$3,588.10 |
| long | 29 Jul 2024 66,784.70 | 3 Aug 2024 60,698.00 | 5 | −$2,927.54 |
| long | 30 Jul 2024 66,188.00 | 3 Aug 2024 60,698.00 | 4 | −$2,654.13 |
| long | 31 Jul 2024 64,628.00 | 3 Aug 2024 60,698.00 | 3 | −$1,928.71 |
| long | 1 Aug 2024 65,354.00 | 3 Aug 2024 60,698.00 | 2 | −$2,268.70 |
| long | 2 Aug 2024 61,498.30 | 3 Aug 2024 60,698.00 | 1 | −$433.48 |
| long | 23 Aug 2024 64,037.30 | 27 Aug 2024 59,415.00 | 4 | −$2,177.72 |
| long | 24 Aug 2024 64,157.00 | 27 Aug 2024 59,415.00 | 3 | −$2,229.01 |
| long | 25 Aug 2024 64,220.00 | 27 Aug 2024 59,415.00 | 2 | −$2,255.97 |
| long | 26 Aug 2024 62,834.00 | 27 Aug 2024 59,415.00 | 1 | −$1,648.42 |
| long | 18 Sep 2024 61,760.00 | 2 Oct 2024 60,649.30 | 14 | −$569.45 |
| long | 19 Sep 2024 62,948.00 | 2 Oct 2024 60,649.30 | 13 | −$1,111.88 |
| long | 20 Sep 2024 63,201.10 | 2 Oct 2024 60,649.30 | 12 | −$1,225.06 |
| long | 21 Sep 2024 63,349.00 | 2 Oct 2024 60,649.30 | 11 | −$1,290.93 |
| long | 22 Sep 2024 63,578.80 | 2 Oct 2024 60,649.30 | 10 | −$1,392.96 |
| long | 23 Sep 2024 63,340.00 | 2 Oct 2024 60,649.30 | 9 | −$1,286.67 |
| long | 24 Sep 2024 64,262.70 | 2 Oct 2024 60,649.30 | 8 | −$1,694.75 |
| long | 25 Sep 2024 63,152.00 | 2 Oct 2024 60,649.30 | 7 | −$1,201.52 |
| long | 26 Sep 2024 65,174.00 | 2 Oct 2024 60,649.30 | 6 | −$2,093.04 |
| long | 27 Sep 2024 65,770.00 | 2 Oct 2024 60,649.30 | 5 | −$2,349.67 |
| long | 28 Sep 2024 65,858.00 | 2 Oct 2024 60,649.30 | 4 | −$2,387.41 |
| long | 29 Sep 2024 65,602.00 | 2 Oct 2024 60,649.30 | 3 | −$2,276.90 |
| long | 30 Sep 2024 63,327.60 | 2 Oct 2024 60,649.30 | 2 | −$1,273.07 |
| long | 1 Oct 2024 60,805.80 | 2 Oct 2024 60,649.30 | 1 | −$116.01 |
| long | 5 Oct 2024 62,058.00 | 9 Oct 2024 60,636.00 | 4 | −$693.74 |
| long | 6 Oct 2024 62,819.90 | 9 Oct 2024 60,636.00 | 3 | −$1,030.94 |
| long | 7 Oct 2024 62,224.00 | 9 Oct 2024 60,636.00 | 2 | −$767.55 |
| long | 8 Oct 2024 62,160.50 | 9 Oct 2024 60,636.00 | 1 | −$739.15 |
| long | 12 Oct 2024 63,206.20 | 25 Feb 2025 88,680.40 | 136 | $11,357.40 |
| long | 13 Oct 2024 62,870.00 | 25 Feb 2025 88,680.40 | 135 | $11,566.80 |
| long | 14 Oct 2024 66,084.00 | 25 Feb 2025 88,680.40 | 134 | $9,665.80 |
| long | 15 Oct 2024 67,074.10 | 25 Feb 2025 88,680.40 | 133 | $9,119.92 |
| long | 16 Oct 2024 67,620.00 | 25 Feb 2025 88,680.40 | 132 | $8,827.91 |
| long | 17 Oct 2024 67,421.80 | 25 Feb 2025 88,680.40 | 131 | $8,932.06 |
| long | 18 Oct 2024 68,428.00 | 25 Feb 2025 88,680.40 | 130 | $8,412.01 |
| long | 19 Oct 2024 68,378.00 | 25 Feb 2025 88,680.40 | 129 | $8,437.05 |
| long | 20 Oct 2024 69,032.00 | 25 Feb 2025 88,680.40 | 128 | $8,111.28 |
| long | 21 Oct 2024 67,377.50 | 25 Feb 2025 88,680.40 | 127 | $8,934.74 |
| long | 22 Oct 2024 67,426.00 | 25 Feb 2025 88,680.40 | 126 | $8,910.18 |
| long | 23 Oct 2024 66,668.70 | 25 Feb 2025 88,680.40 | 125 | $9,287.61 |
| long | 24 Oct 2024 68,198.30 | 25 Feb 2025 88,680.40 | 124 | $8,537.66 |
| long | 25 Oct 2024 66,698.30 | 25 Feb 2025 88,680.40 | 123 | $9,264.07 |
| long | 26 Oct 2024 67,092.80 | 25 Feb 2025 88,680.40 | 122 | $9,073.14 |
| long | 27 Oct 2024 68,021.70 | 25 Feb 2025 88,680.40 | 121 | $8,633.04 |
| long | 28 Oct 2024 69,962.20 | 25 Feb 2025 88,680.40 | 120 | $7,740.05 |
| long | 29 Oct 2024 72,736.40 | 25 Feb 2025 88,680.40 | 119 | $6,507.45 |
| long | 30 Oct 2024 72,344.80 | 25 Feb 2025 88,680.40 | 118 | $6,677.79 |
| long | 31 Oct 2024 70,292.00 | 25 Feb 2025 88,680.40 | 117 | $7,571.84 |
| long | 1 Nov 2024 69,496.00 | 25 Feb 2025 88,680.40 | 116 | $7,918.47 |
| long | 2 Nov 2024 69,374.80 | 25 Feb 2025 88,680.40 | 115 | $7,970.68 |
| long | 3 Nov 2024 68,776.00 | 25 Feb 2025 88,680.40 | 114 | $8,226.98 |
| long | 4 Nov 2024 67,850.00 | 25 Feb 2025 88,680.40 | 113 | $8,619.95 |
| long | 5 Nov 2024 69,372.00 | 25 Feb 2025 88,680.40 | 112 | $7,980.88 |
| long | 22 Apr 2025 93,443.00 | 30 Aug 2025 108,816.00 | 130 | $6,019.26 |
| long | 23 Apr 2025 93,691.10 | 30 Aug 2025 108,816.00 | 129 | $5,905.85 |
| long | 24 Apr 2025 93,980.50 | 30 Aug 2025 108,816.00 | 128 | $5,775.05 |
| long | 25 Apr 2025 94,638.70 | 30 Aug 2025 108,816.00 | 127 | $5,482.07 |
| long | 26 Apr 2025 94,628.00 | 30 Aug 2025 108,816.00 | 126 | $5,486.60 |
| long | 27 Apr 2025 93,749.30 | 30 Aug 2025 108,816.00 | 125 | $5,873.83 |
| long | 28 Apr 2025 95,011.20 | 30 Aug 2025 108,816.00 | 124 | $5,322.04 |
| long | 29 Apr 2025 94,256.80 | 30 Aug 2025 108,816.00 | 123 | $5,648.44 |
| long | 30 Apr 2025 94,172.00 | 30 Aug 2025 108,816.00 | 122 | $5,685.03 |
| long | 1 May 2025 96,489.90 | 30 Aug 2025 108,816.00 | 121 | $4,701.51 |
| long | 2 May 2025 96,887.10 | 30 Aug 2025 108,816.00 | 120 | $4,536.75 |
| long | 3 May 2025 95,856.40 | 30 Aug 2025 108,816.00 | 119 | $4,963.38 |
| long | 4 May 2025 94,277.60 | 30 Aug 2025 108,816.00 | 118 | $5,623.76 |
| long | 5 May 2025 94,733.70 | 30 Aug 2025 108,816.00 | 117 | $5,432.60 |
| long | 6 May 2025 96,834.00 | 30 Aug 2025 108,816.00 | 116 | $4,568.80 |
| long | 7 May 2025 97,030.50 | 30 Aug 2025 108,816.00 | 115 | $4,489.13 |
| long | 8 May 2025 103,262.00 | 30 Aug 2025 108,816.00 | 114 | $2,038.00 |
| long | 9 May 2025 102,972.00 | 30 Aug 2025 108,816.00 | 113 | $2,149.21 |
| long | 10 May 2025 104,810.00 | 30 Aug 2025 108,816.00 | 112 | $1,447.40 |
| long | 11 May 2025 104,118.00 | 30 Aug 2025 108,816.00 | 111 | $1,710.21 |
| long | 12 May 2025 102,791.00 | 30 Aug 2025 108,816.00 | 110 | $2,215.50 |
| long | 13 May 2025 104,104.00 | 30 Aug 2025 108,816.00 | 109 | $1,716.40 |
| long | 14 May 2025 103,508.00 | 30 Aug 2025 108,816.00 | 108 | $1,942.26 |
| long | 15 May 2025 103,764.00 | 30 Aug 2025 108,816.00 | 107 | $1,845.34 |
| long | 16 May 2025 103,464.00 | 30 Aug 2025 108,816.00 | 106 | $1,958.54 |
| long | 2 Sep 2025 111,240.00 | 25 Sep 2025 108,994.00 | 23 | −$889.60 |
| long | 3 Sep 2025 111,706.00 | 25 Sep 2025 108,994.00 | 22 | −$1,057.30 |
| long | 4 Sep 2025 110,731.00 | 25 Sep 2025 108,994.00 | 21 | −$704.38 |
| long | 5 Sep 2025 110,660.00 | 25 Sep 2025 108,994.00 | 20 | −$678.47 |
| long | 6 Sep 2025 110,188.00 | 25 Sep 2025 108,994.00 | 19 | −$505.16 |
| long | 7 Sep 2025 111,137.00 | 25 Sep 2025 108,994.00 | 18 | −$852.70 |
| long | 8 Sep 2025 112,065.00 | 25 Sep 2025 108,994.00 | 17 | −$1,188.22 |
| long | 9 Sep 2025 111,546.00 | 25 Sep 2025 108,994.00 | 16 | −$1,000.90 |
| long | 10 Sep 2025 113,960.00 | 25 Sep 2025 108,994.00 | 15 | −$1,863.34 |
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 |
|---|---|---|---|---|---|
| VIDYA Trend Strategy this page | — | v5 strategy | −7.1% | 194 | 30.3% |
| Follow the Crypto Shorts by xtradernet | sma | v4 strategy | No trades on this market | ||
| buy down and sell high trend 200 sma and ma cross by willi130503 | sma | v4 strategy | No trades on this market | ||
| Mayer Multiple Strategy by xtradernet | sma | v4 strategy | No trades on this market | ||
| Moving Average Cross Strategy early Closing by Geduldtrader | sma | v4 strategy | +73.8% | 20 | 151.5% |
| MFI Simple Strategy by OztheWoz | sma | v5 strategy | −0.2% | 28 | 3.2% |
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.
- 2 strategy calls use the when = argument (line 24, 25). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Same 194 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 24: when = VIDYA>VIDYA[1] → if block
- Line 25: when = VIDYA<VIDYA[1] → if block
⋯if (InDateRange)- strategy.entry("Long", strategy.long, when = VIDYA>VIDYA[1])+ if VIDYA>VIDYA[1]+ strategy.entry("Long", strategy.long)- strategy.close("Long", when = VIDYA<VIDYA[1])+ if VIDYA<VIDYA[1]+ strategy.close("Long")if (not InDateRange)⋯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: 194 before, 190 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.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-// @version=5+// @version=6// Author = TradeAutomation⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 18 ms | Yes 1,000 bars in 28 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“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/// @version=5// Author = TradeAutomationstrategy(title="VIDYA Trend Strategy", shorttitle="VIDYA Trend Strategy", process_orders_on_close=true, overlay=true, pyramiding=25, commission_type=strategy.commission.percent, commission_value=.075, slippage = 1, initial_capital = 1000000, default_qty_type=strategy.percent_of_equity, default_qty_value=4)// Backtest Date Range Inputs // StartTime = input.time(defval=timestamp('01 Jan 2000 08:00'), group="Date Range", title='Start Time')EndTime = input.time(defval=timestamp('01 Jan 2099 00:00'), group="Date Range", title='End Time')InDateRange = time>=StartTime and time<=EndTime// Strategy Inputs //len = input.int(title="VIDYA Length", defval=50, step=5,group="Trend Settings")src = input.source(title="VIDYA Price Source",defval=ohlc4, group="Trend Settings")// VIDYA Calculations //valpha=2/(len+1)vud1=src>src[1] ? src-src[1] : 0vdd1=src<src[1] ? src[1]-src : 0vUD=math.sum(vud1,9)vDD=math.sum(vdd1,9)vCMO=nz((vUD-vDD)/(vUD+vDD))var VIDYA = 0.0VIDYA := na(VIDYA[1]) ? ta.sma(src, len) : nz(valpha*math.abs(vCMO)*src)+(1-valpha*math.abs(vCMO))*nz(VIDYA[1])plot(VIDYA, title="VIDYA",color=(VIDYA > VIDYA[1]) ? color.green : (VIDYA<VIDYA[1]) ? color.red : (VIDYA==VIDYA[1]) ? color.gray : color.black, linewidth=2)// Entry & Exit Signals //if (InDateRange) strategy.entry("Long", strategy.long, when = VIDYA>VIDYA[1]) strategy.close("Long", when = VIDYA<VIDYA[1])if (not InDateRange) strategy.close_all()