Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Profit Maximizer Strategy

A Pine Script v4 strategy built on SMA (tr, 10), ATR (10) and EMA (zxEMAData, 12). 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. 29 settings; defaults include Source hl2, ATR Length 10 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 Profit Maximizer Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did Profit Maximizer Strategy do on BTCUSDT 1D with default settings?
−3.62%
From 26 Jan 2024 to 21 Oct 2026, over 5 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Profit Maximizer Strategy 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.
What alerts does Profit Maximizer Strategy have?
6
Cross Alert; Crossover Alarm; Crossunder Alarm; Price Cross Alert; and more.
Does Profit Maximizer Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 214, 216.

BTCUSDT · 1D · default settings

  • Moving Avg Line
  • PMax
  • Buy
  • Sell
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (29)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$96,378$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 212, 213) so the engine trades the way the script says.
Net profit
−3.62%
−$3,621.74
Buy and hold
+102.5%
same period
Closed trades
5
0 won · 5 lost
Profitable
0.0%
of closed trades
Profit factor
0.00
gross profit ÷ gross loss
Max drawdown
3.62%
−$3,621.74

One run with the author's default settings, $100,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

    1 setting does nothing

    “Show Price/Pmax Crossing Signals?” is declared but never read.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    7 settings have no label

    In the settings dialog start (line 103), increment (line 104), maximum (line 105), CCI (line 171), ATR (line 172), sma1length (line 199), sma2length (line 200) 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.

  • Note

    Uses an argument v6 removed

    when = on line 212, 213. The upgraded version below moves each call inside an if block.

  • Note

    Uses iff(), which v5 removed line 202

    iff() on line 202. v5 writes it as the ternary c ? a : b.

  • Note

    Uses transp =, which v5 removed line 76

    transp = on line 76, 84, 86. 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, sum → math.sum, abs → math.abs, round → math.round, ema → ta.ema, linreg → ta.linreg, wma → ta.wma, ceil → math.ceil, floor → math.floor, max → math.max, min → math.min, cross → ta.cross, crossover → ta.crossover, crossunder → ta.crossunder, cci → ta.cci.
  • 2 strategy calls use the when = argument (line 212, 213). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 5 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 1: //@version=4 → //@version=5
  • Line 7: input(type = input.integer) → input.int()
  • Line 8: input(type = input.float) → input.float()
  • Line 11: input(type = input.bool) → input.bool()
  • Line 12: input(type = input.bool) → input.bool()
  • Line 13: input(type = input.bool) → input.bool()
69 more edits
  • Line 14: input(type = input.bool) → input.bool()
  • Line 15: input(type = input.bool) → input.bool()
  • Line 16: sma → ta.sma
  • Line 16: tr → ta.tr
  • Line 17: atr → ta.atr
  • Line 21: sum → math.sum
  • Line 22: sum → math.sum
  • Line 25: abs → math.abs
  • Line 25: abs → math.abs
  • Line 29: round → math.round
  • Line 31: ema → ta.ema
  • Line 32: linreg → ta.linreg
  • Line 33: linreg → ta.linreg
  • Line 35: linreg → ta.linreg
  • Line 39: sma → ta.sma
  • Line 42: ema → ta.ema
  • Line 45: wma → ta.wma
  • Line 48: sma → ta.sma
  • Line 48: sma → ta.sma
  • Line 48: ceil → math.ceil
  • Line 48: floor → math.floor
  • Line 67: max → math.max
  • Line 70: min → math.min
  • Line 76: transp = 0 → color.new(color.red, 0)
  • Line 77: cross → ta.cross
  • Line 78: crossover → ta.crossover
  • Line 79: crossunder → ta.crossunder
  • Line 80: cross → ta.cross
  • Line 81: crossover → ta.crossover
  • Line 82: crossunder → ta.crossunder
  • Line 83: crossover → ta.crossover
  • Line 84: transp = 0 → color.new(color.green, 0)
  • Line 85: crossunder → ta.crossunder
  • Line 86: transp = 0 → color.new(color.red, 0)
  • Line 87: crossover → ta.crossover
  • Line 89: crossunder → ta.crossunder
  • Line 96: input(type = input.integer) → input.int()
  • Line 97: input(type = input.integer) → input.int()
  • Line 98: input(type = input.source) → input.source()
  • Line 99: input(type = input.integer) → input.int()
  • Line 100: input(type = input.bool) → input.bool()
  • Line 101: input(type = input.bool) → input.bool()
  • Line 137: max → math.max
  • Line 144: min → math.min
  • Line 151: min → math.min
  • Line 155: min → math.min
  • Line 157: min → math.min
  • Line 159: min → math.min
  • Line 161: max → math.max
  • Line 163: max → math.max
  • Line 166: sma → ta.sma
  • Line 166: ema → ta.ema
  • Line 167: sma → ta.sma
  • Line 167: ema → ta.ema
  • Line 169: sma → ta.sma
  • Line 169: ema → ta.ema
  • Line 175: cci → ta.cci
  • Line 177: sma → ta.sma
  • Line 177: tr → ta.tr
  • Line 178: sma → ta.sma
  • Line 178: tr → ta.tr
  • Line 201: input(type = input.bool) → input.bool()
  • Line 202: iff(c, a, b) → (c ? a : b)
  • Line 202: sma → ta.sma
  • Line 202: sma → ta.sma
  • Line 202: sma → ta.sma
  • Line 202: sma → ta.sma
  • Line 212: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
  • Line 213: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
