Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

LONG SAZB $

A Pine Script v4 strategy built on EMA (source, 70), EMA or SMA (MACDsource, 13) and SMA (macd, 24). It has 7 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.015% commission. 48 settings; defaults include From Day 01, From Month 04 and From Year 2022.

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 LONG SAZB $ repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did LONG SAZB $ do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
Can LONG SAZB $ be converted to Pine Script v5?
Not tested
The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
Does LONG SAZB $ use a stop loss?
Yes
strategy.exit sets a stop on line 158.
Does LONG SAZB $ run in Zeal Terminal?
Yes
It compiles in 39 ms and runs 1,000 bars in 145 ms, in the browser.

BTCUSDT · 1D · default settings

  • Histogram
  • Positive delta
  • Negative delta
  • MACD line
  • Signal
  • EMA on MACD line
  • Dots
  • %K
  • %D
  • Upper Band
  • Lower Band
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$1,000$2,025Equity from $1,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 long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 157) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market. The live re-run is not offered here: the script requests BINANCE:BTCUSDT 60, BINANCE:BTCUSDT 15, which this page cannot load in your browser.

Needs BINANCE:BTCUSDT 60 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Needs BINANCE:BTCUSDT 15 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Values that depend on it are empty on this chart.

Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.00

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

    6 settings do nothing

    “═════════════════════ SOURCE ═════════════════════”, “════════════════════ MTF EMA ════════════════════”, “═════════════════════ MACD ══════════════════════”, “═══════════════════ STOCHASTIC ════════════════════”, “═════════════════ LONG SL ═════════════════”, “═════════════════ LONG TP ═════════════════” are declared but never read.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    Uses transp =, which v5 removed line 37

    transp = on line 37, 71, 72, 73, 78, 79, 80, 81, 85, 105, 135, 136, 151. v5 folds the transparency into the colour with color.new(c, transp).

  • Note

    Uses long =, which v5 renamed line 157

    long = on line 157. v5 writes it as direction = strategy.long or strategy.short.

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 ema → ta.ema, security → request.security, sma → ta.sma, crossunder → ta.crossunder, stoch → ta.stoch, atr → ta.atr, lowest → ta.lowest, highest → ta.highest, crossover → ta.crossover, cross → ta.cross.

v4 → v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 20: input(type = input.bool) → input.bool()
  • Line 21: input(type = input.bool) → input.bool()
  • Line 24: input(type = input.bool) → input.bool()
  • Line 25: input(type = input.resolution) → input.timeframe()
  • Line 26: input(type = input.integer) → input.int()
  • Line 27: ema → ta.ema
