Pine Script v4 · Strategy
Cross impro test by Canundo Crossover Crossunder Tick values
A Pine Script v4 strategy built on SMA (close, 2), Crossover and Crossunder. It has 2 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 is one contract and pays no commission. 4 settings; defaults include Backtest Trade Candle Count 3000, Change mintick for Cross Check (0 = Standard Tick/Pip, Chose pips like 0.5, 10, 100, 0.002) 0 and Add spread between values to be crossed. 0.
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 Cross impro test by Canundo Crossover Crossunder Tick values repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 112 of 112 trades.
- How did Cross impro test by Canundo Crossover Crossunder Tick values do on BTCUSDT 1D with default settings?
- +28.92%
- From 26 Jan 2024 to 21 Oct 2026, over 383 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Cross impro test by Canundo Crossover Crossunder Tick values be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does Cross impro test by Canundo Crossover Crossunder Tick values use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Cross impro test by Canundo Crossover Crossunder Tick values run in Zeal Terminal?
- Yes
- It compiles in 12 ms and runs 1,000 bars in 39 ms, in the browser.
BTCUSDT · 1D · default settings
- SMA1
- SMA1 Improved
- SMA1 Improved + Spread
- SMA2
- SMA2 Improved
- SMA2 Improved + Spread
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +28.92%
- $28,918.30
- Buy and hold
- +102.5%
- same period
- Closed trades
- 383
- 158 won · 225 lost
- Profitable
- 41.3%
- of closed trades
- Profit factor
- 1.08
- gross profit ÷ gross loss
- Max drawdown
- 36.18%
- −$56,358.60
One run with the author's default settings, $100,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.
-
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.
-
Note
Uses transp =, which v5 removed line 36
transp = on line 36. v5 folds the transparency into the colour with color.new(c, transp).
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 floor → math.floor, ceil → math.ceil, sma → ta.sma, crossover → ta.crossover, crossunder → ta.crossunder.
Same 383 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 6: input(type = input.bool) → input.bool()
- Line 7: input(type = input.integer) → input.int()
- Line 8: input(type = input.float) → input.float()
- Line 10: input(type = input.float) → input.float()
- Line 19: floor → math.floor
8 more edits
- Line 19: ceil → math.ceil
- Line 19: floor → math.floor
- Line 19: ceil → math.ceil
- Line 21: sma → ta.sma
- Line 22: sma → ta.sma
- Line 23: crossover → ta.crossover
- Line 26: crossunder → ta.crossunder
- Line 36: transp = 100 removed: the call sets no colour to fold it into, so its default colour loses the transparency
⋯// © Canundo-//@version=4+//@version=5strategy("Cross impro test by Canundo", overlay=true)//Run on 1 min chart for better testing cases where x and y of crossover have the same value.-EnableStrictCross = input(title="Enable Strict Cross (rounds SMA to pips/ticks), otherwise standard", type=input.bool, defval=true) //Disable to see differences+EnableStrictCross = input.bool(title="Enable Strict Cross (rounds SMA to pips/ticks), otherwise standard", defval=true) //Disable to see differences-BacktestTradeCandleCount = input(title="Backtest Trade Candle Count", type=input.integer, defval=3000) //Avoid error for too many trades+BacktestTradeCandleCount = input.int(title="Backtest Trade Candle Count", defval=3000) //Avoid error for too many trades-MinTick = input(title="Change mintick for Cross Check (0 = Standard Tick/Pip, Chose pips like 0.5, 10, 100, 0.002)",- type=input.float, defval=0) //Precision of round to pip function+MinTick = input.float(title="Change mintick for Cross Check (0 = Standard Tick/Pip, Chose pips like 0.5, 10, 100, 0.002)", defval=0) //Precision of round to pip function-SpreadBetween = input(title="Add spread between values to be crossed.",- type=input.float, defval=0)+SpreadBetween = input.float(title="Add spread between values to be crossed.", defval=0) ⋯mult = 1 / (MinTick == 0 ? syminfo.mintick : MinTick)-f_roundToPip(x)=> (x-floor(x*mult)/mult) < (ceil(x*mult)/mult-x) ? floor(x*mult)/mult : ceil(x*mult)/mult+f_roundToPip(x)=> (x-math.floor(x*mult)/mult) < (math.ceil(x*mult)/mult-x) ? math.floor(x*mult)/mult : math.ceil(x*mult)/mult//Very short SMA's to show the effect of crossovers und price values with more decimals than the tick has-sma1 = sma(close, 2), sma1impr = EnableStrictCross ? f_roundToPip(sma1) : sma1+sma1 = ta.sma(close, 2), sma1impr = EnableStrictCross ? f_roundToPip(sma1) : sma1-sma2 = sma(close, 3), sma2impr = EnableStrictCross ? f_roundToPip(sma2) : sma2+sma2 = ta.sma(close, 3), sma2impr = EnableStrictCross ? f_roundToPip(sma2) : sma2-longCondition = crossover(sma1impr - SpreadBetween/2, sma2impr + SpreadBetween/2)+longCondition = ta.crossover(sma1impr - SpreadBetween/2, sma2impr + SpreadBetween/2)if (longCondition and f_tWindow()) strategy.entry("Long", strategy.long)-shortCondition = crossunder(sma1impr + SpreadBetween/2, sma2impr - SpreadBetween/2)+shortCondition = ta.crossunder(sma1impr + SpreadBetween/2, sma2impr - SpreadBetween/2)if (shortCondition and f_tWindow())⋯plot(strategy.position_size < 0 ? sma2impr + SpreadBetween : sma2impr - SpreadBetween, title="SMA2 Improved + Spread", color=color.green, linewidth=1)-plot(sma1*1000, title="sma1*1000 (Show hidden decimal values)", transp=100)+plot(sma1*1000, title="sma1*1000 (Show hidden decimal values)")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: 383 before, 280 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.
⋯// © Canundo-//@version=5+//@version=6strategy("Cross impro test by Canundo", overlay=true)⋯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 |
|---|---|---|---|
| Enable Strict Cross (rounds SMA to pips/ticks), otherwise standard | true | bool | sma1impr sma2impr |
| Backtest Trade Candle Count | 3000 | int (written input.integer) | timeFrame |
| Change mintick for Cross Check (0 = Standard Tick/Pip, Chose pips like 0.5, 10, 100, 0.002) | 0 | float | mult |
| Add spread between values to be crossed. | 0 | float | longCondition shortCondition SMA1 Improved + Spread SMA2 Improved + Spread |
What it calculates
- SMA (
sma,ta.smain v5)close, 2sma1 · line 21 - SMA (
sma,ta.smain v5)close, 3sma2 · line 22 - Crossover (
crossover,ta.crossoverin v5)sma1impr - SpreadBetween/2, sma2impr + SpreadBetween/2longCondition · line 23 - Crossunder (
crossunder,ta.crossunderin v5)sma1impr + SpreadBetween/2, sma2impr - SpreadBetween/2shortCondition · line 26
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 | (longCondition and f_tWindow()) | On | 25 |
| Open Short short | (shortCondition and f_tWindow()) | On | 28 |
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 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 | +28.9% | +102.5% | 383 | 41% | 1.08 | 36.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.4% | +5.5% | 384 | 35% | 1.00 | 17.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +3.6% | +9.8% | 364 | 41% | 1.21 | 2.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.3% | +8.4% | 407 | 36% | 0.93 | 0.9% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 355 | 40% | 0.98 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 371 | 38% | 1.02 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.4% | +148.3% | 373 | 41% | 0.90 | 1.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.1% | +17.1% | 377 | 39% | 1.14 | 0.2% | 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 | 143 | 40% | −$17,792.40 |
| Sideways market | 156 | 44% | $39,974.50 |
| Falling market | 84 | 38% | $6,736.16 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
45.5%
The 95th percentile of the worst drawdown when the same 383 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 23.0% to 45.5%; the tick is what actually happened, 33.4%. Order luck alone moves it this much.
The first 150 of 383 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 1 Feb 2024 42,580.00 | 3 Feb 2024 43,200.00 | 2 | −$619.99 |
| long | 3 Feb 2024 43,200.00 | 5 Feb 2024 42,582.90 | 2 | −$617.11 |
| short | 5 Feb 2024 42,582.90 | 7 Feb 2024 43,099.00 | 2 | −$516.08 |
| long | 7 Feb 2024 43,099.00 | 19 Feb 2024 52,137.70 | 12 | $9,038.72 |
| short | 19 Feb 2024 52,137.70 | 20 Feb 2024 51,774.70 | 1 | $362.94 |
| long | 20 Feb 2024 51,774.70 | 21 Feb 2024 52,258.80 | 1 | $484.08 |
| short | 21 Feb 2024 52,258.80 | 22 Feb 2024 51,849.40 | 1 | $409.44 |
| long | 22 Feb 2024 51,849.40 | 23 Feb 2024 51,288.40 | 1 | −$560.96 |
| short | 23 Feb 2024 51,288.40 | 26 Feb 2024 51,728.80 | 3 | −$440.43 |
| long | 26 Feb 2024 51,728.80 | 2 Mar 2024 62,387.90 | 5 | $10,659.10 |
| short | 2 Mar 2024 62,387.90 | 3 Mar 2024 61,987.30 | 1 | $400.62 |
| long | 3 Mar 2024 61,987.30 | 7 Mar 2024 66,074.00 | 4 | $4,086.76 |
| short | 7 Mar 2024 66,074.00 | 8 Mar 2024 66,823.20 | 1 | −$749.14 |
| long | 8 Mar 2024 66,823.20 | 16 Mar 2024 69,499.80 | 8 | $2,676.66 |
| short | 16 Mar 2024 69,499.80 | 19 Mar 2024 67,610.00 | 3 | $1,889.84 |
| long | 19 Mar 2024 67,610.00 | 20 Mar 2024 61,937.40 | 1 | −$5,672.59 |
| short | 20 Mar 2024 61,937.40 | 22 Mar 2024 65,501.30 | 2 | −$3,563.87 |
| long | 22 Mar 2024 65,501.30 | 23 Mar 2024 63,796.60 | 1 | −$1,704.64 |
| short | 23 Mar 2024 63,796.60 | 25 Mar 2024 67,210.00 | 2 | −$3,413.36 |
| long | 25 Mar 2024 67,210.00 | 28 Mar 2024 69,470.00 | 3 | $2,259.99 |
| short | 28 Mar 2024 69,470.00 | 29 Mar 2024 70,780.60 | 1 | −$1,310.61 |
| long | 29 Mar 2024 70,780.60 | 31 Mar 2024 69,582.20 | 2 | −$1,198.43 |
| short | 31 Mar 2024 69,582.20 | 1 Apr 2024 71,280.00 | 1 | −$1,697.83 |
| long | 1 Apr 2024 71,280.00 | 3 Apr 2024 65,464.00 | 2 | −$5,816.01 |
| short | 3 Apr 2024 65,464.00 | 5 Apr 2024 68,487.80 | 2 | −$3,023.81 |
| long | 5 Apr 2024 68,487.80 | 7 Apr 2024 68,896.00 | 2 | $408.20 |
| short | 7 Apr 2024 68,896.00 | 8 Apr 2024 69,360.40 | 1 | −$464.38 |
| long | 8 Apr 2024 69,360.40 | 11 Apr 2024 70,631.10 | 3 | $1,270.70 |
| short | 11 Apr 2024 70,631.10 | 12 Apr 2024 70,006.20 | 1 | $624.86 |
| long | 12 Apr 2024 70,006.20 | 13 Apr 2024 67,116.50 | 1 | −$2,889.70 |
| short | 13 Apr 2024 67,116.50 | 16 Apr 2024 63,420.00 | 3 | $3,696.53 |
| long | 16 Apr 2024 63,420.00 | 17 Apr 2024 63,793.40 | 1 | $373.41 |
| short | 17 Apr 2024 63,793.40 | 20 Apr 2024 63,818.00 | 3 | −$24.61 |
| long | 20 Apr 2024 63,818.00 | 25 Apr 2024 64,289.60 | 5 | $471.57 |
| short | 25 Apr 2024 64,289.60 | 30 Apr 2024 63,866.00 | 5 | $423.58 |
| long | 30 Apr 2024 63,866.00 | 1 May 2024 60,672.00 | 1 | −$3,193.99 |
| short | 1 May 2024 60,672.00 | 4 May 2024 62,882.00 | 3 | −$2,210.00 |
| long | 4 May 2024 62,882.00 | 7 May 2024 63,165.20 | 3 | $283.17 |
| short | 7 May 2024 63,165.20 | 11 May 2024 60,800.00 | 4 | $2,365.19 |
| long | 11 May 2024 60,800.00 | 12 May 2024 60,826.00 | 1 | $26.00 |
| short | 12 May 2024 60,826.00 | 13 May 2024 61,484.00 | 1 | −$658.01 |
| long | 13 May 2024 61,484.00 | 18 May 2024 67,024.00 | 5 | $5,540.00 |
| short | 18 May 2024 67,024.00 | 19 May 2024 66,915.20 | 1 | $108.80 |
| long | 19 May 2024 66,915.20 | 20 May 2024 66,274.00 | 1 | −$641.20 |
| short | 20 May 2024 66,274.00 | 21 May 2024 71,446.60 | 1 | −$5,172.62 |
| long | 21 May 2024 71,446.60 | 23 May 2024 69,166.60 | 2 | −$2,280.00 |
| short | 23 May 2024 69,166.60 | 26 May 2024 69,290.60 | 3 | −$123.94 |
| long | 26 May 2024 69,290.60 | 28 May 2024 69,436.40 | 2 | $145.87 |
| short | 28 May 2024 69,436.40 | 29 May 2024 68,398.40 | 1 | $1,038.03 |
| long | 29 May 2024 68,398.40 | 30 May 2024 67,652.40 | 1 | −$745.99 |
| short | 30 May 2024 67,652.40 | 1 Jun 2024 67,540.00 | 2 | $112.40 |
| long | 1 Jun 2024 67,540.00 | 2 Jun 2024 67,766.80 | 1 | $226.83 |
| short | 2 Jun 2024 67,766.80 | 3 Jun 2024 67,765.60 | 1 | $1.22 |
| long | 3 Jun 2024 67,765.60 | 8 Jun 2024 69,355.60 | 5 | $1,589.98 |
| short | 8 Jun 2024 69,355.60 | 10 Jun 2024 69,648.10 | 2 | −$292.55 |
| long | 10 Jun 2024 69,648.10 | 12 Jun 2024 67,314.20 | 2 | −$2,333.92 |
| short | 12 Jun 2024 67,314.20 | 14 Jun 2024 66,773.00 | 2 | $541.22 |
| long | 14 Jun 2024 66,773.00 | 15 Jun 2024 66,044.00 | 1 | −$729.02 |
| short | 15 Jun 2024 66,044.00 | 17 Jun 2024 66,676.90 | 2 | −$632.87 |
| long | 17 Jun 2024 66,676.90 | 19 Jun 2024 65,175.30 | 2 | −$1,501.54 |
| short | 19 Jun 2024 65,175.30 | 27 Jun 2024 60,865.00 | 8 | $4,310.34 |
| long | 27 Jun 2024 60,865.00 | 28 Jun 2024 61,706.50 | 1 | $841.48 |
| short | 28 Jun 2024 61,706.50 | 29 Jun 2024 60,427.80 | 1 | $1,278.62 |
| long | 29 Jun 2024 60,427.80 | 30 Jun 2024 60,986.70 | 1 | $558.84 |
| short | 30 Jun 2024 60,986.70 | 1 Jul 2024 62,772.00 | 1 | −$1,785.33 |
| long | 1 Jul 2024 62,772.00 | 3 Jul 2024 62,135.50 | 2 | −$636.55 |
| short | 3 Jul 2024 62,135.50 | 7 Jul 2024 58,230.10 | 4 | $3,905.33 |
| long | 7 Jul 2024 58,230.10 | 9 Jul 2024 56,714.60 | 2 | −$1,515.52 |
| short | 9 Jul 2024 56,714.60 | 10 Jul 2024 58,050.00 | 1 | −$1,335.39 |
| long | 10 Jul 2024 58,050.00 | 12 Jul 2024 57,339.90 | 2 | −$710.11 |
| short | 12 Jul 2024 57,339.90 | 14 Jul 2024 59,204.00 | 2 | −$1,864.12 |
| long | 14 Jul 2024 59,204.00 | 18 Jul 2024 64,088.00 | 4 | $4,883.98 |
| short | 18 Jul 2024 64,088.00 | 20 Jul 2024 66,660.00 | 2 | −$2,572.02 |
| long | 20 Jul 2024 66,660.00 | 24 Jul 2024 65,936.00 | 4 | −$724.01 |
| short | 24 Jul 2024 65,936.00 | 27 Jul 2024 67,908.00 | 3 | −$1,972.00 |
| long | 27 Jul 2024 67,908.00 | 30 Jul 2024 66,784.70 | 3 | −$1,123.32 |
| short | 30 Jul 2024 66,784.70 | 8 Aug 2024 55,133.80 | 9 | $11,650.90 |
| long | 8 Aug 2024 55,133.80 | 11 Aug 2024 60,923.50 | 3 | $5,789.75 |
| short | 11 Aug 2024 60,923.50 | 14 Aug 2024 60,587.20 | 3 | $336.35 |
| long | 14 Aug 2024 60,587.20 | 16 Aug 2024 57,541.10 | 2 | −$3,046.11 |
| short | 16 Aug 2024 57,541.10 | 18 Aug 2024 59,492.00 | 2 | −$1,950.94 |
| long | 18 Aug 2024 59,492.00 | 20 Aug 2024 59,438.50 | 2 | −$53.49 |
| short | 20 Aug 2024 59,438.50 | 21 Aug 2024 59,013.80 | 1 | $424.70 |
| long | 21 Aug 2024 59,013.80 | 27 Aug 2024 62,834.00 | 6 | $3,820.20 |
| short | 27 Aug 2024 62,834.00 | 31 Aug 2024 59,124.00 | 4 | $3,710.01 |
| long | 31 Aug 2024 59,124.00 | 1 Sep 2024 58,974.00 | 1 | −$149.99 |
| short | 1 Sep 2024 58,974.00 | 4 Sep 2024 57,487.70 | 3 | $1,486.26 |
| long | 4 Sep 2024 57,487.70 | 5 Sep 2024 57,970.90 | 1 | $483.16 |
| short | 5 Sep 2024 57,970.90 | 9 Sep 2024 54,869.90 | 4 | $3,100.95 |
| long | 9 Sep 2024 54,869.90 | 16 Sep 2024 59,132.00 | 7 | $4,262.05 |
| short | 16 Sep 2024 59,132.00 | 18 Sep 2024 60,314.00 | 2 | −$1,181.99 |
| long | 18 Sep 2024 60,314.00 | 27 Sep 2024 65,174.00 | 9 | $4,860.00 |
| short | 27 Sep 2024 65,174.00 | 28 Sep 2024 65,769.90 | 1 | −$595.96 |
| long | 28 Sep 2024 65,769.90 | 30 Sep 2024 65,602.00 | 2 | −$167.94 |
| short | 30 Sep 2024 65,602.00 | 5 Oct 2024 62,086.00 | 5 | $3,516.01 |
| long | 5 Oct 2024 62,086.00 | 9 Oct 2024 62,160.50 | 4 | $74.50 |
| short | 9 Oct 2024 62,160.50 | 12 Oct 2024 62,540.00 | 3 | −$379.49 |
| long | 12 Oct 2024 62,540.00 | 22 Oct 2024 67,377.50 | 10 | $4,837.51 |
| short | 22 Oct 2024 67,377.50 | 25 Oct 2024 68,198.30 | 3 | −$820.77 |
| long | 25 Oct 2024 68,198.30 | 27 Oct 2024 67,092.80 | 2 | −$1,105.51 |
| short | 27 Oct 2024 67,092.80 | 28 Oct 2024 68,021.70 | 1 | −$928.93 |
| long | 28 Oct 2024 68,021.70 | 1 Nov 2024 70,292.00 | 4 | $2,270.32 |
| short | 1 Nov 2024 70,292.00 | 7 Nov 2024 75,572.00 | 6 | −$5,279.98 |
| long | 7 Nov 2024 75,572.00 | 16 Nov 2024 91,032.10 | 9 | $15,460.10 |
| short | 16 Nov 2024 91,032.10 | 17 Nov 2024 90,588.00 | 1 | $444.10 |
| long | 17 Nov 2024 90,588.00 | 18 Nov 2024 89,856.00 | 1 | −$732.00 |
| short | 18 Nov 2024 89,856.00 | 20 Nov 2024 92,310.80 | 2 | −$2,454.82 |
| long | 20 Nov 2024 92,310.80 | 24 Nov 2024 97,672.40 | 4 | $5,361.60 |
| short | 24 Nov 2024 97,672.40 | 28 Nov 2024 95,863.10 | 4 | $1,809.29 |
| long | 28 Nov 2024 95,863.10 | 2 Dec 2024 97,185.20 | 4 | $1,322.06 |
| short | 2 Dec 2024 97,185.20 | 3 Dec 2024 95,840.60 | 1 | $1,344.56 |
| long | 3 Dec 2024 95,840.60 | 4 Dec 2024 95,849.70 | 1 | $9.08 |
| short | 4 Dec 2024 95,849.70 | 5 Dec 2024 98,587.30 | 1 | −$2,737.63 |
| long | 5 Dec 2024 98,587.30 | 7 Dec 2024 99,740.80 | 2 | $1,153.52 |
| short | 7 Dec 2024 99,740.80 | 8 Dec 2024 99,832.00 | 1 | −$91.15 |
| long | 8 Dec 2024 99,832.00 | 10 Dec 2024 97,276.50 | 2 | −$2,555.51 |
| short | 10 Dec 2024 97,276.50 | 12 Dec 2024 101,125.00 | 2 | −$3,848.52 |
| long | 12 Dec 2024 101,125.00 | 14 Dec 2024 101,424.00 | 2 | $299.24 |
| short | 14 Dec 2024 101,424.00 | 15 Dec 2024 101,420.00 | 1 | $4.24 |
| long | 15 Dec 2024 101,420.00 | 19 Dec 2024 100,204.00 | 4 | −$1,215.99 |
| short | 19 Dec 2024 100,204.00 | 22 Dec 2024 97,292.00 | 3 | $2,912.01 |
| long | 22 Dec 2024 97,292.00 | 23 Dec 2024 95,186.30 | 1 | −$2,105.72 |
| short | 23 Dec 2024 95,186.30 | 25 Dec 2024 98,663.60 | 2 | −$3,477.30 |
| long | 25 Dec 2024 98,663.60 | 27 Dec 2024 95,791.60 | 2 | −$2,871.98 |
| short | 27 Dec 2024 95,791.60 | 30 Dec 2024 93,738.20 | 3 | $2,053.41 |
| long | 30 Dec 2024 93,738.20 | 31 Dec 2024 92,792.10 | 1 | −$946.14 |
| short | 31 Dec 2024 92,792.10 | 2 Jan 2025 94,591.80 | 2 | −$1,799.73 |
| long | 2 Jan 2025 94,591.80 | 9 Jan 2025 95,060.60 | 7 | $468.83 |
| short | 9 Jan 2025 95,060.60 | 12 Jan 2025 94,600.00 | 3 | $460.62 |
| long | 12 Jan 2025 94,600.00 | 13 Jan 2025 94,545.10 | 1 | −$54.92 |
| short | 13 Jan 2025 94,545.10 | 15 Jan 2025 96,560.90 | 2 | −$2,015.78 |
| long | 15 Jan 2025 96,560.90 | 20 Jan 2025 101,332.00 | 5 | $4,770.72 |
| short | 20 Jan 2025 101,332.00 | 22 Jan 2025 106,144.00 | 2 | −$4,812.25 |
| long | 22 Jan 2025 106,144.00 | 24 Jan 2025 103,910.00 | 2 | −$2,233.47 |
| short | 24 Jan 2025 103,910.00 | 25 Jan 2025 104,871.00 | 1 | −$960.16 |
| long | 25 Jan 2025 104,871.00 | 27 Jan 2025 102,620.00 | 2 | −$2,250.50 |
| short | 27 Jan 2025 102,620.00 | 30 Jan 2025 103,733.00 | 3 | −$1,113.24 |
| long | 30 Jan 2025 103,733.00 | 1 Feb 2025 102,430.00 | 2 | −$1,303.69 |
| short | 1 Feb 2025 102,430.00 | 5 Feb 2025 97,763.10 | 4 | $4,666.42 |
| long | 5 Feb 2025 97,763.10 | 6 Feb 2025 96,612.40 | 1 | −$1,150.70 |
| short | 6 Feb 2025 96,612.40 | 11 Feb 2025 97,430.80 | 5 | −$818.38 |
| long | 11 Feb 2025 97,430.80 | 13 Feb 2025 97,870.00 | 2 | $439.18 |
| short | 13 Feb 2025 97,870.00 | 14 Feb 2025 96,608.10 | 1 | $1,261.87 |
| long | 14 Feb 2025 96,608.10 | 15 Feb 2025 97,500.50 | 1 | $892.34 |
| short | 15 Feb 2025 97,500.50 | 16 Feb 2025 97,569.70 | 1 | −$69.20 |
| long | 16 Feb 2025 97,569.70 | 17 Feb 2025 96,118.10 | 1 | −$1,451.55 |
| short | 17 Feb 2025 96,118.10 | 20 Feb 2025 96,644.40 | 3 | −$526.25 |
| long | 20 Feb 2025 96,644.40 | 23 Feb 2025 96,551.00 | 3 | −$93.36 |
| short | 23 Feb 2025 96,551.00 | 24 Feb 2025 96,258.00 | 1 | $293.01 |
| long | 24 Feb 2025 96,258.00 | 25 Feb 2025 91,552.90 | 1 | −$4,705.12 |
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 |
|---|---|---|---|---|---|
| Cross impro test by Canundo Crossover Crossunder Tick values this page | — | v4 strategy | +28.9% | 383 | 36.2% |
| 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% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 12 ms | Yes 1,000 bars in 39 ms | Not measured |
| PineTS | No v5 and v6 only | — | 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. 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/// © Canundo//@version=4strategy("Cross impro test by Canundo", overlay=true)//Run on 1 min chart for better testing cases where x and y of crossover have the same value.EnableStrictCross = input(title="Enable Strict Cross (rounds SMA to pips/ticks), otherwise standard", type=input.bool, defval=true) //Disable to see differencesBacktestTradeCandleCount = input(title="Backtest Trade Candle Count", type=input.integer, defval=3000) //Avoid error for too many tradesMinTick = input(title="Change mintick for Cross Check (0 = Standard Tick/Pip, Chose pips like 0.5, 10, 100, 0.002)", type=input.float, defval=0) //Precision of round to pip functionSpreadBetween = input(title="Add spread between values to be crossed.", type=input.float, defval=0) //Calculate Timeframe for Backtest demonstrationstarttime = 0, starttime := starttime[1] != 0 ? starttime[1] : timenowtimeFrame = (time_close - time_close[1]) * BacktestTradeCandleCountf_tWindow() => time >= starttime - timeFrame ? true : false//Rounding functionmult = 1 / (MinTick == 0 ? syminfo.mintick : MinTick)f_roundToPip(x)=> (x-floor(x*mult)/mult) < (ceil(x*mult)/mult-x) ? floor(x*mult)/mult : ceil(x*mult)/mult//Very short SMA's to show the effect of crossovers und price values with more decimals than the tick hassma1 = sma(close, 2), sma1impr = EnableStrictCross ? f_roundToPip(sma1) : sma1sma2 = sma(close, 3), sma2impr = EnableStrictCross ? f_roundToPip(sma2) : sma2longCondition = crossover(sma1impr - SpreadBetween/2, sma2impr + SpreadBetween/2)if (longCondition and f_tWindow()) strategy.entry("Long", strategy.long)shortCondition = crossunder(sma1impr + SpreadBetween/2, sma2impr - SpreadBetween/2)if (shortCondition and f_tWindow()) strategy.entry("Short", strategy.short)//Show changed SMA as line, show normal SMA with crosses.plot(sma1, title="SMA1", color=color.red, linewidth=2, style=plot.style_cross)plot(sma1impr, title="SMA1 Improved", color=color.red, linewidth=2, style=plot.style_cross)plot(strategy.position_size < 0 ? sma1impr - SpreadBetween/2 : sma1impr + SpreadBetween/2, title="SMA1 Improved + Spread", color=color.red, linewidth=1)plot(sma2, title="SMA2", color=color.green, linewidth=2, style=plot.style_cross)plot(sma2impr, title="SMA2 Improved ", color=color.green, linewidth=2, style=plot.style_cross)plot(strategy.position_size < 0 ? sma2impr + SpreadBetween : sma2impr - SpreadBetween, title="SMA2 Improved + Spread", color=color.green, linewidth=1)plot(sma1*1000, title="sma1*1000 (Show hidden decimal values)", transp=100)