-//@version=4+//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯src = input(hl2, title="Source")-Periods = input(title="ATR Length", type=input.integer, defval=10)+Periods = input.int(title="ATR Length", defval=10)-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)mav = input(title="Moving Average Type", defval="VAR", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])length =input(12, "Moving Average Length", minval=1)-changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=false)+changeATR= input.bool(title="Change ATR Calculation Method ?", defval=false)-showsupport = input(title="Show Moving Average?", type=input.bool, defval=true)+showsupport = input.bool(title="Show Moving Average?", defval=true)-showsignalsk = input(title="Show Crossing Signals?", type=input.bool, defval=true)+showsignalsk = input.bool(title="Show Crossing Signals?", defval=true)-showsignalsc = input(title="Show Price/Pmax Crossing Signals?", type=input.bool, defval=false)+showsignalsc = input.bool(title="Show Price/Pmax Crossing Signals?", defval=false)-highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)+highlighting = input.bool(title="Highlighter On/Off ?", defval=true)-atr2 = sma(tr, Periods)+atr2 = ta.sma(ta.tr, Periods)-atr= changeATR ? atr(Periods) : atr2+atr= changeATR ? ta.atr(Periods) : atr2valpha=2/(length+1)⋯vdd1=src<src[1] ? src[1]-src : 0-vUD=sum(vud1,9)+vUD=math.sum(vud1,9)-vDD=sum(vdd1,9)+vDD=math.sum(vdd1,9)vCMO=nz((vUD-vDD)/(vUD+vDD))VAR=0.0-VAR:=nz(valpha*abs(vCMO)*src)+(1-valpha*abs(vCMO))*nz(VAR[1])+VAR:=nz(valpha*math.abs(vCMO)*src)+(1-valpha*math.abs(vCMO))*nz(VAR[1])wwalpha = 1/ length⋯WWMA := wwalpha*src + (1-wwalpha)*nz(WWMA[1])-zxLag = length/2==round(length/2) ? length/2 : (length - 1) / 2+zxLag = length/2==math.round(length/2) ? length/2 : (length - 1) / 2zxEMAData = (src + (src - src[zxLag]))-ZLEMA = ema(zxEMAData, length)+ZLEMA = ta.ema(zxEMAData, length)-lrc = linreg(src, length, 0)+lrc = ta.linreg(src, length, 0)-lrc1 = linreg(src,length,1)+lrc1 = ta.linreg(src,length,1)lrs = (lrc-lrc1)-TSF = linreg(src, length, 0)+lrs+TSF = ta.linreg(src, length, 0)+lrsgetMA(src, length) =>⋯    if mav == "SMA"-        ma := sma(src, length)+        ma := ta.sma(src, length)        ma    if mav == "EMA"-        ma := ema(src, length)+        ma := ta.ema(src, length)        ma    if mav == "WMA"-        ma := wma(src, length)+        ma := ta.wma(src, length)        ma    if mav == "TMA"-        ma := sma(sma(src, ceil(length / 2)), floor(length / 2) + 1)+        ma := ta.sma(ta.sma(src, math.ceil(length / 2)), math.floor(length / 2) + 1)        ma⋯longStopPrev = nz(longStop[1], longStop)-longStop := MAvg > longStopPrev ? max(longStop, longStopPrev) : longStop+longStop := MAvg > longStopPrev ? math.max(longStop, longStopPrev) : longStopshortStop = MAvg + Multiplier*atrshortStopPrev = nz(shortStop[1], shortStop)-shortStop := MAvg < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop+shortStop := MAvg < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStopdir = 1⋯plot(showsupport ? MAvg : na, color=#0585E1, linewidth=2, title="Moving Avg Line")-pALL=plot(PMax, color=color.red, linewidth=2, title="PMax", transp=0)+pALL=plot(PMax, color=color.new(color.red, 0), linewidth=2, title="PMax")-alertcondition(cross(MAvg, PMax), title="Cross Alert", message="PMax - Moving Avg Crossing!")+alertcondition(ta.cross(MAvg, PMax), title="Cross Alert", message="PMax - Moving Avg Crossing!")-alertcondition(crossover(MAvg, PMax), title="Crossover Alarm", message="Moving Avg BUY SIGNAL!")+alertcondition(ta.crossover(MAvg, PMax), title="Crossover Alarm", message="Moving Avg BUY SIGNAL!")-alertcondition(crossunder(MAvg, PMax), title="Crossunder Alarm", message="Moving Avg SELL SIGNAL!")+alertcondition(ta.crossunder(MAvg, PMax), title="Crossunder Alarm", message="Moving Avg SELL SIGNAL!")-alertcondition(cross(src, PMax), title="Price Cross Alert", message="PMax - Price Crossing!")+alertcondition(ta.cross(src, PMax), title="Price Cross Alert", message="PMax - Price Crossing!")-alertcondition(crossover(src, PMax), title="Price Crossover Alarm", message="PRICE OVER PMax - BUY SIGNAL!")+alertcondition(ta.crossover(src, PMax), title="Price Crossover Alarm", message="PRICE OVER PMax - BUY SIGNAL!")-alertcondition(crossunder(src, PMax), title="Price Crossunder Alarm", message="PRICE UNDER PMax - SELL SIGNAL!")+alertcondition(ta.crossunder(src, PMax), title="Price Crossunder Alarm", message="PRICE UNDER PMax - SELL SIGNAL!")-buySignalk = crossover(MAvg, PMax)+buySignalk = ta.crossover(MAvg, PMax)-plotshape(buySignalk and showsignalsk ? PMax*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)+plotshape(buySignalk and showsignalsk ? PMax*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)-sellSignallk = crossunder(MAvg, PMax)+sellSignallk = ta.crossunder(MAvg, PMax)-plotshape(sellSignallk and showsignalsk ? PMax*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)+plotshape(sellSignallk and showsignalsk ? PMax*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)-buySignalc = crossover(src, PMax)+buySignalc = ta.crossover(src, PMax)// plotshape(buySignalc and showsignalsc ? PMax*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=#0F18BF, textcolor=color.white, transp=0)-sellSignallc = crossunder(src, PMax)+sellSignallc = ta.crossunder(src, PMax)// plotshape(sellSignallc and showsignalsc ? PMax*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=#0F18BF, textcolor=color.white, transp=0)⋯fill(mPlot, pALL, title="DownTrend Highligter", color=shortFillColor)-fast_length = input(title="Fast Length", type=input.integer, defval=12)+fast_length = input.int(title="Fast Length", defval=12)-slow_length = input(title="Slow Length", type=input.integer, defval=26)+slow_length = input.int(title="Slow Length", defval=26)-srcc = input(title="Source", type=input.source, defval=close)+srcc = input.source(title="Source", defval=close)-signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)+signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)-sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=true)+sma_source = input.bool(title="Simple MA(Oscillator)", defval=true)-sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)+sma_signal = input.bool(title="Simple MA(Signal Line)", defval=false)//sar⋯            uptrend := false-            SAR := max(EP, high)+            SAR := math.max(EP, high)            EP := low⋯            uptrend := true-            SAR := min(EP, low)+            SAR := math.min(EP, low)            EP := high⋯                EP := high-                AF := min(AF + increment, maximum)+                AF := math.min(AF + increment, maximum)        else⋯                EP := low-                AF := min(AF + increment, maximum)+                AF := math.min(AF + increment, maximum)    if uptrend-        SAR := min(SAR, low[1])+        SAR := math.min(SAR, low[1])        if bar_index > 1-            SAR := min(SAR, low[2])+            SAR := math.min(SAR, low[2])    else-        SAR := max(SAR, high[1])+        SAR := math.max(SAR, high[1])        if bar_index > 1-            SAR := max(SAR, high[2])+            SAR := math.max(SAR, high[2])    nextBarSAR := SAR + AF * (EP - SAR)// Calculating-fast_ma = sma_source ? sma(srcc, fast_length) : ema(srcc, fast_length)+fast_ma = sma_source ? ta.sma(srcc, fast_length) : ta.ema(srcc, fast_length)-slow_ma = sma_source ? sma(srcc, slow_length) : ema(srcc, slow_length)+slow_ma = sma_source ? ta.sma(srcc, slow_length) : ta.ema(srcc, slow_length)macd = fast_ma - slow_ma-signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)+signal = sma_signal ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)hist = macd - signal⋯original=input(true,title='original coloring')-thisCCI = cci(close, CCI)+thisCCI = ta.cci(close, CCI)lastCCI = nz(thisCCI[1])-bufferDn= high + Multiplierc * sma(tr,ATR)+bufferDn= high + Multiplierc * ta.sma(ta.tr,ATR)-bufferUp= low - Multiplierc * sma(tr,ATR)+bufferUp= low - Multiplierc * ta.sma(ta.tr,ATR)if (thisCCI >= 0 and lastCCI < 0) ⋯sma2length = input(35)-UsePercent = input(title="Show Dif as percent of current Candle", type=input.bool, defval=true)+UsePercent = input.bool(title="Show Dif as percent of current Candle", defval=true)-smadif=iff(UsePercent,(sma(srce, sma1length) - sma(srce, sma2length)) / srce * 100, sma(srce, sma1length) - sma(srce, sma2length))+smadif=(UsePercent ? (ta.sma(srce, sma1length) - ta.sma(srce, sma2length)) / srce * 100 : ta.sma(srce, sma1length) - ta.sma(srce, sma2length))col=smadif <= 0 ? color.red : color.green⋯sl=input(0.01, title="sl")-strategy.entry("long",1,when=longC)+strategy.entry("long",strategy.long,when=longC)-strategy.entry("short",0,when=shortC)+strategy.entry("short",strategy.short,when=shortC)strategy.exit("x_long", "long" ,loss = close * sl / syminfo.mintick, profit = close * tp / syminfo.mintick , alert_message = "closelong")⋯

