Pine Script v4 · Strategy
CROSS_ALGO SYSTEM
A Pine Script v4 strategy built on EMA (close, 13), Crossover (SEMA, LEMA) and Crossunder (SEMA, LEMA). It has 4 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. 2 settings; defaults include LSEMA 13 and LLEMA 50.
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_ALGO SYSTEM repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
- How did CROSS_ALGO SYSTEM do on BTCUSDT 1D with default settings?
- +16.77%
- From 26 Jan 2024 to 21 Oct 2026, over 17 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can CROSS_ALGO SYSTEM 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_ALGO SYSTEM use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does CROSS_ALGO SYSTEM run in Zeal Terminal?
- Yes
- It compiles in 8 ms and runs 1,000 bars in 24 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- EMA
- Crossover
- Crossunder
- Crossunder
- Crossover
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +16.77%
- $16,774.60
- Buy and hold
- +102.5%
- same period
- Closed trades
- 17
- 6 won · 11 lost
- Profitable
- 35.3%
- of closed trades
- Profit factor
- 1.25
- gross profit ÷ gross loss
- Max drawdown
- 33.41%
- −$37,985.30
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 an argument v6 removed
when = on line 18, 19, 20, 21. The upgraded version below moves each call inside an if block.
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 ema → ta.ema, crossover → ta.crossover, crossunder → ta.crossunder.
- 4 strategy calls use the when = argument (line 18, 19, 20, 21). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 17 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.integer) → input.int()
- Line 7: input(type = input.integer) → input.int()
- Line 9: ema → ta.ema
- Line 10: ema → ta.ema
- Line 12: crossover → ta.crossover
3 more edits
- Line 13: crossunder → ta.crossunder
- Line 15: crossunder → ta.crossunder
- Line 16: crossover → ta.crossover
⋯// © himanshumahalle-//@version=4+//@version=5strategy("CROSS_ALGO SYSTEM")// INPUT CONTROLS-lengthSEMA= input(title="LSEMA", type = input.integer, defval=13,minval=1,maxval=100,step=1)+lengthSEMA= input.int(title="LSEMA", defval=13,minval=1,maxval=100,step=1)-lengthLEMA= input(title="LLEMA", type = input.integer, defval=50,minval=1,maxval=100,step=1)+lengthLEMA= input.int(title="LLEMA", defval=50,minval=1,maxval=100,step=1)//INDICATOR-SEMA= ema(close,lengthSEMA)+SEMA= ta.ema(close,lengthSEMA)-LEMA= ema(close,lengthLEMA)+LEMA= ta.ema(close,lengthLEMA)// BUY AND SELL-buy = crossover(SEMA,LEMA)+buy = ta.crossover(SEMA,LEMA)-sell = crossunder(SEMA,LEMA)+sell = ta.crossunder(SEMA,LEMA)//EXITS-buyexit = crossunder(SEMA,LEMA)+buyexit = ta.crossunder(SEMA,LEMA)-sellexit = crossover(SEMA,LEMA)+sellexit = ta.crossover(SEMA,LEMA)//EXECUTION⋯Same 17 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 18: when = buy → if block
- Line 19: when = sell → if block
- Line 20: when = buyexit → if block
- Line 21: when = sellexit → if block
⋯//EXECUTION-strategy.entry("long",strategy.long,when=buy,comment = "Buy")+if buy+ strategy.entry("long",strategy.long,comment = "Buy")-strategy.entry("short",strategy.short,when=sell,comment = "Sell")+if sell+ strategy.entry("short",strategy.short,comment = "Sell")-strategy.close("long",when= buyexit , comment= "Sell")+if buyexit+ strategy.close("long" , comment= "Sell")-strategy.close("short",when= sellexit , comment= "Buy")+if sellexit+ strategy.close("short" , comment= "Buy")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: 17 before, 18 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.
⋯// © himanshumahalle-//@version=5+//@version=6strategy("CROSS_ALGO SYSTEM")⋯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 |
|---|---|---|---|
| LSEMA | 13 | int (written input.integer) · min 1 · max 100 · step 1 | SEMA |
| LLEMA | 50 | int (written input.integer) · min 1 · max 100 · step 1 | LEMA |
What it calculates
- EMA (
ema,ta.emain v5)close, LSEMA (13)SEMA · line 9 - EMA (
ema,ta.emain v5)close, LLEMA (50)LEMA · line 10 - Crossover (
crossover,ta.crossoverin v5)SEMA, LEMAbuy · line 12 - Crossunder (
crossunder,ta.crossunderin v5)SEMA, LEMAsell · line 13 - Crossunder (
crossunder,ta.crossunderin v5)SEMA, LEMAbuyexit · line 15 - Crossover (
crossover,ta.crossoverin v5)SEMA, LEMAsellexit · line 16
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 | buy | On | 18 |
| Open short short | sell | On | 19 |
| Close long | buyexit | On | 20 |
| Close short | sellexit | On | 21 |
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 | +16.8% | +102.5% | 17 | 35% | 1.25 | 33.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +4.5% | +5.5% | 18 | 28% | 1.29 | 9.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.6% | +9.8% | 20 | 40% | 1.40 | 2.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.3% | +8.4% | 20 | 20% | 0.75 | 0.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.2% | +16.7% | 25 | 24% | 0.54 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 18 | 33% | 2.46 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.3% | +148.3% | 15 | 33% | 1.96 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.1% | +17.1% | 31 | 26% | 0.64 | 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 | 2 | 0% | −$10,813.00 |
| Sideways market | 13 | 38% | $13,246.50 |
| Falling market | 2 | 50% | $14,341.20 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
42.3%
The 95th percentile of the worst drawdown when the same 17 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 20.5% to 42.3%; the tick is what actually happened, 29.2%. Order luck alone moves it this much.
All 17 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 2 May 2024 58,365.00 | 18 May 2024 67,024.00 | 16 | −$8,659.03 |
| long | 18 May 2024 67,024.00 | 21 Jun 2024 64,870.00 | 34 | −$2,154.01 |
| short | 21 Jun 2024 64,870.00 | 22 Jul 2024 68,165.40 | 31 | −$3,295.36 |
| long | 22 Jul 2024 68,165.40 | 5 Aug 2024 58,161.00 | 14 | −$10,004.40 |
| short | 5 Aug 2024 58,161.00 | 21 Sep 2024 63,201.10 | 47 | −$5,040.05 |
| long | 21 Sep 2024 63,201.10 | 12 Feb 2025 95,778.20 | 144 | $32,577.20 |
| short | 12 Feb 2025 95,778.20 | 23 Apr 2025 93,443.00 | 70 | $2,335.22 |
| long | 23 Apr 2025 93,443.00 | 27 Aug 2025 111,763.00 | 126 | $18,320.20 |
| short | 27 Aug 2025 111,763.00 | 15 Sep 2025 115,268.00 | 19 | −$3,504.79 |
| long | 15 Sep 2025 115,268.00 | 26 Sep 2025 108,994.00 | 11 | −$6,273.52 |
| short | 26 Sep 2025 108,994.00 | 2 Oct 2025 118,595.00 | 6 | −$9,600.50 |
| long | 2 Oct 2025 118,595.00 | 17 Oct 2025 108,194.00 | 15 | −$10,400.70 |
| short | 17 Oct 2025 108,194.00 | 15 Jan 2026 96,951.80 | 90 | $11,242.50 |
| long | 15 Jan 2026 96,951.80 | 23 Jan 2026 89,559.70 | 8 | −$7,392.10 |
| short | 23 Jan 2026 89,559.70 | 14 Apr 2026 74,418.00 | 81 | $15,141.70 |
| long | 14 Apr 2026 74,418.00 | 29 May 2026 73,617.50 | 45 | −$800.48 |
| short | 29 May 2026 73,617.50 | 20 Aug 2026 69,334.80 | 83 | $4,282.74 |
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_ALGO SYSTEM this page | — | v4 strategy | +16.8% | 17 | 33.4% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 8 ms | Yes 1,000 bars in 24 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/// © himanshumahalle//@version=4strategy("CROSS_ALGO SYSTEM")// INPUT CONTROLSlengthSEMA= input(title="LSEMA", type = input.integer, defval=13,minval=1,maxval=100,step=1)lengthLEMA= input(title="LLEMA", type = input.integer, defval=50,minval=1,maxval=100,step=1)//INDICATORSEMA= ema(close,lengthSEMA)LEMA= ema(close,lengthLEMA)// BUY AND SELLbuy = crossover(SEMA,LEMA)sell = crossunder(SEMA,LEMA)//EXITSbuyexit = crossunder(SEMA,LEMA)sellexit = crossover(SEMA,LEMA)//EXECUTIONstrategy.entry("long",strategy.long,when=buy,comment = "Buy")strategy.entry("short",strategy.short,when=sell,comment = "Sell")strategy.close("long",when= buyexit , comment= "Sell")strategy.close("short",when= sellexit , comment= "Buy")