72 more edits
  • Line 28: security → request.security
  • Line 30: input(type = input.resolution) → input.timeframe()
  • Line 31: input(type = input.integer) → input.int()
  • Line 32: ema → ta.ema
  • Line 33: security → request.security
  • Line 37: transp = 70 → color.new(mtf1 > mtf2 ? color.red : color.green, 70)
  • Line 39: input(type = input.bool) → input.bool()
  • Line 47: input(type = input.integer) → input.int()
  • Line 49: ema → ta.ema
  • Line 49: sma → ta.sma
  • Line 50: ema → ta.ema
  • Line 50: sma → ta.sma
  • Line 53: ema → ta.ema
  • Line 53: sma → ta.sma
  • Line 54: ema → ta.ema
  • Line 54: sma → ta.sma
  • Line 59: ema → ta.ema
  • Line 60: ema → ta.ema
  • Line 61: sma → ta.sma
  • Line 65: input(type = input.bool) → input.bool()
  • Line 66: input(type = input.integer) → input.int()
  • Line 71: transp = 100 → color.new(color.green, 100)
  • Line 72: transp = 100 → color.new(color.red, 100)
  • Line 73: transp = 20 → color.new(leadLine1 > leadLine2 ? #53b987 : #eb4d5c, 20)
  • Line 78: transp = 40 → color.new(color.green, 40)
  • Line 79: transp = 40 → color.new(color.green, 40)
  • Line 80: transp = 0 → color.new(color.black, 0)
  • Line 81: transp = 0 → color.new(color.gray, 0)
  • Line 85: ema → ta.ema
  • Line 85: transp = 0 → color.new(color.red, 0)
  • Line 87: crossunder → ta.crossunder
  • Line 89: input(type = input.bool) → input.bool()
  • Line 90: input(type = input.bool) → input.bool()
  • Line 95: sma → ta.sma
  • Line 95: stoch → ta.stoch
  • Line 96: sma → ta.sma
  • Line 99: ema → ta.ema
  • Line 105: transp = 80 → color.new(#9915FF, 80)
  • Line 110: crossunder → ta.crossunder
  • Line 117: input(type = input.bool) → input.bool()
  • Line 118: input(type = input.float) → input.float()
  • Line 120: input(type = input.bool) → input.bool()
  • Line 121: crossunder → ta.crossunder
  • Line 122: input(type = input.bool) → input.bool()
  • Line 123: input(type = input.float) → input.float()
  • Line 126: crossunder → ta.crossunder
  • Line 127: input(type = input.bool) → input.bool()
  • Line 128: input(type = input.bool) → input.bool()
  • Line 129: input(type = input.integer) → input.int()
  • Line 130: input(type = input.integer) → input.int()
  • Line 131: input(type = input.float) → input.float()
  • Line 132: atr → ta.atr
  • Line 133: lowest → ta.lowest
  • Line 134: crossunder → ta.crossunder
  • Line 135: transp = 100 → color.new(color.blue, 100)
  • Line 136: transp = 0 → color.new(color.red, 0)
  • Line 137: input(type = input.bool) → input.bool()
  • Line 138: input(type = input.bool) → input.bool()
  • Line 139: input(type = input.float) → input.float()
  • Line 142: crossunder → ta.crossunder
  • Line 143: input(type = input.bool) → input.bool()
  • Line 144: input(type = input.bool) → input.bool()
  • Line 145: input(type = input.integer) → input.int()
  • Line 146: input(type = input.integer) → input.int()
  • Line 147: input(type = input.float) → input.float()
  • Line 148: atr → ta.atr
  • Line 149: highest → ta.highest
  • Line 150: crossover → ta.crossover
  • Line 151: transp = 0 → color.new(color.green, 0)
  • Line 153: cross → ta.cross
  • Line 157: long = true → direction = strategy.long
  • Line 171: //@version=4 → //@version=5
⋯     commission_value=0.015)-SOURCE = input(title = "═════════════════════ SOURCE ═════════════════════", defval = false, type = input.bool)+SOURCE = input.bool(title = "═════════════════════ SOURCE ═════════════════════", defval = false)-sourcehl2 = input(title="Source hl2 or (open+close)/2 ?",type=input.bool,defval=true)+sourcehl2 = input.bool(title="Source hl2 or (open+close)/2 ?",defval=true)source = sourcehl2 ? hl2 : ((open+close)/2)//MTF EMA-MTFEMA = input(title = "════════════════════ MTF EMA ════════════════════", defval = false, type = input.bool)+MTFEMA = input.bool(title = "════════════════════ MTF EMA ════════════════════", defval = false)-res1=input(title="MTF EMA 1", type=input.resolution, defval="60")+res1=input.timeframe(title="MTF EMA 1", defval="60")-len1 = input(title = "EMA Period 1", type=input.integer, defval=70, minval=1)+len1 = input.int(title = "EMA Period 1", defval=70, minval=1)-ema1 = ema(source, len1)+ema1 = ta.ema(source, len1)-emaStep1 = security (syminfo.tickerid, res1, ema1, barmerge.gaps_off, barmerge.lookahead_off)+emaStep1 = request.security (syminfo.tickerid, res1, ema1, barmerge.gaps_off, barmerge.lookahead_off)mtf1 = emaStep1-res2=input(title="MTF EMA 2", type=input.resolution, defval="15")+res2=input.timeframe(title="MTF EMA 2", defval="15")-len2 = input(title = "EMA Period 2", type=input.integer, defval=68, minval=1)+len2 = input.int(title = "EMA Period 2", defval=68, minval=1)-ema2 = ema(source, len2)+ema2 = ta.ema(source, len2)-emaStep2 = security (syminfo.tickerid, res2, ema2, barmerge.gaps_off, barmerge.lookahead_off)+emaStep2 = request.security (syminfo.tickerid, res2, ema2, barmerge.gaps_off, barmerge.lookahead_off)mtf2 = emaStep2⋯t2 = plot(mtf2, linewidth=4, color= color.navy, title="EMA")-fill(t1, t2, transp = 70, color = mtf1 > mtf2 ? color.red : color.green)+fill(t1, t2, color = color.new(mtf1 > mtf2 ? color.red : color.green, 70))///MACD-MACD= input(title = "═════════════════════ MACD ══════════════════════", defval = false, type = input.bool)+MACD= input.bool(title = "═════════════════════ MACD ══════════════════════", defval = false)MACDsource=close⋯useOldAlgo = input(false, title="Use normal MACD")-Lmacsig=input(title="LONG MACD and signal crossover limit",type=input.integer,defval=180)+Lmacsig=input.int(title="LONG MACD and signal crossover limit",defval=180)// Fast line-ma1= useEma ? ema(MACDsource, fastLength) : sma(MACDsource, fastLength) +ma1= useEma ? ta.ema(MACDsource, fastLength) : ta.sma(MACDsource, fastLength) -ma2 = useEma ?  ema(ma1,fastLength) :  sma(ma1,fastLength) +ma2 = useEma ?  ta.ema(ma1,fastLength) :  ta.sma(ma1,fastLength) fastMA = ((2 * ma1) - ma2)// Slow line-mas1=  useEma ? ema(MACDsource , slowLength) :  sma(MACDsource , slowLength)+mas1=  useEma ? ta.ema(MACDsource , slowLength) :  ta.sma(MACDsource , slowLength)-mas2 =  useEma ? ema(mas1 , slowLength): sma(mas1 , slowLength)+mas2 =  useEma ? ta.ema(mas1 , slowLength): ta.sma(mas1 , slowLength)slowMA = ((2 * mas1) - mas2)⋯// Signal line-emasig1 = ema(macd, signalLength)+emasig1 = ta.ema(macd, signalLength)-emasig2 = ema(emasig1, signalLength)+emasig2 = ta.ema(emasig1, signalLength)-signal = useOldAlgo ? sma(macd, signalLength) : (2 * emasig1) - emasig2+signal = useOldAlgo ? ta.sma(macd, signalLength) : (2 * emasig1) - emasig2hist = macd - signal⋯//MACD ribbon-macdribbon=input(title="Show MACD ribbon?",type=input.bool,defval=false)+macdribbon=input.bool(title="Show MACD ribbon?",defval=false)-macdx=input(title="MACD ribbon multiplier", type=input.integer, defval=3, minval=1)+macdx=input.int(title="MACD ribbon multiplier", defval=3, minval=1)leadLine1 = macdribbon ? macd*macdx + source : na⋯//MACD plot-p3 = plot(leadLine1, color= color.green, title="MACD", transp = 100, linewidth = 8)+p3 = plot(leadLine1, color= color.new(color.green, 100), title="MACD", linewidth = 8)-p4 = plot(leadLine2, color= color.red, title="Signal", transp = 100, linewidth = 8)+p4 = plot(leadLine2, color= color.new(color.red, 100), title="Signal", linewidth = 8)-fill(p3, p4, transp = 20, color = leadLine1 > leadLine2 ? #53b987 : #eb4d5c)+fill(p3, p4, color = color.new(leadLine1 > leadLine2 ? #53b987 : #eb4d5c, 20))plot((leadLine3), color = histline, title="Histogram", linewidth = 3) ⋯downHist = (hist <= 0) ? hist : 0-p1 = plot(upHist, color=color.green, transp=40, style=plot.style_columns, title='Positive delta')+p1 = plot(upHist, color=color.new(color.green, 40), style=plot.style_columns, title='Positive delta')-p2 = plot(downHist, color=color.green, transp=40, style=plot.style_columns, title='Negative delta') +p2 = plot(downHist, color=color.new(color.green, 40), style=plot.style_columns, title='Negative delta') -zeroLine = plot(macd, color=color.black, transp=0, linewidth=2, title='MACD line')+zeroLine = plot(macd, color=color.new(color.black, 0), linewidth=2, title='MACD line')-signalLine = plot(signal, color=color.gray, transp=0, linewidth=2, title='Signal')+signalLine = plot(signal, color=color.new(color.gray, 0), linewidth=2, title='Signal')ribbonDiff = color.green⋯circleYPosition = signal-plot(ema(macd,MacdEmaLength) , color=color.red, transp=0, linewidth=2, title='EMA on MACD line')+plot(ta.ema(macd,MacdEmaLength) , color=color.new(color.red, 0), linewidth=2, title='EMA on MACD line')ribbonDiff2 = hist > 0 ? color.green : color.red-plot(crossunder(signal,macd) ? circleYPosition : na,style=plot.style_circles, linewidth=4, color=ribbonDiff, title='Dots')+plot(ta.crossunder(signal,macd) ? circleYPosition : na,style=plot.style_circles, linewidth=4, color=ribbonDiff, title='Dots')//STOCHASTIC-stochchch= input(title = "═══════════════════ STOCHASTIC ════════════════════", defval = false, type = input.bool)+stochchch= input.bool(title = "═══════════════════ STOCHASTIC ════════════════════", defval = false)-StochOn = input(title="Stochastic On?",type=input.bool,defval=true)+StochOn = input.bool(title="Stochastic On?",defval=true)periodK = input(10, title="K", minval=1)⋯stochlimit = input(30, title="Stoch value crossover", minval=1)-k = sma(stoch(close, high, low, periodK), smoothK)+k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)-d = sma(k, periodD)+d = ta.sma(k, periodD)stochSignal = StochOn ? (d < stochlimit ? true : false) : truepp= input(1, title="avg price length", minval=1)-p = ema (source, pp)+p = ta.ema (source, pp)K = k + p⋯h1 = hline(20, "Lower Band", color=#606060)-fill(h0, h1, color=#9915FF, transp=80, title="Background")+fill(h0, h1, color=color.new(#9915FF, 80), title="Background")//Long ⋯downtrend = close < mtf1 and mtf1 > mtf2 -crossMACD = crossunder(macd,signal) +crossMACD = ta.crossunder(macd,signal) LongBuy = uptrend and stochSignal? crossMACD and signal < Lmacsig and macd < Lmacsig : na⋯//ATR & TP/SL-ATRTPSLX= input(title = "═════════════════ LONG SL ═════════════════", defval = false, type = input.bool)+ATRTPSLX= input.bool(title = "═════════════════ LONG SL ═════════════════", defval = false)-maxIdLossPcnt = input(5, "Max Intraday Loss(%)", type=input.float, minval=0.0, step=0.1)+maxIdLossPcnt = input.float(5, "Max Intraday Loss(%)", minval=0.0, step=0.1)strategy.risk.max_intraday_loss(maxIdLossPcnt, strategy.percent_of_equity)-SSL2=input(title="Long Stop Loss when MTF EMA cross?",type=input.bool,defval=false)+SSL2=input.bool(title="Long Stop Loss when MTF EMA cross?",defval=false)-SSLOP = LONG  and crossunder(source, mtf1) +SSLOP = LONG  and ta.crossunder(source, mtf1) -SlossPercOn = input(title="Long Stop Loss (%) on?",type=input.bool,defval=false)+SlossPercOn = input.bool(title="Long Stop Loss (%) on?",defval=false)-SlossPerc = input(title="Long Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=4.7) * 0.01+SlossPerc = input.float(title="Long Stop Loss (%)", minval=0.0, step=0.1, defval=4.7) * 0.01SSpricePerc = LONG and SlossPercOn? strategy.position_avg_price * (-1 - SlossPerc) : naplot(series = SSpricePerc, linewidth=2, color= color.maroon,style=plot.style_linebr, title="Long Stop Loss %") -SSLX = LONG and crossunder(source, SSpricePerc)+SSLX = LONG and ta.crossunder(source, SSpricePerc)-SSLatr= input(title="Long Stop Loss ATR?",type=input.bool,defval=true)+SSLatr= input.bool(title="Long Stop Loss ATR?",defval=true)-useStructure=input(title="Look back for High/Lows?",type=input.bool,defval=true)+useStructure=input.bool(title="Look back for High/Lows?",defval=true)-Slookback=input(title="How far to look back for High/Lows:",type=input.integer,defval=18,minval=1)+Slookback=input.int(title="How far to look back for High/Lows:",defval=18,minval=1)-SatrLenghth=input(title="Long ATR Lenghth",type=input.integer,defval=9,minval=1)+SatrLenghth=input.int(title="Long ATR Lenghth",defval=9,minval=1)-SatrStopMultiplier=input(title="Long ATR Stop x ?", type=input.float,defval=4.3, minval=0.1,step=0.1)+SatrStopMultiplier=input.float(title="Long ATR Stop x ?",defval=4.3, minval=0.1,step=0.1)-Satr = atr(SatrLenghth)+Satr = ta.atr(SatrLenghth)-LongStop = SSLatr ? ((useStructure ? lowest(low, Slookback) : source) - Satr * SatrStopMultiplier) : na+LongStop = SSLatr ? ((useStructure ? ta.lowest(low, Slookback) : source) - Satr * SatrStopMultiplier) : na-SStop = crossunder(source,LongStop)+SStop = ta.crossunder(source,LongStop)-plot(Satr, color=color.blue, title="ATR", transp=100)+plot(Satr, color=color.new(color.blue, 100), title="ATR")-plot(series = uptrend ? LongStop : na, color=color.red, style=plot.style_linebr, title="Long Trailing Stop", transp=0)+plot(series = uptrend ? LongStop : na, color=color.new(color.red, 0), style=plot.style_linebr, title="Long Trailing Stop")-ATRTPSLXX= input(title = "═════════════════ LONG TP ═════════════════", defval = false, type = input.bool)+ATRTPSLXX= input.bool(title = "═════════════════ LONG TP ═════════════════", defval = false)-TpPercOn = input(title="Long Take Profit (%) on?",type=input.bool,defval=true)+TpPercOn = input.bool(title="Long Take Profit (%) on?",defval=true)-TpPerc = input(title="Long Take Profit (%)", type=input.float, minval=0.0, step=0.1, defval=5.3) * 0.01+TpPerc = input.float(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=5.3) * 0.01TppricePerc = LONG and TpPercOn? strategy.position_avg_price * (-1 + TpPerc) : naplot(series = TppricePerc, linewidth=2, color= color.lime,style=plot.style_linebr, title="Long Take Profit %") -TPLX = LONG and crossunder(source, TppricePerc)+TPLX = LONG and ta.crossunder(source, TppricePerc)-TP1=input(title="1 Long Take Profit On?",type=input.bool,defval=true)+TP1=input.bool(title="1 Long Take Profit On?",defval=true)-useStructure1=input(title="Look back for High/Lows?",type=input.bool,defval=true)+useStructure1=input.bool(title="Look back for High/Lows?",defval=true)-STplookback=input(title="How far to look back for High/Lows for 1 TP",type=input.integer,defval=12,minval=1)+STplookback=input.int(title="How far to look back for High/Lows for 1 TP",defval=12,minval=1)-STpatrLenghth=input(title="Long ATR Lenghth 1 TP",type=input.integer,defval=24,minval=1)+STpatrLenghth=input.int(title="Long ATR Lenghth 1 TP",defval=24,minval=1)-SatrProfitMultiplier = input(title="First Long ATR Take Profit x ?", type=input.float,defval=5.5, minval=0.1,step=0.1)+SatrProfitMultiplier = input.float(title="First Long ATR Take Profit x ?",defval=5.5, minval=0.1,step=0.1)-STpatr = atr(STpatrLenghth)+STpatr = ta.atr(STpatrLenghth)-LongTakeProfit = (useStructure1 ? highest(high, STplookback) : source) + STpatr * SatrProfitMultiplier+LongTakeProfit = (useStructure1 ? ta.highest(high, STplookback) : source) + STpatr * SatrProfitMultiplier-LongTP = TP1 ? crossover(source, LongTakeProfit): false+LongTP = TP1 ? ta.crossover(source, LongTakeProfit): false-plot(series = uptrend ? LongTakeProfit: na , color=color.green, style=plot.style_linebr, title="Long Trailing Take Profit", transp=0)+plot(series = uptrend ? LongTakeProfit: na , color=color.new(color.green, 0), style=plot.style_linebr, title="Long Trailing Take Profit")// Bar color-barcolor(cross(macd, signal) ? (macd - signal > 0 ? (uptrend and macd < 0 and signal < 0 ? color.yellow : na) : (downtrend and macd > 0 and signal > 0 ? color.blue : na)) : na)+barcolor(ta.cross(macd, signal) ? (macd - signal > 0 ? (uptrend and macd < 0 and signal < 0 ? color.yellow : na) : (downtrend and macd > 0 and signal > 0 ? color.blue : na)) : na)// Strategy ATR⋯if GOLONG and TP1-    strategy.entry(id="Entry LONG 1TP", long=true,comment="Entry Long")+    strategy.entry(id="Entry LONG 1TP", direction = strategy.long,comment="Entry Long")    strategy.exit("Long Profit or Loss 1TP","Entry LONG 1TP", limit=LongTakeProfit, stop=LongStop)⋯//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)-//@version=4+//@version=5

Clean v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 4: input() → input.int()
  • Line 5: input() → input.int()
  • Line 6: input() → input.int()
  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 11: input() → input.int()
11 more edits
  • Line 41: input() → input.int()
  • Line 42: input() → input.int()
  • Line 43: input() → input.int()
  • Line 44: input() → input.int()
  • Line 45: input() → input.bool()
  • Line 46: input() → input.bool()
  • Line 91: input() → input.int()
  • Line 92: input() → input.int()
  • Line 93: input() → input.int()
  • Line 94: input() → input.int()
  • Line 98: input() → input.int()
⋯// From Date Inputs-fromDay = input(defval = 01, title = "From Day", minval = 1, maxval = 31)+fromDay = input.int(defval = 01, title = "From Day", minval = 1, maxval = 31)-fromMonth = input(defval = 04, title = "From Month", minval = 1, maxval = 12)+fromMonth = input.int(defval = 04, title = "From Month", minval = 1, maxval = 12)-fromYear = input(defval = 2022, title = "From Year", minval = 1970)+fromYear = input.int(defval = 2022, title = "From Year", minval = 1970) // To Date Inputs-toDay = input(defval = 01, title = "To Day", minval = 1, maxval = 31)+toDay = input.int(defval = 01, title = "To Day", minval = 1, maxval = 31)-toMonth = input(defval = 05, title = "To Month", minval = 1, maxval = 12)+toMonth = input.int(defval = 05, title = "To Month", minval = 1, maxval = 12)-toYear = input(defval = 2022, title = "To Year", minval = 1970)+toYear = input.int(defval = 2022, title = "To Year", minval = 1970) ⋯MACDsource=close-fastLength = input(13, minval=1, title="MACD fast moving average")+fastLength = input.int(13, minval=1, title="MACD fast moving average")-slowLength=input(18,minval=1, title="MACD slow moving average")+slowLength=input.int(18,minval=1, title="MACD slow moving average")-signalLength=input(24,minval=1, title="MACD signal line moving average")+signalLength=input.int(24,minval=1, title="MACD signal line moving average")-MacdEmaLength =input(9, title="MACD EMA period", minval=1)+MacdEmaLength =input.int(9, title="MACD EMA period", minval=1)-useEma = input(true, title="Use EMA (otherwise SMA)")+useEma = input.bool(true, title="Use EMA (otherwise SMA)")-useOldAlgo = input(false, title="Use normal MACD")+useOldAlgo = input.bool(false, title="Use normal MACD")Lmacsig=input.int(title="LONG MACD and signal crossover limit",defval=180)⋯StochOn = input.bool(title="Stochastic On?",defval=true)-periodK = input(10, title="K", minval=1)+periodK = input.int(10, title="K", minval=1)-periodD = input(1, title="D", minval=1)+periodD = input.int(1, title="D", minval=1)-smoothK = input(3, title="Smooth", minval=1)+smoothK = input.int(3, title="Smooth", minval=1)-stochlimit = input(30, title="Stoch value crossover", minval=1)+stochlimit = input.int(30, title="Stoch value crossover", minval=1)k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)⋯stochSignal = StochOn ? (d < stochlimit ? true : false) : true-pp= input(1, title="avg price length", minval=1)+pp= input.int(1, title="avg price length", minval=1)p = ta.ema (source, pp)⋯

Does it run in Pine Script v6?

Not tested

Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)-//@version=5+//@version=6