Clean v5

VerifiedDownload the v5 script

Same 5 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 6: input() → input.source()
  • Line 9: input() → input.string()
  • Line 10: input() → input.int()
  • Line 103: input() → input.float()
  • Line 104: input() → input.float()
  • Line 105: input() → input.float()
11 more edits
  • Line 171: input() → input.int()
  • Line 172: input() → input.int()
  • Line 173: input() → input.int()
  • Line 174: input() → input.bool()
  • Line 198: input() → input.source()
  • Line 199: input() → input.int()
  • Line 200: input() → input.int()
  • Line 210: input() → input.float()
  • Line 211: input() → input.float()
  • Line 212: when = longC → if block
  • Line 213: when = shortC → if block
⋯strategy("Profit Maximizer Strategy","PMax strat", overlay=true)-src = input(hl2, title="Source")+src = input.source(hl2, title="Source")Periods = input.int(title="ATR Length", defval=10)Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0)-mav = input(title="Moving Average Type", defval="VAR", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])+mav = input.string(title="Moving Average Type", defval="VAR", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])-length =input(12, "Moving Average Length", minval=1)+length =input.int(12, "Moving Average Length", minval=1)changeATR= input.bool(title="Change ATR Calculation Method ?", defval=false)⋯//sar-start = input(0.02)+start = input.float(0.02)-increment = input(0.03)+increment = input.float(0.03)-maximum = input(0.3)+maximum = input.float(0.3)var bool uptrend = na⋯hist = macd - signal-CCI = input(20)+CCI = input.int(20)-ATR = input(5)+ATR = input.int(5)-Multiplierc=input(1,title='ATR Multiplier')+Multiplierc=input.int(1,title='ATR Multiplier')-original=input(true,title='original coloring')+original=input.bool(true,title='original coloring')thisCCI = ta.cci(close, CCI)⋯//elliot wave-srce = input(close, title="source")+srce = input.source(close, title="source")-sma1length = input(5)+sma1length = input.int(5)-sma2length = input(35)+sma2length = input.int(35)UsePercent = input.bool(title="Show Dif as percent of current Candle", defval=true)⋯//shortC = low < low[1] and low[1] < low[2] and low[2] < low[3] and low[3] < low[4] and close[4] < low[5]-tp=input(0.35, title="tp")+tp=input.float(0.35, title="tp")-sl=input(0.01, title="sl")+sl=input.float(0.01, title="sl")-strategy.entry("long",strategy.long,when=longC)+if longC+    strategy.entry("long",strategy.long)-strategy.entry("short",strategy.short,when=shortC)+if shortC+    strategy.entry("short",strategy.short)strategy.exit("x_long", "long" ,loss = close * sl / syminfo.mintick, profit = close * tp / syminfo.mintick , alert_message = "closelong")⋯

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L91: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.

