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
- 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
VerifiedSame 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")⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Source | hl2 | source | vud1 vdd1 VAR WWMA zxEMAData lrc lrc1 TSF ma MAvg buySignalc sellSignallc Price Cross Alert Price Crossover Alarm Price Crossunder Alarm |
| ATR Length | 10 | int (written input.integer) | atr2 atr |
| ATR Multiplier | 3.0 | float · step 0.1 | longStop shortStop |
| Moving Average Type | VAR | string · 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 Length | 12 | int · min 1 | valpha wwalpha zxLag ZLEMA lrc lrc1 TSF ma MAvg |
| Change ATR Calculation Method ? | false | bool | atr |
| Show Moving Average? | true | bool | Moving Avg Line |
| Show Crossing Signals? | true | bool | Buy Sell |
| Show Price/Pmax Crossing Signals? | false | bool | unused |
| Highlighter On/Off ? | true | bool | longFillColor shortFillColor |
| Fast Length | 12 | int (written input.integer) | fast_ma |
| Slow Length | 26 | int (written input.integer) | slow_ma |
| Source | close | source | fast_ma slow_ma |
| Signal Smoothing | 9 | int (written input.integer) · min 1 · max 50 | signal |
| Simple MA(Oscillator) | true | bool | fast_ma slow_ma |
| Simple MA(Signal Line) | false | bool | signal |
| Start (no label in the script) | 0.02 | float | SAR AF |
| Increment (no label in the script) | 0.03 | float | AF |
| Maximum (no label in the script) | 0.3 | float | AF |
| CCI (no label in the script) | 20 | int | thisCCI |
| ATR (no label in the script) | 5 | int | bufferDn bufferUp |
| ATR Multiplier | 1 | int | bufferDn bufferUp |
| original coloring | true | bool | swap4 |
| source | close | source | smadif |
| Sma1length (no label in the script) | 5 | int | smadif |
| Sma2length (no label in the script) | 35 | int | smadif |
| Show Dif as percent of current Candle | true | bool | smadif |
| tp | 0.35 | float | exit x_long exit x_short |
| sl | 0.01 | float | exit x_long exit x_short |
What it calculates
- SMA (
sma,ta.smain v5)tr, ATR Length (10)atr2 · line 16 - ATR (
atr,ta.atrin v5)ATR Length (10)atr · line 17 - EMA (
ema,ta.emain v5)zxEMAData, Moving Average Length (12)ZLEMA · line 31 - Linreg (
linreg,ta.linregin v5)Source (hl2), Moving Average Length (12), 0lrc · line 32 - Linreg (
linreg,ta.linregin v5)Source (hl2), Moving Average Length (12), 1lrc1 · line 33 - Linreg (
linreg,ta.linregin v5)Source (hl2), Moving Average Length (12), 0TSF · line 35 - SMA / EMA / WMA (
sma,ta.smain v5)Source (hl2), Moving Average Length (12)ma · line 39 - Crossover (
crossover,ta.crossoverin v5)MAvg, PMaxbuySignalk · line 83 - Crossunder (
crossunder,ta.crossunderin v5)MAvg, PMaxsellSignallk · line 85 - Crossover (
crossover,ta.crossoverin v5)Source (hl2), PMaxbuySignalc · line 87 - Crossunder (
crossunder,ta.crossunderin v5)Source (hl2), PMaxsellSignallc · line 89 - SMA / EMA (
sma,ta.smain v5)Source (close), Fast Length (12)fast_ma · line 166 - SMA / EMA (
sma,ta.smain v5)Source (close), Slow Length (26)slow_ma · line 167 - SMA / EMA (
sma,ta.smain v5)macd, Signal Smoothing (9)signal · line 169 - CCI (
cci,ta.cciin v5)close, CCI (20)thisCCI · line 175 - SMA (
sma,ta.smain v5)tr, ATR (5)bufferDn · line 177 - SMA (
sma,ta.smain v5)tr, ATR (5)bufferUp · line 178 - SMA (
sma,ta.smain 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
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | longC | On | 212 |
| Open short short | shortC | On | 213 |
| Exit x_long stop and limit | every bar | On | 214 |
| Exit x_short stop and limit | every bar | On | 216 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Cross Alert | alertcondition | PMax - Moving Avg Crossing! | 77 |
| Crossover Alarm | alertcondition | Moving Avg BUY SIGNAL! | 78 |
| Crossunder Alarm | alertcondition | Moving Avg SELL SIGNAL! | 79 |
| Price Cross Alert | alertcondition | PMax - Price Crossing! | 80 |
| Price Crossover Alarm | alertcondition | PRICE OVER PMax - BUY SIGNAL! | 81 |
| Price Crossunder Alarm | alertcondition | PRICE UNDER PMax - SELL SIGNAL! | 82 |
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 | −3.6% | +102.5% | 5 | 0% | 0.00 | 3.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −5.0% | +5.5% | 7 | 0% | 0.00 | 5.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.1% | +9.8% | 4 | 0% | 0.00 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.1% | +8.4% | 4 | 0% | 0.00 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 5 | 0% | 0.00 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 7 | 0% | 0.00 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.0% | +148.3% | 4 | 0% | 0.00 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 2 | 0% | 0.00 | 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 | 0 | — | $0.00 |
| Sideways market | 4 | 0% | −$3,055.45 |
| Falling market | 1 | 0% | −$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.
All 5 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 5 Jul 2024 57,050.00 | 6 Jul 2024 57,616.30 | 1 | −$566.29 |
| long | 20 Oct 2024 68,378.00 | 21 Oct 2024 67,687.70 | 1 | −$690.32 |
| long | 2 May 2025 96,489.90 | 4 May 2025 95,531.30 | 2 | −$958.57 |
| short | 5 Jun 2026 63,886.00 | 13 Jun 2026 64,521.80 | 8 | −$635.81 |
| long | 23 Aug 2026 77,074.90 | 23 Aug 2026 76,304.20 | 0 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Profit Maximizer Strategy this page | — | v4 strategy | −3.6% | 5 | 3.6% |
| Profit Maximizer PMax Strategy - Long-Short by melihtuna | sma atr ema linreg | v4 strategy | +16.2% | 4 | 27.8% |
| Strategy - Profit Maximizer by PMax by MartinCrespo | sma atr ema linreg | v4 strategy | No trades on this market | ||
| Open Close Cross Strategy plus Explorer by roses27 | sma ema wma linreg atr | v4 strategy | does not run in Zeal Terminal | ||
| Y-Profit Maximizer Strategy with Exit Points by Enes_Yetkin_ | ema sma atr linreg | v4 strategy | −1.9% | 13 | 30.4% |
| Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN] by myncrypto | sma ema wma atr | v5 strategy | −47.2% | 4 | 48.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 58 ms | With a workaround 1,000 bars in 132 ms | Not measured |
| PineTS | No 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)