Settings

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

SettingDefaultType and rangeFeeds
From Day01int · min 1 · max 31startDate
From Month04int · min 1 · max 12startDate
From Year2022int · min 1970startDate
To Day01int · min 1 · max 31finishDate
To Month05int · min 1 · max 12finishDate
To Year2022int · min 1970finishDate
═════════════════════ SOURCE ═════════════════════falseboolunused
Source hl2 or (open+close)/2 ?trueboolsource
════════════════════ MTF EMA ════════════════════falseboolunused
MTF EMA 160timeframe (written input.resolution)emaStep1
EMA Period 170int (written input.integer) · min 1ema1
MTF EMA 215timeframe (written input.resolution)emaStep2
EMA Period 268int (written input.integer) · min 1ema2
═════════════════════ MACD ══════════════════════falseboolunused
MACD fast moving average13int · min 1ma1 ma2
MACD slow moving average18int · min 1mas1 mas2
MACD signal line moving average24int · min 1emasig1 emasig2 signal
MACD EMA period9int · min 1EMA on MACD line
Use EMA (otherwise SMA)trueboolma1 ma2 mas1 mas2
Use normal MACDfalseboolsignal
LONG MACD and signal crossover limit180int (written input.integer)LongBuy
Show MACD ribbon?falseboolleadLine1 leadLine2
MACD ribbon multiplier3int (written input.integer) · min 1leadLine1 leadLine2
═══════════════════ STOCHASTIC ════════════════════falseboolunused
Stochastic On?trueboolstochSignal
K10int · min 1k
D1int · min 1d
Smooth3int · min 1k
Stoch value crossover30int · min 1stochSignal
avg price length1int · min 1p
═════════════════ LONG SL ═════════════════falseboolunused
Max Intraday Loss(%)5float · min 0.0 · step 0.1line 119
Long Stop Loss when MTF EMA cross?falseboolclose Entry LONG 1TP line 164
Long Stop Loss (%) on?falseboolSSpricePerc
Long Stop Loss (%)4.7float · min 0.0 · step 0.1SSpricePerc
Long Stop Loss ATR?trueboolLongStop GOLONG
Look back for High/Lows?trueboolLongStop
How far to look back for High/Lows:18int (written input.integer) · min 1LongStop
Long ATR Lenghth9int (written input.integer) · min 1Satr
Long ATR Stop x ?4.3float · min 0.1 · step 0.1LongStop
═════════════════ LONG TP ═════════════════falseboolunused
Long Take Profit (%) on?trueboolTppricePerc
Long Take Profit (%)5.3float · min 0.0 · step 0.1TppricePerc
1 Long Take Profit On?trueboolLongTP entry Entry LONG 1TP exit Long Profit or Loss 1TP line 156
Look back for High/Lows?trueboolLongTakeProfit
How far to look back for High/Lows for 1 TP12int (written input.integer) · min 1LongTakeProfit
Long ATR Lenghth 1 TP24int (written input.integer) · min 1STpatr
First Long ATR Take Profit x ?5.5float · min 0.1 · step 0.1LongTakeProfit