-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Sourcehl2sourcevud1 vdd1 VAR WWMA zxEMAData lrc lrc1 TSF ma MAvg buySignalc sellSignallc Price Cross Alert Price Crossover Alarm Price Crossunder Alarm
ATR Length10int (written input.integer)atr2 atr
ATR Multiplier3.0float · step 0.1longStop shortStop
Moving Average TypeVARstring · options ["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"]line 38 line 41 line 44 line 47 line 50 line 53 line 56 line 59
Moving Average Length12int · min 1valpha wwalpha zxLag ZLEMA lrc lrc1 TSF ma MAvg
Change ATR Calculation Method ?falseboolatr
Show Moving Average?trueboolMoving Avg Line
Show Crossing Signals?trueboolBuy Sell
Show Price/Pmax Crossing Signals?falseboolunused
Highlighter On/Off ?trueboollongFillColor shortFillColor
Fast Length12int (written input.integer)fast_ma
Slow Length26int (written input.integer)slow_ma
Sourceclosesourcefast_ma slow_ma
Signal Smoothing9int (written input.integer) · min 1 · max 50signal
Simple MA(Oscillator)trueboolfast_ma slow_ma
Simple MA(Signal Line)falseboolsignal
Start (no label in the script)0.02floatSAR AF
Increment (no label in the script)0.03floatAF
Maximum (no label in the script)0.3floatAF
CCI (no label in the script)20intthisCCI
ATR (no label in the script)5intbufferDn bufferUp
ATR Multiplier1intbufferDn bufferUp
original coloringtrueboolswap4
sourceclosesourcesmadif
Sma1length (no label in the script)5intsmadif
Sma2length (no label in the script)35intsmadif
Show Dif as percent of current Candletrueboolsmadif
tp0.35floatexit x_long exit x_short
sl0.01floatexit x_long exit x_short

