Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Sine Wave Theory

A Pine Script v5 strategy built on SMA (volume, 7). It has 6 order rules, 6 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 13 settings; defaults include Starting Wave Direction 1, Sine Wave # 28 and Resolution D.

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 Sine Wave Theory repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did Sine Wave Theory do on BTCUSDT 1D with default settings?
−3,660.00%
From 26 Jan 2024 to 21 Oct 2026, over 8 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Sine Wave Theory 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: 8 before, 7 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 Sine Wave Theory use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Sine Wave Theory run in Zeal Terminal?
Yes
It compiles in 37 ms and runs 1,000 bars in 70 ms, in the browser.

BTCUSDT · 1D · default settings

  • Center
  • Bar Change
  • Volume Average Change
  • Coin Flip Change
  • 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 (13)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctCenter$-41,758$2,025Equity from $1,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. Zeal Terminal's engine currently reads an order side written as direction = strategy.short, direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 47, 49, 51, 53, 55, 57) so the engine trades the way the script says.
Net profit
−3,660.00%
−$36,600.00
Buy and hold
+102.5%
same period
Closed trades
8
5 won · 3 lost
Profitable
62.5%
of closed trades
Profit factor
0.40
gross profit ÷ gross loss
Max drawdown
729.67%
−$70,388.30

One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A short 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

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Bar Change
Starting Wave Direction1intbar_change_wave_count
Sine Wave #28intentry short entry long line 39 line 46 line 48
ResolutionDtimeframebar_color_time_adj
Tradetrueboolentry short entry long line 46 line 48
Volume
Starting Wave Direction1intvolume_wave_count
Lookback Length7intavg_volume
Sine Wave #28intentry short-volume entry long-volume line 41 line 50 line 52
ResolutionDtimeframevolume_state_time_adj
Tradefalseboolentry short-volume entry long-volume line 50 line 52
Coin Flip
Starting Wave Direction1intcoin_flip_wave_count
Sine Wave #28intentry short-coinflip entry long-coinflip line 43 line 54 line 56
Seed #1intcoin_flip
Tradefalseboolentry short-coinflip entry long-coinflip line 54 line 56

What it calculates

  • SMAvolume, Lookback Length (7)avg_volume · line 18

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.

volumevolumeprice dataavg_volume_lengthLookback Lengthsetting · 7bar_change_sine_wave_resResolutionsetting · Dvolume_sine_wave_resResolutionsetting · Dbar_change_wave_directionStarting Wave Directionsetting · 1volume_wave_directionStarting Wave Directionsetting · 1coin_flip_wave_directionStarting Wave Directionsetting · 1openopenprice dataclosecloseprice datacoin_flip_seedSeed #setting · 1bar_change_sine_wave_numberSine Wave #setting · 28volume_sine_wave_numberSine Wave #setting · 28coin_flip_sine_wave_numberSine Wave #setting · 28avg_volumeSMA→ avg_volumebar_color_time_adjbar_color_time_adjvaluevolume_state_time_adjvolume_state_time_adjvaluebar_change_wave_countbar_change_wave_countvaluevolume_wave_countvolume_wave_countvaluecoin_flip_wave_countcoin_flip_wave_countvaluebar_color, volume_state, coin_flipColourbar_color · volume_state +1entry:shortOpen shortstrategy.entryentry:longOpen longstrategy.entryentry:short-volumeOpen short-volumestrategy.entryentry:long-volumeOpen long-volumestrategy.entryentry:short-coinflipOpen short-coinflipstrategy.entryentry:long-coinflipOpen long-coinflipstrategy.entryhline:58Centerhlineplot:59Bar Changeplotplot:60Volume Average Changeplotplot:61Coin Flip Changeplot

Order rules

OrderFires whenBy defaultLine
Open short short(bar_change_wave_count==bar_change_sine_wave_number and bar_change_trade==true)On47
Open long long(bar_change_wave_count==bar_change_sine_wave_number*-1 and bar_change_trade==true)On49
Open short-volume short(volume_wave_count==volume_sine_wave_number and volume_trade==true)On51
Open long-volume long(volume_wave_count==volume_sine_wave_number*-1 and volume_trade==true)On53
Open short-coinflip short(coin_flip_wave_count==coin_flip_sine_wave_number and coin_flip_trade==true)On55
Open long-coinflip long(coin_flip_wave_count==coin_flip_sine_wave_number*-1 and coin_flip_trade==true)On57

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.

2/2trades 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 data2 request.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

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−3,660.0%+102.5%863%0.40729.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−1,993.9%+5.5%10%0.002,416.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−586.4%+9.8%825%0.19553.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−87.8%+8.4%10%0.00119.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+19.7%+16.7%888%3.857.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−2.4%+21.5%10%0.004.3%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−70.3%+148.3%838%0.39122.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—24.1%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 market2100%$6,151.71
Sideways market540%−$52,605.60
Falling market1100%$9,853.95

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

3,844.0%

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, 259.6% to 3,844.0%; the tick is what actually happened, 456.8%. Order luck alone moves it this much.

