Pine Script v4 · Strategy
pomila
A Pine Script v4 strategy built on SMA (tr, 10), ATR (10) and Barssince (buySignal). 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. 13 settings; defaults include ATR Period 10, Source hl2 and ATR Multiplier 3.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 pomila repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
- How did pomila do on BTCUSDT 1D with default settings?
- −54.63%
- From 26 Jan 2024 to 21 Oct 2026, over 25 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can pomila 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 pomila use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does pomila run in Zeal Terminal?
- Yes
- It compiles in 24 ms and runs 1,000 bars in 68 ms, in the browser.
BTCUSDT · 1D · default settings
- Up Trend
- UpTrend Begins
- Down Trend
- DownTrend Begins
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −54.63%
- −$54,630.60
- Buy and hold
- +102.5%
- same period
- Closed trades
- 25
- 7 won · 18 lost
- Profitable
- 28.0%
- of closed trades
- Profit factor
- 0.61
- gross profit ÷ gross loss
- Max drawdown
- 86.58%
- −$86,582.10
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 47, 50. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 25
transp = on line 25, 26, 29, 30. 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 sma → ta.sma, atr → ta.atr, max → math.max, min → math.min, barssince → ta.barssince.
- 2 strategy calls use the when = argument (line 47, 50). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 25 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 5: input(type = input.integer) → input.int()
- Line 7: input(type = input.float) → input.float()
- Line 8: input(type = input.bool) → input.bool()
- Line 9: input(type = input.bool) → input.bool()
- Line 10: input(type = input.bool) → input.bool()
12 more edits
- Line 11: input(type = input.bool) → input.bool()
- Line 12: sma → ta.sma
- Line 12: tr → ta.tr
- Line 13: atr → ta.atr
- Line 16: max → math.max
- Line 19: min → math.min
- Line 25: transp = 0 → color.new(color.green, 0)
- Line 26: transp = 0 → color.new(color.green, 0)
- Line 29: transp = 0 → color.new(color.red, 0)
- Line 30: transp = 0 → color.new(color.red, 0)
- Line 51: barssince → ta.barssince
- Line 52: barssince → ta.barssince
⋯// © KivancOzbilgic-//@version=4+//@version=5strategy("pomila", overlay=true)-Periods = input(title="ATR Period", type=input.integer, defval=10)+Periods = input.int(title="ATR Period", defval=10)src = input(hl2, title="Source")-Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)+Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0)-changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)+changeATR= input.bool(title="Change ATR Calculation Method ?", defval=true)-showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=false)+showsignals = input.bool(title="Show Buy/Sell Signals ?", defval=false)-highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)+highlighting = input.bool(title="Highlighter On/Off ?", defval=true)-barcoloring = input(title="Bar Coloring On/Off ?", type=input.bool, defval=true)+barcoloring = input.bool(title="Bar Coloring On/Off ?", defval=true)-atr2 = sma(tr, Periods)+atr2 = ta.sma(ta.tr, Periods)-atr= changeATR ? atr(Periods) : atr2+atr= changeATR ? ta.atr(Periods) : atr2up=src-(Multiplier*atr)up1 = nz(up[1],up)-up := close[1] > up1 ? max(up,up1) : up+up := close[1] > up1 ? math.max(up,up1) : updn=src+(Multiplier*atr)dn1 = nz(dn[1], dn)-dn := close[1] < dn1 ? min(dn, dn1) : dn+dn := close[1] < dn1 ? math.min(dn, dn1) : dntrend = 1⋯buySignal = trend == 1 and trend[1] == -1-plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)+plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))-plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)+plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)sellSignal = trend == -1 and trend[1] == 1-plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)+plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))-plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)+plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)⋯ strategy.entry("SELL", strategy.short, when = window())-buy1= barssince(buySignal)+buy1= ta.barssince(buySignal)-sell1 = barssince(sellSignal)+sell1 = ta.barssince(sellSignal)color1 = buy1[1] < sell1[1] ? color.green : buy1[1] > sell1[1] ? color.red : na⋯Same 25 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.source()
- Line 36: input() → input.int()
- Line 37: input() → input.int()
- Line 38: input() → input.int()
- Line 39: input() → input.int()
- Line 40: input() → input.int()
3 more edits
- Line 41: input() → input.int()
- Line 47: when = window() → if block
- Line 50: when = window() → if block
⋯Periods = input.int(title="ATR Period", defval=10)-src = input(hl2, title="Source")+src = input.source(hl2, title="Source")Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0)⋯fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)-FromMonth = input(defval = 9, title = "From Month", minval = 1, maxval = 12)+FromMonth = input.int(defval = 9, title = "From Month", minval = 1, maxval = 12)-FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+FromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-FromYear = input(defval = 2018, title = "From Year", minval = 999)+FromYear = input.int(defval = 2018, title = "From Year", minval = 999)-ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)+ToMonth = input.int(defval = 1, title = "To Month", minval = 1, maxval = 12)-ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)+ToDay = input.int(defval = 1, title = "To Day", minval = 1, maxval = 31)-ToYear = input(defval = 9999, title = "To Year", minval = 999)+ToYear = input.int(defval = 9999, title = "To Year", minval = 999)start = timestamp(FromYear, FromMonth, FromDay, 00, 00) ⋯if (longCondition)- strategy.entry("BUY", strategy.long, when = window())+ if window()+ strategy.entry("BUY", strategy.long)shortCondition = sellSignalif (shortCondition)- strategy.entry("SELL", strategy.short, when = window())+ if window()+ strategy.entry("SELL", strategy.short)buy1= ta.barssince(buySignal)⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L31:C56: 'linewidth' must be at least 1 in Pine Script v6. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © KivancOzbilgic-//@version=5+//@version=6strategy("pomila", 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 |
|---|---|---|---|
| ATR Period | 10 | int (written input.integer) | atr2 atr |
| Source | hl2 | source | up dn |
| ATR Multiplier | 3.0 | float · step 0.1 | up dn |
| Change ATR Calculation Method ? | true | bool | atr |
| Show Buy/Sell Signals ? | false | bool | Buy Sell |
| Highlighter On/Off ? | true | bool | longFillColor shortFillColor |
| Bar Coloring On/Off ? | true | bool | barcolor |
| From Month | 9 | int · min 1 · max 12 | start |
| From Day | 1 | int · min 1 · max 31 | start |
| From Year | 2018 | int · min 999 | start |
| To Month | 1 | int · min 1 · max 12 | finish |
| To Day | 1 | int · min 1 · max 31 | finish |
| To Year | 9999 | int · min 999 | finish |
What it calculates
- SMA (
sma,ta.smain v5)tr, ATR Period (10)atr2 · line 12 - ATR (
atr,ta.atrin v5)ATR Period (10)atr · line 13 - Barssince (
barssince,ta.barssincein v5)buySignalbuy1 · line 51 - Barssince (
barssince,ta.barssincein v5)sellSignalsell1 · line 52
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 BUY long | window() | On | 47 |
| Open SELL short | window() | On | 50 |
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 | −54.6% | +102.5% | 25 | 28% | 0.61 | 86.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +5.5% | +5.5% | 23 | 39% | 1.19 | 13.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.0% | +9.8% | 22 | 41% | 1.00 | 2.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.1% | +8.4% | 23 | 30% | 1.08 | 0.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.1% | +16.7% | 22 | 41% | 1.42 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 23 | 35% | 1.30 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.6% | +148.3% | 26 | 31% | 0.54 | 1.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 23 | 35% | 1.03 | 0.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 | 6 | 17% | −$47,537.00 |
| Sideways market | 13 | 31% | $12,702.10 |
| Falling market | 6 | 33% | −$19,795.70 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
86.3%
The 95th percentile of the worst drawdown when the same 25 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 61.5% to 86.3%; the tick is what actually happened, 75.8%. Order luck alone moves it this much.
All 25 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 20 Mar 2024 61,937.40 | 21 May 2024 71,446.60 | 62 | −$9,509.21 |
| long | 21 May 2024 71,446.60 | 22 Jun 2024 64,143.60 | 32 | −$7,303.06 |
| short | 22 Jun 2024 64,143.60 | 16 Jul 2024 64,724.10 | 24 | −$580.50 |
| long | 16 Jul 2024 64,724.10 | 4 Aug 2024 60,698.00 | 19 | −$4,026.07 |
| short | 4 Aug 2024 60,698.00 | 24 Aug 2024 64,037.20 | 20 | −$3,339.25 |
| long | 24 Aug 2024 64,037.20 | 6 Sep 2024 56,180.00 | 13 | −$7,857.24 |
| short | 6 Sep 2024 56,180.00 | 20 Sep 2024 62,948.00 | 14 | −$6,768.00 |
| long | 20 Sep 2024 62,948.00 | 24 Dec 2024 94,881.50 | 95 | $31,933.50 |
| short | 24 Dec 2024 94,881.50 | 18 Jan 2025 104,077.00 | 25 | −$9,196.00 |
| long | 18 Jan 2025 104,077.00 | 25 Feb 2025 91,552.90 | 38 | −$12,524.60 |
| short | 25 Feb 2025 91,552.90 | 3 Mar 2025 94,270.00 | 6 | −$2,717.11 |
| long | 3 Mar 2025 94,270.00 | 11 Mar 2025 78,595.90 | 8 | −$15,674.10 |
| short | 11 Mar 2025 78,595.90 | 23 Apr 2025 93,443.00 | 43 | −$14,847.10 |
| long | 23 Apr 2025 93,443.00 | 23 Jun 2025 100,964.00 | 61 | $7,520.88 |
| short | 23 Jun 2025 100,964.00 | 10 Jul 2025 111,234.00 | 17 | −$10,270.10 |
| long | 10 Jul 2025 111,234.00 | 22 Aug 2025 112,500.00 | 43 | $1,266.00 |
| short | 22 Aug 2025 112,500.00 | 2 Oct 2025 118,595.00 | 41 | −$6,094.99 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$5,820.50 |
| short | 11 Oct 2025 112,774.00 | 14 Jan 2026 95,414.00 | 95 | $17,360.50 |
| long | 14 Jan 2026 95,414.00 | 21 Jan 2026 88,427.70 | 7 | −$6,986.33 |
| short | 21 Jan 2026 88,427.70 | 5 Mar 2026 72,666.80 | 43 | $15,760.90 |
| long | 5 Mar 2026 72,666.80 | 30 Mar 2026 66,010.90 | 25 | −$6,655.84 |
| short | 30 Mar 2026 66,010.90 | 14 Apr 2026 74,418.00 | 15 | −$8,407.07 |
| long | 14 Apr 2026 74,418.00 | 23 May 2026 75,539.50 | 39 | $1,121.50 |
| short | 23 May 2026 75,539.50 | 22 Jul 2026 66,556.10 | 60 | $8,983.35 |
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 |
|---|---|---|---|---|---|
| pomila this page | — | v4 strategy | −54.6% | 25 | 86.6% |
| Trenbolone Strategy by LeSif | sma atr barssince | v4 strategy | −54.6% | 25 | 86.6% |
| Dazzling Bolts by OrcChieftain | sma atr barssince | v4 strategy | +8.5% | 14 | 13.0% |
| I11L - Better Buy Low Volatility or High Volatility- by I11L | atr sma | v5 strategy | +19.2% | 83 | 37.4% |
| Last Price minus Open Price Intraday Volume by avsr90 | barssince sma | v5 strategy | No trades on this market | ||
| Vortex Cross w-MA Confirmation by DraftVenture | atr sma | v5 strategy | +2.4% | 52 | 4.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 24 ms | Yes 1,000 bars in 68 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/// © KivancOzbilgic//@version=4strategy("pomila", overlay=true)Periods = input(title="ATR Period", type=input.integer, defval=10)src = input(hl2, title="Source")Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=false)highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)barcoloring = input(title="Bar Coloring On/Off ?", type=input.bool, defval=true)atr2 = sma(tr, Periods)atr= changeATR ? atr(Periods) : atr2up=src-(Multiplier*atr)up1 = nz(up[1],up)up := close[1] > up1 ? max(up,up1) : updn=src+(Multiplier*atr)dn1 = nz(dn[1], dn)dn := close[1] < dn1 ? min(dn, dn1) : dntrend = 1trend := nz(trend[1], trend)trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trendupPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)buySignal = trend == 1 and trend[1] == -1plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)sellSignal = trend == -1 and trend[1] == 1plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.whiteshortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.whitefill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)FromMonth = input(defval = 9, title = "From Month", minval = 1, maxval = 12)FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)FromYear = input(defval = 2018, title = "From Year", minval = 999)ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)ToYear = input(defval = 9999, title = "To Year", minval = 999)start = timestamp(FromYear, FromMonth, FromDay, 00, 00) finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) window() => time >= start and time <= finish ? true : falselongCondition = buySignalif (longCondition) strategy.entry("BUY", strategy.long, when = window())shortCondition = sellSignalif (shortCondition) strategy.entry("SELL", strategy.short, when = window())buy1= barssince(buySignal)sell1 = barssince(sellSignal)color1 = buy1[1] < sell1[1] ? color.green : buy1[1] > sell1[1] ? color.red : nabarcolor(barcoloring ? color1 : na)