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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Bar Change | |||
| Starting Wave Direction | 1 | int | bar_change_wave_count |
| Sine Wave # | 28 | int | entry short entry long line 39 line 46 line 48 |
| Resolution | D | timeframe | bar_color_time_adj |
| Trade | true | bool | entry short entry long line 46 line 48 |
| Volume | |||
| Starting Wave Direction | 1 | int | volume_wave_count |
| Lookback Length | 7 | int | avg_volume |
| Sine Wave # | 28 | int | entry short-volume entry long-volume line 41 line 50 line 52 |
| Resolution | D | timeframe | volume_state_time_adj |
| Trade | false | bool | entry short-volume entry long-volume line 50 line 52 |
| Coin Flip | |||
| Starting Wave Direction | 1 | int | coin_flip_wave_count |
| Sine Wave # | 28 | int | entry short-coinflip entry long-coinflip line 43 line 54 line 56 |
| Seed # | 1 | int | coin_flip |
| Trade | false | bool | entry 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open short short | (bar_change_wave_count==bar_change_sine_wave_number and bar_change_trade==true) | On | 47 |
| Open long long | (bar_change_wave_count==bar_change_sine_wave_number*-1 and bar_change_trade==true) | On | 49 |
| Open short-volume short | (volume_wave_count==volume_sine_wave_number and volume_trade==true) | On | 51 |
| Open long-volume long | (volume_wave_count==volume_sine_wave_number*-1 and volume_trade==true) | On | 53 |
| Open short-coinflip short | (coin_flip_wave_count==coin_flip_sine_wave_number and coin_flip_trade==true) | On | 55 |
| Open long-coinflip long | (coin_flip_wave_count==coin_flip_sine_wave_number*-1 and coin_flip_trade==true) | On | 57 |
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 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −3,660.0% | +102.5% | 8 | 63% | 0.40 | 729.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −1,993.9% | +5.5% | 1 | 0% | 0.00 | 2,416.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −586.4% | +9.8% | 8 | 25% | 0.19 | 553.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −87.8% | +8.4% | 1 | 0% | 0.00 | 119.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +19.7% | +16.7% | 8 | 88% | 3.85 | 7.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −2.4% | +21.5% | 1 | 0% | 0.00 | 4.3% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −70.3% | +148.3% | 8 | 38% | 0.39 | 122.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 2 | 100% | $6,151.71 |
| Sideways market | 5 | 40% | −$52,605.60 |
| Falling market | 1 | 100% | $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.
All 8 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 22 Mar 2024 65,501.30 | 29 Jun 2024 60,427.80 | 99 | $5,073.44 |
| long | 29 Jun 2024 60,427.80 | 18 Oct 2024 67,421.80 | 111 | $6,993.94 |
| short | 18 Oct 2024 67,421.80 | 1 Feb 2025 102,430.00 | 106 | −$35,007.80 |
| long | 1 Feb 2025 102,430.00 | 15 May 2025 103,508.00 | 103 | $1,078.27 |
| short | 15 May 2025 103,508.00 | 1 Sep 2025 108,246.00 | 109 | −$4,738.53 |
| long | 1 Sep 2025 108,246.00 | 26 Dec 2025 87,225.30 | 116 | −$21,021.10 |
| short | 26 Dec 2025 87,225.30 | 28 Apr 2026 77,371.30 | 123 | $9,853.95 |
| long | 28 Apr 2026 77,371.30 | 26 Aug 2026 78,539.10 | 120 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Sine Wave Theory this page | — | v5 strategy | −3,660.0% | 8 | 729.7% |
| 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.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing 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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 37 ms | With a workaround 1,000 bars in 70 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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)