What it calculates

  • EMA (ema, ta.ema in v5)source, EMA Period 1 (70)ema1 · line 27
  • EMA (ema, ta.ema in v5)source, EMA Period 2 (68)ema2 · line 32
  • EMA / SMA (ema, ta.ema in v5)MACDsource, MACD fast moving average (13)ma1 · line 49
  • EMA / SMA (ema, ta.ema in v5)ma1, MACD fast moving average (13)ma2 · line 50
  • EMA / SMA (ema, ta.ema in v5)MACDsource, MACD slow moving average (18)mas1 · line 53
  • EMA / SMA (ema, ta.ema in v5)mas1, MACD slow moving average (18)mas2 · line 54
  • EMA (ema, ta.ema in v5)macd, MACD signal line moving average (24)emasig1 · line 59
  • EMA (ema, ta.ema in v5)emasig1, MACD signal line moving average (24)emasig2 · line 60
  • SMA (sma, ta.sma in v5)macd, MACD signal line moving average (24)signal · line 61
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, periodK), Smooth (3)k · line 95
  • SMA (sma, ta.sma in v5)k, D (1)d · line 96
  • EMA (ema, ta.ema in v5)source, avg price length (1)p · line 99
  • Crossunder (crossunder, ta.crossunder in v5)macd, signalcrossMACD · line 110
  • ATR (atr, ta.atr in v5)Long ATR Lenghth (9)Satr · line 132
  • Lowest (lowest, ta.lowest in v5)low, How far to look back for High/Lows: (18)LongStop · line 133
  • Crossunder (crossunder, ta.crossunder in v5)source, LongStopSStop · line 134
  • ATR (atr, ta.atr in v5)Long ATR Lenghth 1 TP (24)STpatr · line 148
  • Highest (highest, ta.highest in v5)high, How far to look back for High/Lows for 1 TP (12)LongTakeProfit · line 149
  • Crossover (crossover, ta.crossover in v5)source, LongTakeProfitLongTP · line 150

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 116 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Entry LONG 1TP longGOLONG and TP1On157
Exit Long Profit or Loss 1TP stop and limitGOLONG and TP1On158
Close Entry LONG 1TPSSLXOn160
Close Entry LONG 1TPTPLXOn162
Close Entry LONG 1TPSSLOP and SSL2On165
Close (not time_cond)On168
cancel_all (not time_cond)On169

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • ClearHigher-timeframe data2 security call(s), none with lookahead on.
  • 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

