Pine Script v5 · Strategy
MAPM-V1
A Pine Script v5 strategy built on EMA (close, 8). It has 8 order rules, 4 entries among them, and trades long and short with the default settings. Exits use a profit target and no stop loss. Each trade commits 10% of equity and pays 0.1 commission. 17 settings; defaults include Signal Fast 300, Signal Slow 600 and Step Add Purchases 2.5.
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 MAPM-V1 repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did MAPM-V1 do on BTCUSDT 1D with default settings?
- +0.08%
- From 26 Jan 2024 to 21 Oct 2026, over 1 closed trade, against +102.5% for buy and hold. A backtest, not investment advice.
- Does MAPM-V1 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: 1 before, 1 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 MAPM-V1 use a stop loss?
- No
- Its exits set a profit target but no stop.
- Does MAPM-V1 run in Zeal Terminal?
- Yes
- It compiles in 31 ms and runs 1,000 bars in 63 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +0.08%
- $0.08
- Buy and hold
- +102.5%
- same period
- Closed trades
- 1
- 1 won · 0 lost
- Profitable
- 100.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.23%
- −$0.23
One run with the author's default settings, $100 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.
-
Likely bug
ta.ema(close, 8) ignores the settings line 20
Line 20 hard-codes 8 where line 23 uses “Signal Fast”. Changing those settings moves one band but not this one.
ta.ema(close, 8)ta.ema(close, SignalFast) -
Likely bug
ta.ema(close, 49) ignores the settings line 21
Line 21 hard-codes 49 where line 23 uses “Signal Fast”. Changing those settings moves one band but not this one.
ta.ema(close, 49)ta.ema(close, SignalFast) -
Check
No stop loss
strategy.exit is used without a stop, loss or trailing stop.
-
Note
9 settings have no label
In the settings dialog SignalFast (line 6), SignalSlow (line 7), StepAddPurchases (line 8), VolumePurchases (line 9), Buy (line 10), Sell (line 11), Martingale (line 14), VolumeDepo (line 15), PercentOfDepo (line 16) show an empty name. The labels on this page come from the variable names.
-
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 |
|---|---|---|---|
| Signal Fast (no label in the script) | 300 | int · step 10 | macdSignalF |
| Signal Slow (no label in the script) | 600 | int · step 10 | macdSignalS |
| Step Add Purchases (no label in the script) | 2.5 | float · step 0.1 | SteplimitLong SteplimitShort PickInLong PickInShort |
| Volume Purchases (no label in the script) | 6 | int · step 1 | PurchasesLong PurchasesShort |
| Buy (no label in the script) | true | bool | EntryLong PurchasesLong |
| Sell (no label in the script) | true | bool | EntryShort PurchasesShort |
| Long Take Profit (%) | 1 | float · min 0.0 · step 0.1 | limitLong |
| Short Take Profit (%) | 1 | float · min 0.0 · step 0.1 | limitShort |
| Martingale (no label in the script) | 1.6 | float · min 1 · step 0.1 | entry PurchasesLong entry PurchasesShort |
| Volume Depo (no label in the script) | 100 | int · step 1 | EnterVolume |
| Percent Of Depo (no label in the script) | 10 | float · step 1 | EnterVolume |
| Test Start Year | 2005 | int | startTest |
| Test Start Month | 1 | int | startTest |
| Test Start Day | 1 | int | startTest |
| Test End Year | 2050 | int | endTest |
| Test End Month | 12 | int | endTest |
| Test End Day | 30 | int | endTest |
What it calculates
- EMAclose, 8
fastAverage · line 20 - EMAclose, 49
slowAverage · line 21 - EMAmacd, Signal Fast (300)
macdSignalF · line 23 - EMAmacd, Signal Slow (600)
macdSignalS · line 24
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 Entry Long long | every bar | On | 62 |
| Open PurchasesLong long | every bar | On | 63 |
| cancel PurchasesLong | every bar | On | 64 |
| Exit TPLong limit | every bar | On | 66 |
| Open Entry Short short | every bar | On | 74 |
| Open PurchasesShort short | every bar | On | 75 |
| cancel PurchasesShort | every bar | On | 76 |
| Exit TPShort limit | every bar | On | 78 |
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 | +0.1% | +102.5% | 1 | 100% | — | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.4% | +9.8% | 3 | 67% | 2.26 | 1.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.2% | +8.4% | 1 | 100% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +3.1% | +16.7% | 4 | 100% | — | 0.6% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.1% | +21.5% | 1 | 100% | — | 0.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.3% | +148.3% | 2 | 100% | — | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.1% | +17.1% | 1 | 100% | — | 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 | 1 | 100% | $0.08 |
| Sideways market | 0 | — | $0.00 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.0%
The 95th percentile of the worst drawdown when the same 1 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.0% to 0.0%; the tick is what actually happened, 0.0%. Order luck alone moves it this much.
All 1 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 27 Sep 2026 84,433.10 | 30 Sep 2026 85,277.40 | 3 | $0.08 |
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 |
|---|---|---|---|---|---|
| MAPM-V1 this page | — | v5 strategy | +0.1% | 1 | 0.2% |
| 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% |
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.
- 8 settings use the untyped input() (line 10, 11, 26, 27, 28, 31, 32, 33). 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 1 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 10: input() → input.bool()
- Line 11: input() → input.bool()
- Line 26: input() → input.int()
- Line 27: input() → input.int()
- Line 28: input() → input.int()
- Line 31: input() → input.int()
- Line 32: input() → input.int()
- Line 33: input() → input.int()
⋯VolumePurchases = input.int(6,step=1)-Buy = input(true)+Buy = input.bool(true)-Sell = input(true)+Sell = input.bool(true)longProfitPerc = input.float(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01⋯// Test Start-startYear = input(2005, "Test Start Year")+startYear = input.int(2005, "Test Start Year")-startMonth = input(1, "Test Start Month")+startMonth = input.int(1, "Test Start Month")-startDay = input(1, "Test Start Day")+startDay = input.int(1, "Test Start Day")startTest = timestamp(startYear,startMonth,startDay,0,0)//Test End-endYear = input(2050, "Test End Year")+endYear = input.int(2050, "Test End Year")-endMonth = input(12, "Test End Month")+endMonth = input.int(12, "Test End Month")-endDay = input(30, "Test End Day")+endDay = input.int(30, "Test End Day")endTest = timestamp(endYear,endMonth,endDay,23,59)⋯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: 1 before, 1 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.
⋯// © TradingSoft_tech-//@version=5+//@version=6strategy("MAPM-V1", overlay=true, default_qty_value=10, max_bars_back=5000,default_qty_type = strategy.percent_of_equity, commission_value=0.1, initial_capital = 100, pyramiding=6, currency=currency.USD)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 31 ms | Yes 1,000 bars in 63 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// © TradingSoft_tech//@version=5strategy("MAPM-V1", overlay=true, default_qty_value=10, max_bars_back=5000,default_qty_type = strategy.percent_of_equity, commission_value=0.1, initial_capital = 100, pyramiding=6, currency=currency.USD)///////// OptionsSignalFast = input.int(300, step=10)SignalSlow = input.int(600, step=10)StepAddPurchases = input.float(2.5, step=0.1)VolumePurchases = input.int(6,step=1)Buy = input(true)Sell = input(true)longProfitPerc = input.float(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01shortProfitPerc = input.float(title="Short Take Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01Martingale = input.float(1.6, minval = 1, step = 0.1)VolumeDepo = input.int(100, step=1)PercentOfDepo = input.float(10, step=1)Close = (close)EnterVolume = VolumeDepo*PercentOfDepo*0.01/Close///////// Calculation indicatorfastAverage = ta.ema(close, 8)slowAverage = ta.ema(close, 49)macd = fastAverage - slowAveragemacdSignalF = ta.ema(macd,SignalFast)macdSignalS = ta.ema(macd,SignalSlow)// Test StartstartYear = input(2005, "Test Start Year")startMonth = input(1, "Test Start Month")startDay = input(1, "Test Start Day")startTest = timestamp(startYear,startMonth,startDay,0,0)//Test EndendYear = input(2050, "Test End Year")endMonth = input(12, "Test End Month")endDay = input(30, "Test End Day")endTest = timestamp(endYear,endMonth,endDay,23,59)timeRange = time > startTest and time < endTest ? true : false///////// Plot Data//plot(macd, style = plot.style_histogram)//plot(macdSignalF*10000, style = plot.style_line, color=color.red)//plot(macdSignalS*10000, style = plot.style_line, color=color.blue)//plot(fastAverage, style = plot.style_line, color=color.red)//plot(slowAverage, style = plot.style_line, color=color.blue)///////// Calculation of the updated valuevar x = 0.0if strategy.opentrades>strategy.opentrades[1] x := x + 1else if strategy.opentrades==0 x := 0y = x+1///////// Calculation of reference price dataentryPrice = strategy.opentrades==0? 0 : strategy.opentrades.entry_price(0)limitLong = strategy.position_avg_price * (1 + longProfitPerc)limitShort = strategy.position_avg_price * (1 - shortProfitPerc)SteplimitLong = entryPrice[0]*(1-StepAddPurchases*y/100)SteplimitShort = entryPrice[0]*(1+StepAddPurchases*y/100)///////// Conditions for a longbool EntryLong = ta.crossover(macdSignalF, macdSignalS) and Buy and strategy.opentrades==0 and strategy.position_size==0bool PurchasesLong = Buy and strategy.opentrades==x and strategy.position_size>0 and x<=VolumePurchasesbool CancelPurchasesLong = strategy.position_size==0 and strategy.opentrades==0bool TPLong = strategy.position_size>0 and strategy.opentrades!=0///////// Entry Long + add.purchases + cancel purchases + Take profit Longswitch EntryLong => strategy.entry("Entry Long", strategy.long, qty = EnterVolume) PurchasesLong => strategy.entry("PurchasesLong", strategy.long, qty = EnterVolume*math.pow(Martingale,y), limit = SteplimitLong) CancelPurchasesLong => strategy.cancel("PurchasesLong")switch TPLong => strategy.exit("TPLong", qty_percent = 100, limit = limitLong)///////// Conditions for a Shortbool EntryShort = ta.crossunder(macdSignalF, macdSignalS) and Sell and strategy.opentrades==0 and strategy.position_size==0bool PurchasesShort = Sell and strategy.opentrades==x and strategy.position_size<0 and x<=VolumePurchasesbool CancelPurchasesShort = strategy.position_size==0 and strategy.opentrades==0bool TPShort = strategy.position_size<0 and strategy.opentrades!=0///////// Entry Short + add.purchases + cancel purchases + Take profit Shortswitch EntryShort => strategy.entry("Entry Short", strategy.short, qty = EnterVolume) PurchasesShort => strategy.entry("PurchasesShort", strategy.short, qty = EnterVolume*math.pow(Martingale,y), limit = SteplimitShort) CancelPurchasesShort => strategy.cancel("PurchasesShort")switch TPShort => strategy.exit("TPShort", qty_percent = 100, limit = limitShort) /////////Calculation of conditions and reference data for level drawingInTradeLong = strategy.position_size<0InTradeShort = strategy.position_size>0PickInLong = strategy.opentrades.entry_price(0)*(1-StepAddPurchases*y/100)PickInShort = strategy.opentrades.entry_price(0)*(1+StepAddPurchases*y/100)/////////Displaying the level of Take Profitplot(InTradeLong ? na : limitLong, color=color.new(#00d146, 0), style=plot.style_linebr, linewidth=1)plot(InTradeShort ? na : limitShort, color=color.new(#00d146, 0), style=plot.style_linebr, linewidth=1)/////////Displaying the level of add.purchasesplot(InTradeLong ? na : PickInLong, color=color.white, style=plot.style_linebr, linewidth=1)plot(InTradeShort ? na : PickInShort, color=color.white, style=plot.style_linebr, linewidth=1)