What it calculates

  • SMA (sma, ta.sma in v5)tr, ATR Length (10)atr2 · line 16
  • ATR (atr, ta.atr in v5)ATR Length (10)atr · line 17
  • EMA (ema, ta.ema in v5)zxEMAData, Moving Average Length (12)ZLEMA · line 31
  • Linreg (linreg, ta.linreg in v5)Source (hl2), Moving Average Length (12), 0lrc · line 32
  • Linreg (linreg, ta.linreg in v5)Source (hl2), Moving Average Length (12), 1lrc1 · line 33
  • Linreg (linreg, ta.linreg in v5)Source (hl2), Moving Average Length (12), 0TSF · line 35
  • SMA / EMA / WMA (sma, ta.sma in v5)Source (hl2), Moving Average Length (12)ma · line 39
  • Crossover (crossover, ta.crossover in v5)MAvg, PMaxbuySignalk · line 83
  • Crossunder (crossunder, ta.crossunder in v5)MAvg, PMaxsellSignallk · line 85
  • Crossover (crossover, ta.crossover in v5)Source (hl2), PMaxbuySignalc · line 87
  • Crossunder (crossunder, ta.crossunder in v5)Source (hl2), PMaxsellSignallc · line 89
  • SMA / EMA (sma, ta.sma in v5)Source (close), Fast Length (12)fast_ma · line 166
  • SMA / EMA (sma, ta.sma in v5)Source (close), Slow Length (26)slow_ma · line 167
  • SMA / EMA (sma, ta.sma in v5)macd, Signal Smoothing (9)signal · line 169
  • CCI (cci, ta.cci in v5)close, CCI (20)thisCCI · line 175
  • SMA (sma, ta.sma in v5)tr, ATR (5)bufferDn · line 177
  • SMA (sma, ta.sma in v5)tr, ATR (5)bufferUp · line 178
  • SMA (sma, ta.sma in v5)source (close), Sma1length (5)smadif · line 202

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.