Not run on other markets: the script requests BINANCE:BTCUSDT 60, BINANCE:BTCUSDT 15, and that data is not available here (a lower timeframe than the chart; the engine does not evaluate intrabar data; a lower timeframe than the chart; the engine does not evaluate intrabar data). Its results would rest on empty values.

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
LONG SAZB $ this page—v4 strategy0.0%00.0%
ATR + STC + MA by Romediusema lowest highest atr smav5 strategy−1.2%153.3%
-NoSKi Hammer-Star -w angle of ema Backtester - by noski1atr ema sma highest lowestv5 strategydoes not run in Zeal Terminal
WOMBO COMBO- EMA & VWAP & MACD & BB & STC by MakeMoneyCoESTB2020ema sma stoch highest lowestv4 strategy−0.5%62.2%
MACD Strategy by maxencetajetatr highest lowest ema smav5 strategy+5.8%56.9%
DC Breakout Strategy - This is simplicity at its finest. by Robrecht99sma highest lowest atrv5 strategy+10.8%578.3%

Where it runs

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

Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 157) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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/// © Steven A. Zmuda Burke / stevenz17// From Date InputsfromDay = input(defval = 01, title = "From Day", minval = 1, maxval = 31)fromMonth = input(defval = 04, title = "From Month", minval = 1, maxval = 12)fromYear = input(defval = 2022, title = "From Year", minval = 1970) // To Date InputstoDay = input(defval = 01, title = "To Day", minval = 1, maxval = 31)toMonth = input(defval = 05, title = "To Month", minval = 1, maxval = 12)toYear = input(defval = 2022, title = "To Year", minval = 1970) // Calculate start/end date and time conditionstartDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)finishDate = timestamp(toYear, toMonth, toDay, 00, 00)time_cond = time >= startDate and time <= finishDate// Inputstrategy("LONG", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, slippage=1, commission_type=strategy.commission.percent,      commission_value=0.015)SOURCE = input(title = "═════════════════════ SOURCE ═════════════════════", defval = false, type = input.bool)sourcehl2 = input(title="Source hl2 or (open+close)/2 ?",type=input.bool,defval=true)source = sourcehl2 ? hl2 : ((open+close)/2)//MTF EMAMTFEMA = input(title = "════════════════════ MTF EMA ════════════════════", defval = false, type = input.bool)res1=input(title="MTF EMA 1", type=input.resolution, defval="60")len1 = input(title = "EMA Period 1", type=input.integer, defval=70, minval=1)ema1 = ema(source, len1)emaStep1 = security (syminfo.tickerid, res1, ema1, barmerge.gaps_off, barmerge.lookahead_off)mtf1 = emaStep1res2=input(title="MTF EMA 2", type=input.resolution, defval="15")len2 = input(title = "EMA Period 2", type=input.integer, defval=68, minval=1)ema2 = ema(source, len2)emaStep2 = security (syminfo.tickerid, res2, ema2, barmerge.gaps_off, barmerge.lookahead_off)mtf2 = emaStep2t1 = plot(mtf1, linewidth=4, color= color.aqua, title="EMA")t2 = plot(mtf2, linewidth=4, color= color.navy, title="EMA")fill(t1, t2, transp = 70, color = mtf1 > mtf2 ? color.red : color.green)///MACDMACD= input(title = "═════════════════════ MACD ══════════════════════", defval = false, type = input.bool)MACDsource=closefastLength = input(13, minval=1, title="MACD fast moving average")slowLength=input(18,minval=1, title="MACD slow moving average")signalLength=input(24,minval=1, title="MACD signal line moving average")MacdEmaLength =input(9, title="MACD EMA period", minval=1)useEma = input(true, title="Use EMA (otherwise SMA)")useOldAlgo = input(false, title="Use normal MACD")Lmacsig=input(title="LONG MACD and signal crossover limit",type=input.integer,defval=180)// Fast linema1= useEma ? ema(MACDsource, fastLength) : sma(MACDsource, fastLength) ma2 = useEma ?  ema(ma1,fastLength) :  sma(ma1,fastLength) fastMA = ((2 * ma1) - ma2)// Slow linemas1=  useEma ? ema(MACDsource , slowLength) :  sma(MACDsource , slowLength)mas2 =  useEma ? ema(mas1 , slowLength): sma(mas1 , slowLength)slowMA = ((2 * mas1) - mas2)// MACD linemacd = fastMA - slowMA// Signal lineemasig1 = ema(macd, signalLength)emasig2 = ema(emasig1, signalLength)signal = useOldAlgo ? sma(macd, signalLength) : (2 * emasig1) - emasig2hist = macd - signalhistline = hist > 0 ? color.green : color.red//MACD ribbonmacdribbon=input(title="Show MACD ribbon?",type=input.bool,defval=false)macdx=input(title="MACD ribbon multiplier", type=input.integer, defval=3, minval=1)leadLine1 = macdribbon ? macd*macdx + source : naleadLine2 = macdribbon ? signal*macdx + source : naleadLine3 = hist + source//MACD plotp3 = plot(leadLine1, color= color.green, title="MACD", transp = 100, linewidth = 8)p4 = plot(leadLine2, color= color.red, title="Signal", transp = 100, linewidth = 8)fill(p3, p4, transp = 20, color = leadLine1 > leadLine2 ? #53b987 : #eb4d5c)plot((leadLine3), color = histline, title="Histogram", linewidth = 3) l="TEst"upHist = (hist > 0) ? hist : 0downHist = (hist <= 0) ? hist : 0p1 = plot(upHist, color=color.green, transp=40, style=plot.style_columns, title='Positive delta')p2 = plot(downHist, color=color.green, transp=40, style=plot.style_columns, title='Negative delta') zeroLine = plot(macd, color=color.black, transp=0, linewidth=2, title='MACD line')signalLine = plot(signal, color=color.gray, transp=0, linewidth=2, title='Signal')ribbonDiff = color.greenfill(zeroLine, signalLine, color=ribbonDiff)circleYPosition = signalplot(ema(macd,MacdEmaLength) , color=color.red, transp=0, linewidth=2, title='EMA on MACD line')ribbonDiff2 = hist > 0 ? color.green : color.redplot(crossunder(signal,macd) ? circleYPosition : na,style=plot.style_circles, linewidth=4, color=ribbonDiff, title='Dots')//STOCHASTICstochchch= input(title = "═══════════════════ STOCHASTIC ════════════════════", defval = false, type = input.bool)StochOn = input(title="Stochastic On?",type=input.bool,defval=true)periodK = input(10, title="K", minval=1)periodD = input(1, title="D", minval=1)smoothK = input(3, title="Smooth", minval=1)stochlimit = input(30, title="Stoch value crossover", minval=1)k = sma(stoch(close, high, low, periodK), smoothK)d = sma(k, periodD)stochSignal = StochOn ? (d < stochlimit ? true : false) : truepp= input(1, title="avg price length", minval=1)p = ema (source, pp)K = k + pplot(k, title="%K", color=#0094FF)plot(d, title="%D", color=#FF6A00)h0 = hline(72, "Upper Band", color=#606060)h1 = hline(20, "Lower Band", color=#606060)fill(h0, h1, color=#9915FF, transp=80, title="Background")//Long LS= "════════════════════════════════ LONG CONDITIONS ═══════════════════════════"uptrend = close > mtf1 and mtf1 < mtf2downtrend = close < mtf1 and mtf1 > mtf2 crossMACD = crossunder(macd,signal) LongBuy = uptrend and stochSignal? crossMACD and signal < Lmacsig and macd < Lmacsig : naLONG = strategy.position_size > 0SHORT = strategy.position_size < 0FLAT = strategy.position_size == 0 plotshape(LongBuy, style=shape.xcross, text="LONG", color=color.green)//ATR & TP/SLATRTPSLX= input(title = "═════════════════ LONG SL ═════════════════", defval = false, type = input.bool)maxIdLossPcnt = input(5, "Max Intraday Loss(%)", type=input.float, minval=0.0, step=0.1)strategy.risk.max_intraday_loss(maxIdLossPcnt, strategy.percent_of_equity)SSL2=input(title="Long Stop Loss when MTF EMA cross?",type=input.bool,defval=false)SSLOP = LONG  and crossunder(source, mtf1) SlossPercOn = input(title="Long Stop Loss (%) on?",type=input.bool,defval=false)SlossPerc = input(title="Long Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=4.7) * 0.01SSpricePerc = LONG and SlossPercOn? strategy.position_avg_price * (-1 - SlossPerc) : naplot(series = SSpricePerc, linewidth=2, color= color.maroon,style=plot.style_linebr, title="Long Stop Loss %") SSLX = LONG and crossunder(source, SSpricePerc)SSLatr= input(title="Long Stop Loss ATR?",type=input.bool,defval=true)useStructure=input(title="Look back for High/Lows?",type=input.bool,defval=true)Slookback=input(title="How far to look back for High/Lows:",type=input.integer,defval=18,minval=1)SatrLenghth=input(title="Long ATR Lenghth",type=input.integer,defval=9,minval=1)SatrStopMultiplier=input(title="Long ATR Stop x ?", type=input.float,defval=4.3, minval=0.1,step=0.1)Satr = atr(SatrLenghth)LongStop = SSLatr ? ((useStructure ? lowest(low, Slookback) : source) - Satr * SatrStopMultiplier) : naSStop = crossunder(source,LongStop)plot(Satr, color=color.blue, title="ATR", transp=100)plot(series = uptrend ? LongStop : na, color=color.red, style=plot.style_linebr, title="Long Trailing Stop", transp=0)ATRTPSLXX= input(title = "═════════════════ LONG TP ═════════════════", defval = false, type = input.bool)TpPercOn = input(title="Long Take Profit (%) on?",type=input.bool,defval=true)TpPerc = input(title="Long Take Profit (%)", type=input.float, minval=0.0, step=0.1, defval=5.3) * 0.01TppricePerc = LONG and TpPercOn? strategy.position_avg_price * (-1 + TpPerc) : naplot(series = TppricePerc, linewidth=2, color= color.lime,style=plot.style_linebr, title="Long Take Profit %") TPLX = LONG and crossunder(source, TppricePerc)TP1=input(title="1 Long Take Profit On?",type=input.bool,defval=true)useStructure1=input(title="Look back for High/Lows?",type=input.bool,defval=true)STplookback=input(title="How far to look back for High/Lows for 1 TP",type=input.integer,defval=12,minval=1)STpatrLenghth=input(title="Long ATR Lenghth 1 TP",type=input.integer,defval=24,minval=1)SatrProfitMultiplier = input(title="First Long ATR Take Profit x ?", type=input.float,defval=5.5, minval=0.1,step=0.1)STpatr = atr(STpatrLenghth)LongTakeProfit = (useStructure1 ? highest(high, STplookback) : source) + STpatr * SatrProfitMultiplierLongTP = TP1 ? crossover(source, LongTakeProfit): falseplot(series = uptrend ? LongTakeProfit: na , color=color.green, style=plot.style_linebr, title="Long Trailing Take Profit", transp=0)// Bar colorbarcolor(cross(macd, signal) ? (macd - signal > 0 ? (uptrend and macd < 0 and signal < 0 ? color.yellow : na) : (downtrend and macd > 0 and signal > 0 ? color.blue : na)) : na)// Strategy ATRGOLONG = LongBuy and SSLatr and FLATif GOLONG and TP1    strategy.entry(id="Entry LONG 1TP", long=true,comment="Entry Long")    strategy.exit("Long Profit or Loss 1TP","Entry LONG 1TP", limit=LongTakeProfit, stop=LongStop)if SSLX    strategy.close(id="Entry LONG 1TP", comment="% Long SL EXIT")if TPLX    strategy.close(id="Entry LONG 1TP", comment="% Long TP EXIT")    if SSLOP and SSL2    strategy.close(id="Entry LONG 1TP", comment="MTF EMA cross EXIT")        if (not time_cond)    strategy.close_all()    strategy.cancel_all()    //plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)//@version=4