Pine Script v5 · Strategy
Arnaud Legoux Moving Average Cross (ALMA)
A Pine Script v5 strategy built on ALMA (src, 60), EMA (volume, 5) and Crossover (Alma1, Alma2). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 14 settings; defaults include ALMA Lenghth 1 60, Arnaud Legoux (ALMA) - Offset Value 0.85 and Arnaud Legoux (ALMA) - Sigma Value 6.
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 Arnaud Legoux Moving Average Cross (ALMA) 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 Arnaud Legoux Moving Average Cross (ALMA) do on BTCUSDT 1D with default settings?
- +0.15%
- From 26 Jan 2024 to 21 Oct 2026, over 9 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- What alerts does Arnaud Legoux Moving Average Cross (ALMA) have?
- 2
- BUY Trade Entry Alert; SELL Trade Entry Alert.
- Does Arnaud Legoux Moving Average Cross (ALMA) 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: 9 before, 9 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 Arnaud Legoux Moving Average Cross (ALMA) use a stop loss?
- Yes
- strategy.exit sets a stop on line 67, 69.
BTCUSDT · 1D · default settings
- Alma Fast
- Alma Slow
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +0.15%
- $1,501.79
- Buy and hold
- +102.5%
- same period
- Closed trades
- 9
- 5 won · 4 lost
- Profitable
- 55.6%
- of closed trades
- Profit factor
- 1.16
- gross profit ÷ gross loss
- Max drawdown
- 0.86%
- −$8,581.27
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. 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 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 |
|---|---|---|---|
| Long Entry | true | bool | entry Long line 57 |
| Short Entry | true | bool | entry Short line 61 |
| Arnaud Legoux (ALMA) - Offset Value | 0.85 | float · min 0 · step 0.01 | Alma1 |
| Arnaud Legoux (ALMA) - Sigma Value | 6 | int · min 0 | Alma1 |
| Arnaud Legoux (ALMA) - Offset Value | 0.85 | float · min 0 · step 0.01 | Alma2 |
| Arnaud Legoux (ALMA) - Sigma Value | 6 | int · min 0 | Alma2 |
| Long Length | 10 | int · min 1 | long |
| Short Take Profit | 2 | float · min 0.0 · step 0.1 | shortExitPrice |
| Short Stop Loss | 2.5 | float · min 0.0 · step 0.1 | shortStopPrice |
| ALMA Fast Length Settings | |||
| ALMA Lenghth 1 | 60 | int | Alma1 |
| ALMA Slow Length Settings | |||
| ALMA Length 2 | 120 | int | Alma2 |
| Volume Settings | |||
| Short Length | 5 | int · min 1 | short |
| Take Profit Percentage | |||
| Long Take Profit | 2 | float · min 0.0 · step 0.1 | longExitPrice |
| Stop Percentage | |||
| Long Stop Loss | 2.5 | float · min 0.0 · step 0.1 | longStopPrice |
What it calculates
- ALMAsrc, ALMA Lenghth 1 (60), Arnaud Legoux (ALMA) - Offset Value (0.85), Arnaud Legoux (ALMA) - Sigma Value (6)
Alma1 · line 14 - ALMAsrc, ALMA Length 2 (120), Arnaud Legoux (ALMA) - Offset Value (0.85), Arnaud Legoux (ALMA) - Sigma Value (6)
Alma2 · line 19 - EMAvolume, Short Length (5)
short · line 27 - EMAvolume, Long Length (10)
long · line 28 - CrossoverAlma1, Alma2
buy · line 31 - CrossunderAlma1, Alma2
sell · line 32
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 | buySignal and long_entry | On | 58 |
| Open Short short | sellSignal and short_entry | On | 62 |
| Exit Long TP/SL stop and limit | (strategy.position_size > 0) | On | 67 |
| Exit Short TP/SL stop and limit | (strategy.position_size < 0) | On | 69 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | BUY Trade Entry Alert | 59 |
| (no title) | alert | SELL Trade Entry Alert | 63 |
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 | +0.2% | +102.5% | 9 | 56% | 1.16 | 0.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.0% | +5.5% | 5 | 60% | 1.06 | 0.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.0% | +9.8% | 3 | 100% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 7 | 71% | 1.55 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 12 | 58% | 1.32 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 7 | 14% | 0.10 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 10 | 60% | 1.42 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 14 | 43% | 0.61 | 0.0% | 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 | 50% | −$759.07 |
| Sideways market | 5 | 60% | $2,702.43 |
| Falling market | 2 | 50% | −$441.57 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
1.0%
The 95th percentile of the worst drawdown when the same 9 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.3% to 1.0%; the tick is what actually happened, 0.8%. Order luck alone moves it this much.
All 9 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 26 Jun 2024 61,806.00 | 28 Jun 2024 60,569.90 | 2 | $1,236.13 |
| short | 11 Jan 2025 94,726.10 | 13 Jan 2025 92,831.60 | 2 | $1,894.53 |
| long | 22 Jan 2025 106,144.00 | 23 Jan 2025 103,490.00 | 1 | −$2,653.60 |
| long | 26 Apr 2025 94,638.70 | 1 May 2025 96,531.50 | 5 | $1,892.78 |
| short | 23 Oct 2025 107,567.00 | 24 Oct 2025 110,257.00 | 1 | −$2,689.19 |
| long | 14 Jan 2026 95,414.00 | 19 Jan 2026 93,028.60 | 5 | −$2,385.35 |
| short | 2 Feb 2026 76,968.20 | 3 Feb 2026 78,892.40 | 1 | −$1,924.21 |
| long | 15 Apr 2026 74,131.60 | 17 Apr 2026 75,614.20 | 2 | $1,482.64 |
| short | 2 Jun 2026 71,408.90 | 3 Jun 2026 66,760.80 | 1 | $4,648.06 |
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 |
|---|---|---|---|---|---|
| Arnaud Legoux Moving Average Cross (ALMA) this page | — | v5 strategy | +0.2% | 9 | 0.9% |
| Trend Identifier Strategy by spacekadet17 | alma ema | v5 strategy | +62.0% | 24 | 20.4% |
| Full Crypto Swing Strategy ALMA Cross with MACD by exlux99 | alma ema | v4 strategy | No trades on this market | ||
| Korea premium(KIMP) by roses27 | alma ema | v4 strategy | does not run in Zeal Terminal | ||
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.
- 4 settings use the untyped input() (line 8, 9, 11, 16). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 9 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 8: input() → input.bool()
- Line 9: input() → input.bool()
- Line 11: input() → input.int()
- Line 16: input() → input.int()
⋯src= (close)-long_entry = input(true, title='Long Entry')+long_entry = input.bool(true, title='Long Entry')-short_entry = input(true, title='Short Entry')+short_entry = input.bool(true, title='Short Entry')//Fast Settings-ALMA1 = input(60, "ALMA Lenghth 1", group= "ALMA Fast Length Settings")+ALMA1 = input.int(60, "ALMA Lenghth 1", group= "ALMA Fast Length Settings")alma_offset = input.float(defval=0.85, title='Arnaud Legoux (ALMA) - Offset Value', minval=0, step=0.01)⋯//Slow Settings-ALMA2 = input(120, "ALMA Length 2", group = "ALMA Slow Length Settings")+ALMA2 = input.int(120, "ALMA Length 2", group = "ALMA Slow Length Settings")alma_offset2 = input.float(defval=0.85, title='Arnaud Legoux (ALMA) - Offset Value', minval=0, step=0.01)⋯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: 9 before, 9 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.
⋯// Calculations for TP/SL based off: https://kodify.net/tradingview/orders/percentage-profit/-//@version=5+//@version=6strategy("ALMA Cross", overlay=true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 19 ms | With a workaround 1,000 bars in 50 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently reads an order side written as direction = strategy.long, direction = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 58, 62) 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/// © Sarahann999// Calculations for TP/SL based off: https://kodify.net/tradingview/orders/percentage-profit///@version=5strategy("ALMA Cross", overlay=true)//User Inputssrc= (close)long_entry = input(true, title='Long Entry')short_entry = input(true, title='Short Entry')//Fast SettingsALMA1 = input(60, "ALMA Lenghth 1", group= "ALMA Fast Length Settings")alma_offset = input.float(defval=0.85, title='Arnaud Legoux (ALMA) - Offset Value', minval=0, step=0.01)alma_sigma = input.int(defval=6, title='Arnaud Legoux (ALMA) - Sigma Value', minval=0)Alma1 = ta.alma(src, ALMA1, alma_offset, alma_sigma)//Slow SettingsALMA2 = input(120, "ALMA Length 2", group = "ALMA Slow Length Settings")alma_offset2 = input.float(defval=0.85, title='Arnaud Legoux (ALMA) - Offset Value', minval=0, step=0.01)alma_sigma2 = input.int(defval=6, title='Arnaud Legoux (ALMA) - Sigma Value', minval=0)Alma2 = ta.alma(src, ALMA2, alma_offset2, alma_sigma2)//Volumevar cumVol = 0.cumVol += nz(volume)if barstate.islast and cumVol == 0 runtime.error("No volume is provided by the data vendor.")shortlen = input.int(5, minval=1, title = "Short Length", group= "Volume Settings")longlen = input.int(10, minval=1, title = "Long Length")short = ta.ema(volume, shortlen)long = ta.ema(volume, longlen)osc = 100 * (short - long) / long//Define Cross Conditionsbuy = ta.crossover(Alma1, Alma2)sell = ta.crossunder(Alma1, Alma2)//Calculate Take Profit PercentagelongProfitPerc = input.float(title="Long Take Profit", group='Take Profit Percentage', minval=0.0, step=0.1, defval=2) / 100shortProfitPerc = input.float(title="Short Take Profit", minval=0.0, step=0.1, defval=2) / 100 // Figure out take profit price 1longExitPrice = strategy.position_avg_price * (1 + longProfitPerc)shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)// Make inputs that set the stop % 1longStopPerc = input.float(title="Long Stop Loss", group='Stop Percentage', minval=0.0, step=0.1, defval=2.5) / 100shortStopPerc = input.float(title="Short Stop Loss", minval=0.0, step=0.1, defval=2.5) / 100// Figure Out Stop PricelongStopPrice = strategy.position_avg_price * (1 - longStopPerc)shortStopPrice = strategy.position_avg_price * (1 + shortStopPerc)//Define ConditionsbuySignal = buy and osc > 0 and strategy.position_size == 0//sellSignal sellSignal = sell and osc > 0 and strategy.position_size == 0// Submit entry ordersif buySignal and long_entry strategy.entry(id="Long", direction=strategy.long, alert_message="Enter Long") alert(message="BUY Trade Entry Alert", freq=alert.freq_once_per_bar) if sellSignal and short_entry strategy.entry(id="Short", direction=strategy.short, alert_message="Enter Short") alert(message="SELL Trade Entry Alert", freq=alert.freq_once_per_bar) // Submit exit orders based on take profit priceif (strategy.position_size > 0) strategy.exit(id="Long TP/SL", limit=longExitPrice, stop=longStopPrice, alert_message="Long Exit 1 at {{close}}")if (strategy.position_size < 0) strategy.exit(id="Short TP/SL", limit=shortExitPrice, stop=shortStopPrice, alert_message="Short Exit 1 at {{close}}")//Drawplot(Alma1,"Alma Fast", color=color.purple, style=plot.style_circles)plot(Alma2,"Alma Slow", color=#acb5c2, style=plot.style_circles)