Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (4)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,006,340$2,025,273Equity from $1,000,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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.

SettingDefaultType and rangeFeeds
Date Range
Start Timetimestamp('01 Jan 2000 08:00')timeInDateRange
End Timetimestamp('01 Jan 2099 00:00')timeInDateRange
Trend Settings
VIDYA Length50int · step 5valpha VIDYA
VIDYA Price Sourceohlc4sourcevud1 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.

ohlc4ohlc4price datalenVIDYA Lengthsetting · 50timetimeprice dataStartTimeStart Timesetting · timestamp('01 Jan 2…EndTimeEnd Timesetting · timestamp('01 Jan 2…VIDYASMA→ VIDYAvalphavalphavaluevud1, vdd1vud1 · vdd12 valuesvUDvUDvaluevDDvDDvaluevCMOvCMOvalueInDateRangeInDateRangeconditionentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeclose_all:close_all strategy.close_allplot:21VIDYAplot

Order rules

OrderFires whenBy defaultLine
Open Long longVIDYA>VIDYA[1]On24
Close LongVIDYA<VIDYA[1]On25
Close (not InDateRange)On27

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.

14/14trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−7.1%+102.5%19426%0.8230.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+2.1%+5.5%22023%1.189.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−20.1%+9.8%18318%0.5444.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+24.4%+8.4%12153%7.483.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−57.3%+16.7%22418%0.1559.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+15.8%+21.5%20434%1.9711.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−9.8%+148.3%20216%0.7435.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+7.4%+17.1%20223%1.6210.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 barsTradesWonP&L
Rising market617%−$188,386.00
Sideways market13335%$117,769.00
Falling market0—$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.

0%32%
The first 150 of 194 trades
SideEntryExitBarsP&L
long16 Mar 2024 65,300.601 May 2024 58,365.0046−$4,302.05
long17 Mar 2024 68,393.501 May 2024 58,365.0045−$5,927.38
long18 Mar 2024 67,610.001 May 2024 58,365.0044−$5,526.33
long19 Mar 2024 61,937.401 May 2024 58,365.0043−$2,341.69
long20 Mar 2024 67,840.501 May 2024 58,365.0042−$5,666.86
long21 Mar 2024 65,501.301 May 2024 58,365.0041−$4,402.24
long22 Mar 2024 63,796.701 May 2024 58,365.0040−$3,431.78
long23 Mar 2024 63,990.001 May 2024 58,365.0039−$3,544.11
long24 Mar 2024 67,210.001 May 2024 58,365.0038−$5,359.54
long25 Mar 2024 69,880.001 May 2024 58,365.0037−$6,792.38
long26 Mar 2024 69,988.001 May 2024 58,365.0036−$6,849.19
long27 Mar 2024 69,470.001 May 2024 58,365.0035−$6,572.67
long28 Mar 2024 70,780.601 May 2024 58,365.0034−$7,273.06
long29 Mar 2024 69,850.601 May 2024 58,365.0033−$6,773.35
long30 Mar 2024 69,582.201 May 2024 58,365.0032−$6,626.97
long31 Mar 2024 71,280.001 May 2024 58,365.0031−$7,551.71
long1 Apr 2024 69,649.801 May 2024 58,365.0030−$6,657.52
long2 Apr 2024 65,464.001 May 2024 58,365.0029−$4,289.51
long3 Apr 2024 65,963.301 May 2024 58,365.0028−$4,577.66
long4 Apr 2024 68,487.801 May 2024 58,365.0027−$6,027.57
long5 Apr 2024 67,820.601 May 2024 58,365.0026−$5,644.18
long6 Apr 2024 68,896.001 May 2024 58,365.0025−$6,264.97
long7 Apr 2024 69,360.401 May 2024 58,365.0024−$6,533.88
long8 Apr 2024 71,620.001 May 2024 58,365.0023−$7,848.23
long9 Apr 2024 69,146.001 May 2024 58,365.0022−$6,399.36
long3 May 2024 62,882.0024 Jun 2024 60,293.3052−$1,460.19
long4 May 2024 63,892.1024 Jun 2024 60,293.3051−$1,980.12
long5 May 2024 64,012.0024 Jun 2024 60,293.3050−$2,040.92
long6 May 2024 63,165.2024 Jun 2024 60,293.3049−$1,605.86
long7 May 2024 62,312.1024 Jun 2024 60,293.3048−$1,156.51
long8 May 2024 61,193.0024 Jun 2024 60,293.3047−$550.86
long9 May 2024 63,074.0024 Jun 2024 60,293.3046−$1,560.85
long10 May 2024 60,800.0024 Jun 2024 60,293.3045−$333.33
long11 May 2024 60,826.0024 Jun 2024 60,293.3044−$347.73
long12 May 2024 61,484.0024 Jun 2024 60,293.3043−$709.98
long13 May 2024 62,940.1024 Jun 2024 60,293.3042−$1,495.67
long14 May 2024 61,577.5024 Jun 2024 60,293.3041−$760.38
long15 May 2024 66,206.5024 Jun 2024 60,293.3040−$3,199.11
long16 May 2024 65,235.2024 Jun 2024 60,293.3039−$2,700.09
long17 May 2024 67,024.0024 Jun 2024 60,293.3038−$3,617.73
long18 May 2024 66,915.2024 Jun 2024 60,293.3037−$3,562.14
long19 May 2024 66,274.0024 Jun 2024 60,293.3036−$3,232.50
long20 May 2024 71,446.6024 Jun 2024 60,293.3035−$5,853.69
long21 May 2024 70,148.4024 Jun 2024 60,293.3034−$5,201.63
long22 May 2024 69,166.6024 Jun 2024 60,293.3033−$4,702.27
long23 May 2024 67,969.7024 Jun 2024 60,293.3032−$4,086.89
long24 May 2024 68,550.0024 Jun 2024 60,293.3031−$4,386.97
long25 May 2024 69,290.6024 Jun 2024 60,293.3030−$4,771.05
long26 May 2024 68,507.7024 Jun 2024 60,293.3029−$4,362.73
long27 May 2024 69,436.4024 Jun 2024 60,293.3028−$4,849.35
long15 Jul 2024 64,724.203 Aug 2024 60,698.0019−$2,005.74
long16 Jul 2024 65,044.003 Aug 2024 60,698.0018−$2,151.29
long17 Jul 2024 64,088.003 Aug 2024 60,698.0017−$1,710.88
long18 Jul 2024 63,987.903 Aug 2024 60,698.0016−$1,663.94
long19 Jul 2024 66,660.003 Aug 2024 60,698.0015−$2,878.48
long20 Jul 2024 67,140.003 Aug 2024 60,698.0014−$3,088.96
long21 Jul 2024 68,165.403 Aug 2024 60,698.0013−$3,533.12
long22 Jul 2024 67,532.003 Aug 2024 60,698.0012−$3,258.58
long23 Jul 2024 65,936.003 Aug 2024 60,698.0011−$2,548.39
long24 Jul 2024 65,376.003 Aug 2024 60,698.0010−$2,293.00
long25 Jul 2024 65,800.003 Aug 2024 60,698.009−$2,487.10
long26 Jul 2024 67,908.003 Aug 2024 60,698.008−$3,435.90
long27 Jul 2024 67,896.503 Aug 2024 60,698.007−$3,430.68
long28 Jul 2024 68,249.903 Aug 2024 60,698.006−$3,588.10
long29 Jul 2024 66,784.703 Aug 2024 60,698.005−$2,927.54
long30 Jul 2024 66,188.003 Aug 2024 60,698.004−$2,654.13
long31 Jul 2024 64,628.003 Aug 2024 60,698.003−$1,928.71
long1 Aug 2024 65,354.003 Aug 2024 60,698.002−$2,268.70
long2 Aug 2024 61,498.303 Aug 2024 60,698.001−$433.48
long23 Aug 2024 64,037.3027 Aug 2024 59,415.004−$2,177.72
long24 Aug 2024 64,157.0027 Aug 2024 59,415.003−$2,229.01
long25 Aug 2024 64,220.0027 Aug 2024 59,415.002−$2,255.97
long26 Aug 2024 62,834.0027 Aug 2024 59,415.001−$1,648.42
long18 Sep 2024 61,760.002 Oct 2024 60,649.3014−$569.45
long19 Sep 2024 62,948.002 Oct 2024 60,649.3013−$1,111.88
long20 Sep 2024 63,201.102 Oct 2024 60,649.3012−$1,225.06
long21 Sep 2024 63,349.002 Oct 2024 60,649.3011−$1,290.93
long22 Sep 2024 63,578.802 Oct 2024 60,649.3010−$1,392.96
long23 Sep 2024 63,340.002 Oct 2024 60,649.309−$1,286.67
long24 Sep 2024 64,262.702 Oct 2024 60,649.308−$1,694.75
long25 Sep 2024 63,152.002 Oct 2024 60,649.307−$1,201.52
long26 Sep 2024 65,174.002 Oct 2024 60,649.306−$2,093.04
long27 Sep 2024 65,770.002 Oct 2024 60,649.305−$2,349.67
long28 Sep 2024 65,858.002 Oct 2024 60,649.304−$2,387.41
long29 Sep 2024 65,602.002 Oct 2024 60,649.303−$2,276.90
long30 Sep 2024 63,327.602 Oct 2024 60,649.302−$1,273.07
long1 Oct 2024 60,805.802 Oct 2024 60,649.301−$116.01
long5 Oct 2024 62,058.009 Oct 2024 60,636.004−$693.74
long6 Oct 2024 62,819.909 Oct 2024 60,636.003−$1,030.94
long7 Oct 2024 62,224.009 Oct 2024 60,636.002−$767.55
long8 Oct 2024 62,160.509 Oct 2024 60,636.001−$739.15
long12 Oct 2024 63,206.2025 Feb 2025 88,680.40136$11,357.40
long13 Oct 2024 62,870.0025 Feb 2025 88,680.40135$11,566.80
long14 Oct 2024 66,084.0025 Feb 2025 88,680.40134$9,665.80
long15 Oct 2024 67,074.1025 Feb 2025 88,680.40133$9,119.92
long16 Oct 2024 67,620.0025 Feb 2025 88,680.40132$8,827.91
long17 Oct 2024 67,421.8025 Feb 2025 88,680.40131$8,932.06
long18 Oct 2024 68,428.0025 Feb 2025 88,680.40130$8,412.01
long19 Oct 2024 68,378.0025 Feb 2025 88,680.40129$8,437.05
long20 Oct 2024 69,032.0025 Feb 2025 88,680.40128$8,111.28
long21 Oct 2024 67,377.5025 Feb 2025 88,680.40127$8,934.74
long22 Oct 2024 67,426.0025 Feb 2025 88,680.40126$8,910.18
long23 Oct 2024 66,668.7025 Feb 2025 88,680.40125$9,287.61
long24 Oct 2024 68,198.3025 Feb 2025 88,680.40124$8,537.66
long25 Oct 2024 66,698.3025 Feb 2025 88,680.40123$9,264.07
long26 Oct 2024 67,092.8025 Feb 2025 88,680.40122$9,073.14
long27 Oct 2024 68,021.7025 Feb 2025 88,680.40121$8,633.04
long28 Oct 2024 69,962.2025 Feb 2025 88,680.40120$7,740.05
long29 Oct 2024 72,736.4025 Feb 2025 88,680.40119$6,507.45
long30 Oct 2024 72,344.8025 Feb 2025 88,680.40118$6,677.79
long31 Oct 2024 70,292.0025 Feb 2025 88,680.40117$7,571.84
long1 Nov 2024 69,496.0025 Feb 2025 88,680.40116$7,918.47
long2 Nov 2024 69,374.8025 Feb 2025 88,680.40115$7,970.68
long3 Nov 2024 68,776.0025 Feb 2025 88,680.40114$8,226.98
long4 Nov 2024 67,850.0025 Feb 2025 88,680.40113$8,619.95
long5 Nov 2024 69,372.0025 Feb 2025 88,680.40112$7,980.88
long22 Apr 2025 93,443.0030 Aug 2025 108,816.00130$6,019.26
long23 Apr 2025 93,691.1030 Aug 2025 108,816.00129$5,905.85
long24 Apr 2025 93,980.5030 Aug 2025 108,816.00128$5,775.05
long25 Apr 2025 94,638.7030 Aug 2025 108,816.00127$5,482.07
long26 Apr 2025 94,628.0030 Aug 2025 108,816.00126$5,486.60
long27 Apr 2025 93,749.3030 Aug 2025 108,816.00125$5,873.83
long28 Apr 2025 95,011.2030 Aug 2025 108,816.00124$5,322.04
long29 Apr 2025 94,256.8030 Aug 2025 108,816.00123$5,648.44
long30 Apr 2025 94,172.0030 Aug 2025 108,816.00122$5,685.03
long1 May 2025 96,489.9030 Aug 2025 108,816.00121$4,701.51
long2 May 2025 96,887.1030 Aug 2025 108,816.00120$4,536.75
long3 May 2025 95,856.4030 Aug 2025 108,816.00119$4,963.38
long4 May 2025 94,277.6030 Aug 2025 108,816.00118$5,623.76
long5 May 2025 94,733.7030 Aug 2025 108,816.00117$5,432.60
long6 May 2025 96,834.0030 Aug 2025 108,816.00116$4,568.80
long7 May 2025 97,030.5030 Aug 2025 108,816.00115$4,489.13
long8 May 2025 103,262.0030 Aug 2025 108,816.00114$2,038.00
long9 May 2025 102,972.0030 Aug 2025 108,816.00113$2,149.21
long10 May 2025 104,810.0030 Aug 2025 108,816.00112$1,447.40
long11 May 2025 104,118.0030 Aug 2025 108,816.00111$1,710.21
long12 May 2025 102,791.0030 Aug 2025 108,816.00110$2,215.50
long13 May 2025 104,104.0030 Aug 2025 108,816.00109$1,716.40
long14 May 2025 103,508.0030 Aug 2025 108,816.00108$1,942.26
long15 May 2025 103,764.0030 Aug 2025 108,816.00107$1,845.34
long16 May 2025 103,464.0030 Aug 2025 108,816.00106$1,958.54
long2 Sep 2025 111,240.0025 Sep 2025 108,994.0023−$889.60
long3 Sep 2025 111,706.0025 Sep 2025 108,994.0022−$1,057.30
long4 Sep 2025 110,731.0025 Sep 2025 108,994.0021−$704.38
long5 Sep 2025 110,660.0025 Sep 2025 108,994.0020−$678.47
long6 Sep 2025 110,188.0025 Sep 2025 108,994.0019−$505.16
long7 Sep 2025 111,137.0025 Sep 2025 108,994.0018−$852.70
long8 Sep 2025 112,065.0025 Sep 2025 108,994.0017−$1,188.22
long9 Sep 2025 111,546.0025 Sep 2025 108,994.0016−$1,000.90
long10 Sep 2025 113,960.0025 Sep 2025 108,994.0015−$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.

ScriptSharesTypeNetTradesMax drawdown
VIDYA Trend Strategy this page—v5 strategy−7.1%19430.3%
Follow the Crypto Shorts by xtradernetsmav4 strategyNo trades on this market
buy down and sell high trend 200 sma and ma cross by willi130503smav4 strategyNo trades on this market
Mayer Multiple Strategy by xtradernetsmav4 strategyNo trades on this market
Moving Average Cross Strategy early Closing by Geduldtradersmav4 strategy+73.8%20151.5%
MFI Simple Strategy by OztheWozsmav5 strategy−0.2%283.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.

Clean v5

VerifiedDownload the v5 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 18 msYes 1,000 bars in 28 msNot measured
PineTSNot testedNot testedNot 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()