The script has 86 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open long longlongCOn212
Open short shortshortCOn213
Exit x_long stop and limitevery barOn214
Exit x_short stop and limitevery barOn216

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
Cross AlertalertconditionPMax - Moving Avg Crossing!77
Crossover AlarmalertconditionMoving Avg BUY SIGNAL!78
Crossunder AlarmalertconditionMoving Avg SELL SIGNAL!79
Price Cross AlertalertconditionPMax - Price Crossing!80
Price Crossover AlarmalertconditionPRICE OVER PMax - BUY SIGNAL!81
Price Crossunder AlarmalertconditionPRICE UNDER PMax - SELL SIGNAL!82

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

2/2trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−3.6%+102.5%50%0.003.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−5.0%+5.5%70%0.005.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.1%+9.8%40%0.000.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.1%+8.4%40%0.000.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%50%0.000.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%70%0.000.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%40%0.000.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%20%0.000.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 barsTradesWonP&L
Rising market0—$0.00
Sideways market40%−$3,055.45
Falling market10%−$566.29

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

3.6%

The 95th percentile of the worst drawdown when the same 5 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 3.6% to 3.6%; the tick is what actually happened, 3.6%. Order luck alone moves it this much.

0%4%
All 5 trades
SideEntryExitBarsP&L
short5 Jul 2024 57,050.006 Jul 2024 57,616.301−$566.29
long20 Oct 2024 68,378.0021 Oct 2024 67,687.701−$690.32
long2 May 2025 96,489.904 May 2025 95,531.302−$958.57
short5 Jun 2026 63,886.0013 Jun 2026 64,521.808−$635.81
long23 Aug 2026 77,074.9023 Aug 2026 76,304.200−$770.75

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
Profit Maximizer Strategy this page—v4 strategy−3.6%53.6%
Profit Maximizer PMax Strategy - Long-Short by melihtunasma atr ema linregv4 strategy+16.2%427.8%
Strategy - Profit Maximizer by PMax by MartinCresposma atr ema linregv4 strategyNo trades on this market
Open Close Cross Strategy plus Explorer by roses27sma ema wma linreg atrv4 strategydoes not run in Zeal Terminal
Y-Profit Maximizer Strategy with Exit Points by Enes_Yetkin_ema sma atr linregv4 strategy−1.9%1330.4%
Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN] by myncryptosma ema wma atrv5 strategy−47.2%448.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 58 msWith a workaround 1,000 bars in 132 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 212, 213) 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. 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.