0%4,421%
All 8 trades
SideEntryExitBarsP&L
short22 Mar 2024 65,501.3029 Jun 2024 60,427.8099$5,073.44
long29 Jun 2024 60,427.8018 Oct 2024 67,421.80111$6,993.94
short18 Oct 2024 67,421.801 Feb 2025 102,430.00106−$35,007.80
long1 Feb 2025 102,430.0015 May 2025 103,508.00103$1,078.27
short15 May 2025 103,508.001 Sep 2025 108,246.00109−$4,738.53
long1 Sep 2025 108,246.0026 Dec 2025 87,225.30116−$21,021.10
short26 Dec 2025 87,225.3028 Apr 2026 77,371.30123$9,853.95
long28 Apr 2026 77,371.3026 Aug 2026 78,539.10120$1,167.81

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
Sine Wave Theory this page—v5 strategy−3,660.0%8729.7%
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.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

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: 8 before, 7 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.

⋯// © Gentleman-Goat-//@version=5+//@version=6strategy("Sine Wave Theory",overlay=false, precision = 2, initial_capital = 1000,shorttitle = "SINE_W_T")⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 37 msWith a workaround 1,000 bars in 70 msNot measured
PineTSNot testedNot testedNot measured

Zeal Terminal's engine currently reads an order side written as direction = strategy.short, direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 47, 49, 51, 53, 55, 57) so the engine trades the way the script says.

“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/// © Gentleman-Goat//@version=5strategy("Sine Wave Theory",overlay=false, precision = 2, initial_capital = 1000,shorttitle = "SINE_W_T")var bar_change_wave_direction = input.int(defval=1,title="Starting Wave Direction",group="Bar Change")bar_change_sine_wave_number = input.int(defval=28,title="Sine Wave #",group="Bar Change")bar_change_sine_wave_res = input.timeframe(defval="D",title="Resolution",group="Bar Change")bar_change_trade = input.bool(defval=true,title="Trade",group="Bar Change")var volume_wave_direction = input.int(defval=1,title="Starting Wave Direction",group="Volume")avg_volume_length = input.int(7,title="Lookback Length",group="Volume")volume_sine_wave_number = input.int(defval=28,title="Sine Wave #",group="Volume")volume_sine_wave_res = input.timeframe(defval="D",title="Resolution",group="Volume")volume_trade = input.bool(defval=false,title="Trade",group="Volume")var coin_flip_wave_direction = input.int(defval=1,title="Starting Wave Direction",group="Coin Flip")coin_flip_sine_wave_number = input.int(defval=28,title="Sine Wave #",group="Coin Flip")coin_flip_seed = input.int(defval=1,title="Seed #",group="Coin Flip")coin_flip_trade = input.bool(defval=false,title="Trade",group="Coin Flip")avg_volume = ta.sma(volume,avg_volume_length)//Green or Red Candlebar_color = close>open ? color.green : color.redbar_color_time_adj = request.security(syminfo.tickerid, bar_change_sine_wave_res, bar_color)//Above or Below Averagevolume_state = (volume>avg_volume) ? color.blue : color.purplevolume_state_time_adj = request.security(syminfo.tickerid, volume_sine_wave_res, volume_state) //Coinflipcoin_flip = math.random(0,100,coin_flip_seed)>=50 ? color.teal : color.yellowvar bar_change_wave_count = 0var volume_wave_count = 0var coin_flip_wave_count = 0//Wave Countersif(volume_state_time_adj[1] != volume_state_time_adj)    volume_wave_count := volume_wave_count + volume_wave_directionif(bar_color_time_adj[1] != bar_color_time_adj)    bar_change_wave_count := bar_change_wave_count + bar_change_wave_directionif(coin_flip[1] != coin_flip)    coin_flip_wave_count := coin_flip_wave_count + coin_flip_wave_direction//Direction changersif(math.abs(bar_change_wave_count) == bar_change_sine_wave_number and bar_color_time_adj[1] != bar_color_time_adj)    bar_change_wave_direction := bar_change_wave_direction * -1if(math.abs(volume_wave_count) == volume_sine_wave_number and volume_state_time_adj[1] != volume_state_time_adj)    volume_wave_direction := volume_wave_direction * -1if(math.abs(coin_flip_wave_count) == coin_flip_sine_wave_number and coin_flip[1] != coin_flip)    coin_flip_wave_direction := coin_flip_wave_direction * -1//Entry positionsif(bar_change_wave_count==bar_change_sine_wave_number and bar_change_trade==true)    strategy.entry(id="short",direction=strategy.short)if(bar_change_wave_count==bar_change_sine_wave_number*-1 and bar_change_trade==true)    strategy.entry(id="long",direction=strategy.long)if(volume_wave_count==volume_sine_wave_number and volume_trade==true)    strategy.entry(id="short-volume",direction=strategy.short)if(volume_wave_count==volume_sine_wave_number*-1 and volume_trade==true)    strategy.entry(id="long-volume",direction=strategy.long)if(coin_flip_wave_count==coin_flip_sine_wave_number and coin_flip_trade==true)    strategy.entry(id="short-coinflip",direction=strategy.short)if(coin_flip_wave_count==coin_flip_sine_wave_number*-1 and coin_flip_trade==true)    strategy.entry(id="long-coinflip",direction=strategy.long)hline(0, title='Center', color=color.white, linestyle=hline.style_dashed, linewidth=1)plot(bar_change_wave_count,title="Bar Change", color=bar_color, linewidth=2)plot(volume_wave_count,title="Volume Average Change", color=volume_state, linewidth=2)plot(coin_flip_wave_count,title="Coin Flip Change", color=coin_flip, linewidth=2)