//@version=4// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0///developer original: @KivancOzbilgic//author: @SoftKill21strategy("Profit Maximizer Strategy","PMax strat", overlay=true)src = input(hl2, title="Source")Periods = input(title="ATR Length", type=input.integer, defval=10)Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)mav = input(title="Moving Average Type", defval="VAR", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])length =input(12, "Moving Average Length", minval=1)changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=false)showsupport = input(title="Show Moving Average?", type=input.bool, defval=true)showsignalsk = input(title="Show Crossing Signals?", type=input.bool, defval=true)showsignalsc = input(title="Show Price/Pmax Crossing Signals?", type=input.bool, defval=false)highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)atr2 = sma(tr, Periods)atr= changeATR ? atr(Periods) : atr2valpha=2/(length+1)vud1=src>src[1] ? src-src[1] : 0vdd1=src<src[1] ? src[1]-src : 0vUD=sum(vud1,9)vDD=sum(vdd1,9)vCMO=nz((vUD-vDD)/(vUD+vDD))VAR=0.0VAR:=nz(valpha*abs(vCMO)*src)+(1-valpha*abs(vCMO))*nz(VAR[1])wwalpha = 1/ lengthWWMA = 0.0WWMA := wwalpha*src + (1-wwalpha)*nz(WWMA[1])zxLag = length/2==round(length/2) ? length/2 : (length - 1) / 2zxEMAData = (src + (src - src[zxLag]))ZLEMA = ema(zxEMAData, length)lrc = linreg(src, length, 0)lrc1 = linreg(src,length,1)lrs = (lrc-lrc1)TSF = linreg(src, length, 0)+lrsgetMA(src, length) =>    ma = 0.0    if mav == "SMA"        ma := sma(src, length)        ma    if mav == "EMA"        ma := ema(src, length)        ma    if mav == "WMA"        ma := wma(src, length)        ma    if mav == "TMA"        ma := sma(sma(src, ceil(length / 2)), floor(length / 2) + 1)        ma    if mav == "VAR"        ma := VAR        ma    if mav == "WWMA"        ma := WWMA        ma    if mav == "ZLEMA"        ma := ZLEMA        ma    if mav == "TSF"        ma := TSF        ma    ma    MAvg=getMA(src, length)longStop = MAvg - Multiplier*atrlongStopPrev = nz(longStop[1], longStop)longStop := MAvg > longStopPrev ? max(longStop, longStopPrev) : longStopshortStop = MAvg + Multiplier*atrshortStopPrev = nz(shortStop[1], shortStop)shortStop := MAvg < shortStopPrev ? min(shortStop, shortStopPrev) : shortStopdir = 1dir := nz(dir[1], dir)dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dirPMax = dir==1 ? longStop: shortStopplot(showsupport ? MAvg : na, color=#0585E1, linewidth=2, title="Moving Avg Line")pALL=plot(PMax, color=color.red, linewidth=2, title="PMax", transp=0)alertcondition(cross(MAvg, PMax), title="Cross Alert", message="PMax - Moving Avg Crossing!")alertcondition(crossover(MAvg, PMax), title="Crossover Alarm", message="Moving Avg BUY SIGNAL!")alertcondition(crossunder(MAvg, PMax), title="Crossunder Alarm", message="Moving Avg SELL SIGNAL!")alertcondition(cross(src, PMax), title="Price Cross Alert", message="PMax - Price Crossing!")alertcondition(crossover(src, PMax), title="Price Crossover Alarm", message="PRICE OVER PMax - BUY SIGNAL!")alertcondition(crossunder(src, PMax), title="Price Crossunder Alarm", message="PRICE UNDER PMax - SELL SIGNAL!")buySignalk = crossover(MAvg, PMax)plotshape(buySignalk and showsignalsk ? PMax*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)sellSignallk = crossunder(MAvg, PMax)plotshape(sellSignallk and showsignalsk ? PMax*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)buySignalc = crossover(src, PMax)// plotshape(buySignalc and showsignalsc ? PMax*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=#0F18BF, textcolor=color.white, transp=0)sellSignallc = crossunder(src, PMax)// plotshape(sellSignallc and showsignalsc ? PMax*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=#0F18BF, textcolor=color.white, transp=0)mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0,display=display.none)longFillColor = highlighting ? (MAvg>PMax ? color.green : na) : nashortFillColor = highlighting ? (MAvg<PMax ? color.red : na) : nafill(mPlot, pALL, title="UpTrend Highligter", color=longFillColor)fill(mPlot, pALL, title="DownTrend Highligter", color=shortFillColor)fast_length = input(title="Fast Length", type=input.integer, defval=12)slow_length = input(title="Slow Length", type=input.integer, defval=26)srcc = input(title="Source", type=input.source, defval=close)signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=true)sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)//sarstart = input(0.02)increment = input(0.03)maximum = input(0.3)var bool uptrend = navar float EP = navar float SAR = navar float AF = startvar float nextBarSAR = naif bar_index > 0    firstTrendBar = false    SAR := nextBarSAR    if bar_index == 1        float prevSAR = na        float prevEP = na        lowPrev = low[1]        highPrev = high[1]        closeCur = close        closePrev = close[1]        if closeCur > closePrev            uptrend := true            EP := high            prevSAR := lowPrev            prevEP := high        else            uptrend := false            EP := low            prevSAR := highPrev            prevEP := low        firstTrendBar := true        SAR := prevSAR + start * (prevEP - prevSAR)    if uptrend        if SAR > low            firstTrendBar := true            uptrend := false            SAR := max(EP, high)            EP := low            AF := start    else        if SAR < high            firstTrendBar := true            uptrend := true            SAR := min(EP, low)            EP := high            AF := start    if not firstTrendBar        if uptrend            if high > EP                EP := high                AF := min(AF + increment, maximum)        else            if low < EP                EP := low                AF := min(AF + increment, maximum)    if uptrend        SAR := min(SAR, low[1])        if bar_index > 1            SAR := min(SAR, low[2])    else        SAR := max(SAR, high[1])        if bar_index > 1            SAR := max(SAR, high[2])    nextBarSAR := SAR + AF * (EP - SAR)// Calculatingfast_ma = sma_source ? sma(srcc, fast_length) : ema(srcc, fast_length)slow_ma = sma_source ? sma(srcc, slow_length) : ema(srcc, slow_length)macd = fast_ma - slow_masignal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)hist = macd - signalCCI = input(20)ATR = input(5)Multiplierc=input(1,title='ATR Multiplier')original=input(true,title='original coloring')thisCCI = cci(close, CCI)lastCCI = nz(thisCCI[1])bufferDn= high + Multiplierc * sma(tr,ATR)bufferUp= low - Multiplierc * sma(tr,ATR)if (thisCCI >= 0 and lastCCI < 0)     bufferUp := bufferDn[1]if (thisCCI <= 0 and lastCCI > 0)     bufferDn := bufferUp[1]if (thisCCI >= 0)    if (bufferUp < bufferUp[1])        bufferUp := bufferUp[1]else    if (thisCCI <= 0)        if (bufferDn > bufferDn[1])            bufferDn := bufferDn[1]x=0.0x:=thisCCI >= 0 ?bufferUp:thisCCI <= 0 ?bufferDn:x[1]swap=0.0swap:=x>x[1]?1:x<x[1]?-1:swap[1]swap2=swap==1?color.lime:color.redswap3=thisCCI >=0 ?color.lime:color.redswap4=original?swap3:swap2//elliot wavesrce = input(close, title="source")sma1length = input(5)sma2length = input(35)UsePercent = input(title="Show Dif as percent of current Candle", type=input.bool, defval=true)smadif=iff(UsePercent,(sma(srce, sma1length) - sma(srce, sma2length)) / srce * 100, sma(srce, sma1length) - sma(srce, sma2length))col=smadif <= 0 ? color.red : color.green//longC = high > high[1] and high[1] > high[2] and close[2] > high[3] and hist > 0 and uptrend and smadif < 0 and swap4==color.lime // and buySignalklongC = hist > 0 and uptrend and   swap4==color.lime and buySignalkshortC =  hist < 0 and not uptrend  and swap4==color.red and sellSignallk //longC = high > high[1] and high[1] > high[2] and high[2] > high[3] and high[3] > high[4] and close[4] > high[5]//shortC = low < low[1] and low[1] < low[2] and close[2] < low[3] and hist < 0 and not uptrend and  smadif > 0 and swap4==color.red //and sellSignallk//shortC = low < low[1] and low[1] < low[2] and low[2] < low[3] and low[3] < low[4] and close[4] < low[5]tp=input(0.35, title="tp")sl=input(0.01, title="sl")strategy.entry("long",1,when=longC)strategy.entry("short",0,when=shortC)strategy.exit("x_long", "long" ,loss = close * sl / syminfo.mintick, profit = close * tp / syminfo.mintick , alert_message = "closelong")//strategy.entry("short",0, when= loss = close * sl / syminfo.mintick)strategy.exit("x_short", "short" , loss = close * sl / syminfo.mintick, profit  = close * tp / syminfo.mintick,alert_message = "closeshort")//strategy.entry("long",1, when = loss = close * sl / syminfo.mintick)//strategy.entry("long",1,when = buySignalk )//strategy.entry("short",0, when = sellSignallk)