Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Momentum Strategy (BTC-USDT; 1h) - MACD (with source code)

A Pine Script v4 strategy built on RSI (close, 14). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.075% commission. 26 settings; defaults include Fast Length 12, Slow Length 26 and Source close.

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 Momentum Strategy (BTC-USDT; 1h) - MACD (with source code) repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 12 of 12 trades.
How did Momentum Strategy (BTC-USDT; 1h) - MACD (with source code) do on BTCUSDT 1D with default settings?
−14.96%
From 26 Jan 2024 to 21 Oct 2026, over 41 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Momentum Strategy (BTC-USDT; 1h) - MACD (with source code) be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does Momentum Strategy (BTC-USDT; 1h) - MACD (with source code) use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Momentum Strategy (BTC-USDT; 1h) - MACD (with source code) run in Zeal Terminal?
Yes
It compiles in 53 ms and runs 1,000 bars in 91 ms, in the browser.

BTCUSDT · 1D · default settings

  • MACD
  • 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 (26)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctMACD$83$203Equity from $100
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 true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 87, 91) 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.
Net profit
−14.96%
−$14.96
Buy and hold
+102.5%
same period
Closed trades
41
21 won · 20 lost
Profitable
51.2%
of closed trades
Profit factor
0.87
gross profit ÷ gross loss
Max drawdown
40.13%
−$43.93

One run with the author's default settings, $100 starting capital, commission as the script sets it. A short position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses transp =, which v5 removed line 58

    transp = on line 58, 59. 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 ema → ta.ema, sma → ta.sma, wma → ta.wma, rma → ta.rma, hma → ta.hma, pow → math.pow, linreg → ta.linreg, change → ta.change, crossover → ta.crossover, crossunder → ta.crossunder, rsi → ta.rsi.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 7: input(type = input.integer) → input.int()
  • Line 8: input(type = input.integer) → input.int()
  • Line 9: input(type = input.source) → input.source()
  • Line 10: input(type = input.integer) → input.int()
  • Line 15: type is reserved in v5: renamed type_
89 more edits
  • Line 16: ema → ta.ema
  • Line 16: ema → ta.ema
  • Line 16: ema → ta.ema
  • Line 16: ema → ta.ema
  • Line 16: ema → ta.ema
  • Line 16: sma → ta.sma
  • Line 16: sma → ta.sma
  • Line 16: sma → ta.sma
  • Line 16: sma → ta.sma
  • Line 16: sma → ta.sma
  • Line 16: wma → ta.wma
  • Line 16: wma → ta.wma
  • Line 16: wma → ta.wma
  • Line 16: wma → ta.wma
  • Line 16: wma → ta.wma
  • Line 16: rma → ta.rma
  • Line 16: rma → ta.rma
  • Line 16: rma → ta.rma
  • Line 16: rma → ta.rma
  • Line 16: rma → ta.rma
  • Line 16: ema → ta.ema
  • Line 16: ema → ta.ema
  • Line 16: ema → ta.ema
  • Line 16: ema → ta.ema
  • Line 16: sma → ta.sma
  • Line 16: sma → ta.sma
  • Line 16: sma → ta.sma
  • Line 16: sma → ta.sma
  • Line 16: wma → ta.wma
  • Line 16: wma → ta.wma
  • Line 16: wma → ta.wma
  • Line 16: wma → ta.wma
  • Line 16: rma → ta.rma
  • Line 16: rma → ta.rma
  • Line 16: rma → ta.rma
  • Line 16: rma → ta.rma
  • Line 16: ema → ta.ema
  • Line 16: sma → ta.sma
  • Line 16: wma → ta.wma
  • Line 16: rma → ta.rma
  • Line 16: ema → ta.ema
  • Line 16: ema → ta.ema
  • Line 16: ema → ta.ema
  • Line 16: sma → ta.sma
  • Line 16: sma → ta.sma
  • Line 16: sma → ta.sma
  • Line 16: wma → ta.wma
  • Line 16: wma → ta.wma
  • Line 16: wma → ta.wma
  • Line 16: rma → ta.rma
  • Line 16: rma → ta.rma
  • Line 16: rma → ta.rma
  • Line 16: hma → ta.hma
  • Line 16: hma → ta.hma
  • Line 16: hma → ta.hma
  • Line 16: hma → ta.hma
  • Line 16: hma → ta.hma
  • Line 16: hma → ta.hma
  • Line 16: hma → ta.hma
  • Line 16: hma → ta.hma
  • Line 16: hma → ta.hma
  • Line 16: hma → ta.hma
  • Line 16: hma → ta.hma
  • Line 16: hma → ta.hma
  • Line 16: hma → ta.hma
  • Line 16: ema → ta.ema
  • Line 35: pow → math.pow
  • Line 41: linreg → ta.linreg
  • Line 47: change → ta.change
  • Line 48: change → ta.change
  • Line 51: crossover → ta.crossover
  • Line 52: crossunder → ta.crossunder
  • Line 55: change → ta.change
  • Line 56: change → ta.change
  • Line 58: change → ta.change
  • Line 58: change → ta.change
  • Line 58: transp = 0 → color.new(change(macd)>0 and on_minmax?color.white:change(macd)<0 and on_minmax?color.purple:color.blue, 0)
  • Line 59: transp = 0 → color.new(col_signal, 0)
  • Line 64: rsi → ta.rsi
  • Line 67: change → ta.change
  • Line 67: change → ta.change
  • Line 68: change → ta.change
  • Line 68: change → ta.change
  • Line 78: change → ta.change
  • Line 78: change → ta.change
  • Line 79: change → ta.change
  • Line 79: change → ta.change
  • Line 87: strategy.entry(…, true) → strategy.entry(…, strategy.long)
  • Line 91: strategy.entry(…, false) → strategy.entry(…, strategy.short)
⋯// © Drun30-//@version=4+//@version=5strategy("MACD+RSI", initial_capital=100, overlay=false,default_qty_type=strategy.percent_of_equity,default_qty_value=100,commission_type="percent",commission_value=0.075)⋯// Getting inputs-fast_length = input(title="Fast Length", type=input.integer, defval=12,group="MACD")+fast_length = input.int(title="Fast Length", defval=12,group="MACD")-slow_length = input(title="Slow Length", type=input.integer, defval=26,group="MACD")+slow_length = input.int(title="Slow Length", defval=26,group="MACD")-src = input(title="Source", type=input.source, defval=close,group="MACD")+src = input.source(title="Source", defval=close,group="MACD")-signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9,group="MACD")+signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9,group="MACD")sma_source1 = input(title="Simple MA FAST (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")⋯// Calculating-ma(source,length,type)=>+ma(source,length,type_)=>-    type=="FEMA"?4*ema(source,length)-ema(ema(ema(ema(source,length),length),length),length):type=="FSMA"?4*sma(source,length)-sma(sma(sma(sma(source,length),length),length),length):type=="FWMA"?4*wma(source,length)-wma(wma(wma(wma(source,length),length),length),length):type=="FRMA"?4*rma(source,length)-rma(rma(rma(rma(source,length),length),length),length):type=="TEMA"?3*ema(source,length)-ema(ema(ema(source,length),length),length):type=="TSMA"?3*sma(source,length)-sma(sma(sma(source,length),length),length):type=="TWMA"?3*wma(source,length)-wma(wma(wma(source,length),length),length):type=="TRMA"?3*rma(source,length)-rma(rma(rma(source,length),length),length):type=="EMA"?ema(source,length):type=="SMA"?sma(source,length):type=="WMA"?wma(source,length):type=="RMA"?rma(source,length):type=="DEMA"?2*ema(source,length)-ema(ema(source,length),length):type=="DSMA"?2*sma(source,length)-sma(sma(source,length),length):type=="DWMA"?2*wma(source,length)-wma(wma(source,length),length):type=="DRMA"?2*rma(source,length)-rma(rma(source,length),length):type=="HMA"?hma(source,length):type=="DHMA"?2*hma(source,length)-hma(hma(source,length),length):type=="THMA"?3*hma(source,length)-hma(hma(hma(source,length),length),length):type=="FHMA"?4*hma(source,length)-hma(hma(hma(hma(source,length),length),length),length):ema(source,length)+    type_=="FEMA"?4*ta.ema(source,length)-ta.ema(ta.ema(ta.ema(ta.ema(source,length),length),length),length):type_=="FSMA"?4*ta.sma(source,length)-ta.sma(ta.sma(ta.sma(ta.sma(source,length),length),length),length):type_=="FWMA"?4*ta.wma(source,length)-ta.wma(ta.wma(ta.wma(ta.wma(source,length),length),length),length):type_=="FRMA"?4*ta.rma(source,length)-ta.rma(ta.rma(ta.rma(ta.rma(source,length),length),length),length):type_=="TEMA"?3*ta.ema(source,length)-ta.ema(ta.ema(ta.ema(source,length),length),length):type_=="TSMA"?3*ta.sma(source,length)-ta.sma(ta.sma(ta.sma(source,length),length),length):type_=="TWMA"?3*ta.wma(source,length)-ta.wma(ta.wma(ta.wma(source,length),length),length):type_=="TRMA"?3*ta.rma(source,length)-ta.rma(ta.rma(ta.rma(source,length),length),length):type_=="EMA"?ta.ema(source,length):type_=="SMA"?ta.sma(source,length):type_=="WMA"?ta.wma(source,length):type_=="RMA"?ta.rma(source,length):type_=="DEMA"?2*ta.ema(source,length)-ta.ema(ta.ema(source,length),length):type_=="DSMA"?2*ta.sma(source,length)-ta.sma(ta.sma(source,length),length):type_=="DWMA"?2*ta.wma(source,length)-ta.wma(ta.wma(source,length),length):type_=="DRMA"?2*ta.rma(source,length)-ta.rma(ta.rma(source,length),length):type_=="HMA"?ta.hma(source,length):type_=="DHMA"?2*ta.hma(source,length)-ta.hma(ta.hma(source,length),length):type_=="THMA"?3*ta.hma(source,length)-ta.hma(ta.hma(ta.hma(source,length),length),length):type_=="FHMA"?4*ta.hma(source,length)-ta.hma(ta.hma(ta.hma(ta.hma(source,length),length),length),length):ta.ema(source,length)fast_ma = ma(src,fast_length,sma_source1)  ⋯    if not na(macd[1])-        macd:=pow((macd*(recent_stress)),level)+(1-recent_stress*macd[1])+        macd:=math.pow((macd*(recent_stress)),level)+(1-recent_stress*macd[1])use_ma= input(true,title="Use moving average (MACD)?",group="Moving Average")⋯if use_linreg-    macd:=linreg(macd,input(10,title="Length",group="Linear Regression"),input(1,title="Offset",group="Linear Regression"))+    macd:=ta.linreg(macd,input(10,title="Length",group="Linear Regression"),input(1,title="Offset",group="Linear Regression"))//macd == linea blu (differenza tra media mobile veloce e media mobile lenta)⋯on_minmax = input(true,title="Use min/max macd",group="Condition entry/exit")-aperturaLong = change(macd)>0//crossover(macd,signal)+aperturaLong = ta.change(macd)>0//crossover(macd,signal)-aperturashort=not (change(macd)>0)//crossunder(macd,signal)+aperturashort=not (ta.change(macd)>0)//crossunder(macd,signal)if on_cross    on_minmax:=false-    aperturaLong := crossover(macd,signal)+    aperturaLong := ta.crossover(macd,signal)-    aperturashort := crossunder(macd,signal)+    aperturashort := ta.crossunder(macd,signal)if on_minmax    on_cross:=false-    aperturaLong := change(macd)>0//crossover(macd,signal)+    aperturaLong := ta.change(macd)>0//crossover(macd,signal)-    aperturashort:=change(macd)<0//crossunder(macd,signal)+    aperturashort:=ta.change(macd)<0//crossunder(macd,signal)//plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )-plot(macd, title="MACD", color=change(macd)>0 and on_minmax?color.white:change(macd)<0 and on_minmax?color.purple:color.blue, transp=0)+plot(macd, title="MACD", color=color.new(ta.change(macd)>0 and on_minmax?color.white:ta.change(macd)<0 and on_minmax?color.purple:color.blue, 0))-plot(on_cross?signal:na, title="Signal", color=col_signal, transp=0)+plot(on_cross?signal:na, title="Signal", color=color.new(col_signal, 0))rsiFilter = input(false,title="Use RSI filter?",group="RSI")⋯srcr=input(close,title="RSI source",group="RSI")-rsi=rsi(srcr,len)+rsi=ta.rsi(srcr,len)ovb=input(90,title="Overbought height",group="RSI") ovs=input(44,title="Oversold height",group="RSI")-okLong=rsi<ovb and change(macd)>0 and change(macd)[1]<=0+okLong=rsi<ovb and ta.change(macd)>0 and ta.change(macd)[1]<=0-okShort=rsi>ovs and change(macd)<0 and change(macd)[1]>=0+okShort=rsi>ovs and ta.change(macd)<0 and ta.change(macd)[1]>=0if not rsiFilter⋯if rsiTP-    aperturaLong := change(macd)>0 and change(macd)[1]<=0 and rsi<ovb//crossover(macd,signal)+    aperturaLong := ta.change(macd)>0 and ta.change(macd)[1]<=0 and rsi<ovb//crossover(macd,signal)-    aperturashort:=change(macd)<0 and change(macd)[1]>=0 and rsi>ovs//crossunder(macd,signal)+    aperturashort:=ta.change(macd)<0 and ta.change(macd)[1]>=0 and rsi>ovs//crossunder(macd,signal)if not rsiTP⋯if usiLong and strategy.position_size<=0 and okLong and aperturaLong-    strategy.entry("LONGHISSIMO",true)+    strategy.entry("LONGHISSIMO",strategy.long)if chiusuraLong ⋯if usiShort and strategy.position_size>=0 and okShort and aperturashort-    strategy.entry("SHORTISSIMO",false)+    strategy.entry("SHORTISSIMO",strategy.short)

Clean v5

VerifiedDownload the v5 script

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

  • Line 11: input() → input.string()
  • Line 12: input() → input.string()
  • Line 13: input() → input.string()
  • Line 29: input() → input.bool()
  • Line 30: input() → input.float()
  • Line 31: input() → input.int()
16 more edits
  • Line 36: input() → input.bool()
  • Line 38: input() → input.int()
  • Line 38: input() → input.string()
  • Line 39: input() → input.bool()
  • Line 41: input() → input.int()
  • Line 41: input() → input.int()
  • Line 45: input() → input.bool()
  • Line 46: input() → input.bool()
  • Line 60: input() → input.bool()
  • Line 61: input() → input.bool()
  • Line 62: input() → input.int()
  • Line 63: input() → input.source()
  • Line 65: input() → input.int()
  • Line 66: input() → input.int()
  • Line 73: input() → input.bool()
  • Line 74: input() → input.bool()
⋯signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9,group="MACD")-sma_source1 = input(title="Simple MA FAST (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")+sma_source1 = input.string(title="Simple MA FAST (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")-sma_source2 = input(title="Simple MA SLOW (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")+sma_source2 = input.string(title="Simple MA SLOW (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")-sma_signal = input(title="Simple MA(Signal Line)",defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")+sma_signal = input.string(title="Simple MA(Signal Line)",defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")// Calculating⋯col_signal = #ff6a00-use_stress=input(false,title="Use stress on recent bars",group="Stress")+use_stress=input.bool(false,title="Use stress on recent bars",group="Stress")-recent_stress=input(0.01,title="Stress on recent bars",group="Stress",step=0.01,minval=0.01,maxval=0.99)+recent_stress=input.float(0.01,title="Stress on recent bars",group="Stress",step=0.01,minval=0.01,maxval=0.99)-level=input(1,title="Level of stress",group="Stress")+level=input.int(1,title="Level of stress",group="Stress")if use_stress ⋯        macd:=math.pow((macd*(recent_stress)),level)+(1-recent_stress*macd[1])-use_ma= input(true,title="Use moving average (MACD)?",group="Moving Average")+use_ma= input.bool(true,title="Use moving average (MACD)?",group="Moving Average")if use_ma-    macd:=ma(macd,input(36,title="Length",group="Moving Average"),input(title="Type MA",defval="THMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="Moving Average"))+    macd:=ma(macd,input.int(36,title="Length",group="Moving Average"),input.string(title="Type MA",defval="THMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="Moving Average"))-use_linreg= input(true,title="Use linear regression (MACD)?",group="Linear Regression")+use_linreg= input.bool(true,title="Use linear regression (MACD)?",group="Linear Regression")if use_linreg-    macd:=ta.linreg(macd,input(10,title="Length",group="Linear Regression"),input(1,title="Offset",group="Linear Regression"))+    macd:=ta.linreg(macd,input.int(10,title="Length",group="Linear Regression"),input.int(1,title="Offset",group="Linear Regression"))//macd == linea blu (differenza tra media mobile veloce e media mobile lenta)⋯//hist == istogramma (differenza tra macd e media mobile)-on_cross = input(false,title="Use cross macd and signal",group="Condition entry/exit")+on_cross = input.bool(false,title="Use cross macd and signal",group="Condition entry/exit")-on_minmax = input(true,title="Use min/max macd",group="Condition entry/exit")+on_minmax = input.bool(true,title="Use min/max macd",group="Condition entry/exit")aperturaLong = ta.change(macd)>0//crossover(macd,signal)⋯plot(on_cross?signal:na, title="Signal", color=color.new(col_signal, 0))-rsiFilter = input(false,title="Use RSI filter?",group="RSI")+rsiFilter = input.bool(false,title="Use RSI filter?",group="RSI")-rsiTP = input(true,title="Use RSI Take Profit?",group="RSI")+rsiTP = input.bool(true,title="Use RSI Take Profit?",group="RSI")-len=input(14,title="RSI period",group="RSI")+len=input.int(14,title="RSI period",group="RSI")-srcr=input(close,title="RSI source",group="RSI")+srcr=input.source(close,title="RSI source",group="RSI")rsi=ta.rsi(srcr,len)-ovb=input(90,title="Overbought height",group="RSI") +ovb=input.int(90,title="Overbought height",group="RSI") -ovs=input(44,title="Oversold height",group="RSI")+ovs=input.int(44,title="Oversold height",group="RSI")okLong=rsi<ovb and ta.change(macd)>0 and ta.change(macd)[1]<=0⋯    -usiLong=input(true,title="Use long?")+usiLong=input.bool(true,title="Use long?")-usiShort=input(true,title="Use short?")+usiShort=input.bool(true,title="Use short?")chiusuraShort=rsi<ovs or (aperturaLong)⋯

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 41 before, 28 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © Drun30-//@version=5+//@version=6strategy("MACD+RSI", initial_capital=100, overlay=false,default_qty_type=strategy.percent_of_equity,default_qty_value=100,commission_type="percent",commission_value=0.075)⋯

Settings

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

SettingDefaultType and rangeFeeds
MACD
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 FAST (Oscillator)EMAstring · options ["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"]fast_ma
Simple MA SLOW (Oscillator)EMAstring · options ["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"]slow_ma
Simple MA(Signal Line)EMAstring · options ["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"]signal
Stress
Use stress on recent barsfalseboolline 32
Stress on recent bars0.01float · min 0.01 · max 0.99 · step 0.01macd
Level of stress1intmacd
Moving Average
Use moving average (MACD)?trueboolline 37
Length36intsignal hist aperturaLong aperturashort okLong okShort line 34 MACD
Type MATHMAstring · options ["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"]signal hist aperturaLong aperturashort okLong okShort line 34 MACD
Linear Regression
Use linear regression (MACD)?trueboolline 40
Length10intsignal hist aperturaLong aperturashort okLong okShort line 34 MACD
Offset1intsignal hist aperturaLong aperturashort okLong okShort line 34 MACD
Condition entry/exit
Use cross macd and signalfalseboolline 49 Signal
Use min/max macdtrueboolline 53 MACD
RSI
Use RSI filter?falseboolline 69
Use RSI Take Profit?trueboolline 77 line 80
RSI period14intrsi
RSI sourceclosesourcersi
Overbought height90intaperturaLong okLong chiusuraLong
Oversold height44intaperturashort okShort chiusuraShort
Use long?trueboolentry LONGHISSIMO line 86
Use short?trueboolentry SHORTISSIMO line 90

What it calculates

  • RSI (rsi, ta.rsi in v5)RSI source (close), RSI period (14)rsi · line 64

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.

closecloseprice datalenRSI periodsetting · 14fast_lengthFast Lengthsetting · 12sma_source1Simple MA FAST (Oscilla…setting · EMAslow_lengthSlow Lengthsetting · 26sma_source2Simple MA SLOW (Oscilla…setting · EMAmacdOffsetsetting · 1signal_lengthSignal Smoothingsetting · 9sma_signalSimple MA(Signal Line)setting · EMAovbOverbought heightsetting · 90ovsOversold heightsetting · 44rsiRSI→ rsifast_mafast_mavalueslow_maslow_mavaluesignalsignalvaluehisthistvalueaperturaLongaperturaLongconditionaperturashortaperturashortconditionokLongokLongconditionokShortokShortconditionchiusuraShortchiusuraShortconditionchiusuraLongchiusuraLongconditioncol_grow_above, col_grow_below, col_fall_above, col_fall_below, col_macd, col_signalColourcol_grow_above · col_grow_bel…close:SHORTISSIMOClose SHORTISSIMOstrategy.closeentry:LONGHISSIMOOpen LONGHISSIMOstrategy.entryclose:LONGHISSIMOClose LONGHISSIMOstrategy.closeentry:SHORTISSIMOOpen SHORTISSIMOstrategy.entryplot:58MACDplotplot:59Signalplot

Order rules

OrderFires whenBy defaultLine
Close SHORTISSIMOchiusuraShortOn85
Open LONGHISSIMO longusiLong and strategy.position_size<=0 and okLong and aperturaLongOn87
Close LONGHISSIMOchiusuraLongOn89
Open SHORTISSIMO shortusiShort and strategy.position_size>=0 and okShort and aperturashortOn91

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

Does it repaint?

No

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

12/12trades 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−15.0%+102.5%4151%0.8740.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+4.9%+5.5%3743%1.1315.3%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−23.8%+9.8%4238%0.8557.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+20.8%+8.4%4058%1.4815.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−68.8%+16.7%3546%0.5280.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+54.4%+21.5%4156%1.7518.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−44.5%+148.3%4455%0.6664.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+9.1%+17.1%3949%1.2612.1%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market1553%−$17.16
Sideways market1436%−$45.73
Falling market1267%$48.00

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

How bad could the drawdown be?

58.0%

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

0%67%
All 41 trades
SideEntryExitBarsP&L
long5 Jul 2024 57,050.003 Aug 2024 61,498.3029$7.64
long20 Aug 2024 59,438.505 Sep 2024 57,970.9016−$2.82
long19 Sep 2024 61,760.005 Oct 2024 62,086.0016$0.40
short5 Oct 2024 62,086.0011 Oct 2024 60,326.406$2.83
long20 Oct 2024 68,378.006 Nov 2024 69,372.0017$1.41
short6 Nov 2024 69,372.0012 Nov 2024 88,648.006−$30.62
long12 Nov 2024 88,648.0029 Nov 2024 95,644.0017$6.11
short29 Nov 2024 95,644.0018 Dec 2024 106,134.0019−$9.46
long18 Dec 2024 106,134.0026 Dec 2024 99,429.608−$4.88
short26 Dec 2024 99,429.6028 Dec 2024 94,299.002$3.54
long9 Jan 2025 95,060.601 Feb 2025 102,430.0023$5.63
short1 Feb 2025 102,430.003 Feb 2025 97,700.602$3.57
long20 Feb 2025 96,644.402 Mar 2025 86,064.5010−$9.24
long19 Mar 2025 82,715.006 Apr 2025 83,538.0018$0.63
short6 Apr 2025 83,538.007 Apr 2025 78,430.001$4.46
long19 Apr 2025 84,474.709 May 2025 103,262.0020$17.48
short9 May 2025 103,262.0027 May 2025 109,435.0018−$5.93
long27 May 2025 109,435.0029 May 2025 107,782.002−$1.51
short29 May 2025 107,782.006 Jun 2025 101,509.008$5.07
long16 Jun 2025 105,594.0025 Jun 2025 106,083.009$0.29
short25 Jun 2025 106,083.0029 Jun 2025 107,297.004−$1.23
long29 Jun 2025 107,297.0025 Jul 2025 118,341.0026$9.47
short25 Jul 2025 118,341.002 Aug 2025 113,298.008$4.23
long14 Aug 2025 123,306.0026 Aug 2025 110,112.0012−$11.61
long10 Sep 2025 111,546.0027 Sep 2025 109,643.0017−$1.77
long7 Oct 2025 124,659.0017 Oct 2025 108,194.0010−$12.51
long31 Oct 2025 108,323.0011 Nov 2025 106,011.0011−$1.85
short11 Nov 2025 106,011.0012 Nov 2025 103,059.001$2.09
long1 Dec 2025 90,360.0019 Dec 2025 85,516.4018−$4.48
long4 Jan 2026 90,628.0023 Jan 2026 89,559.7019−$1.02
long17 Feb 2026 68,892.4014 Mar 2026 70,930.0025$2.13
short14 Mar 2026 70,930.0019 Mar 2026 71,246.605−$0.47
long19 Mar 2026 71,246.6023 Mar 2026 67,859.004−$3.81
long10 Apr 2026 71,788.0030 Apr 2026 75,780.0020$3.99
short30 Apr 2026 75,780.0023 May 2026 75,539.5023$0.13
long17 Jun 2026 65,675.003 Jul 2026 61,560.0016−$4.99
long11 Jul 2026 64,161.7029 Jul 2026 63,915.0018−$0.39
short29 Jul 2026 63,915.002 Aug 2026 62,823.704$1.13
long13 Aug 2026 63,480.006 Sep 2026 79,831.8024$18.85
short6 Sep 2026 79,831.8024 Sep 2026 84,397.6018−$5.44
long24 Sep 2026 84,397.6010 Oct 2026 82,635.6016−$1.95

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
Momentum Strategy (BTC-USDT; 1h) - MACD (with source code) this page—v4 strategy−15.0%4140.1%
Triple RSI strategy by Trade_by_DBrsiv5 strategy+3.2%23.3%
Hobbiecode - RSI + Close previous day by hobbiecodersiv5 strategy+1.2%634.2%
dirt cheap yet elegant RSI Strategy by SparkyFlaryrsiv4 strategy−11.4%820.5%
RSI Classic Strategy (by Coinrule) by Coinrulersiv4 strategy+7.5%67.2%
RSITrendStrategy by email_analystsrsiv4 strategy+69.2%2238.6%

Where it runs

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

Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 87, 91) 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/// © Drun30//@version=4strategy("MACD+RSI", initial_capital=100, overlay=false,default_qty_type=strategy.percent_of_equity,default_qty_value=100,commission_type="percent",commission_value=0.075)//@version=4// Getting inputsfast_length = input(title="Fast Length", type=input.integer, defval=12,group="MACD")slow_length = input(title="Slow Length", type=input.integer, defval=26,group="MACD")src = input(title="Source", type=input.source, defval=close,group="MACD")signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9,group="MACD")sma_source1 = input(title="Simple MA FAST (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")sma_source2 = input(title="Simple MA SLOW (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")sma_signal = input(title="Simple MA(Signal Line)",defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")// Calculatingma(source,length,type)=>    type=="FEMA"?4*ema(source,length)-ema(ema(ema(ema(source,length),length),length),length):type=="FSMA"?4*sma(source,length)-sma(sma(sma(sma(source,length),length),length),length):type=="FWMA"?4*wma(source,length)-wma(wma(wma(wma(source,length),length),length),length):type=="FRMA"?4*rma(source,length)-rma(rma(rma(rma(source,length),length),length),length):type=="TEMA"?3*ema(source,length)-ema(ema(ema(source,length),length),length):type=="TSMA"?3*sma(source,length)-sma(sma(sma(source,length),length),length):type=="TWMA"?3*wma(source,length)-wma(wma(wma(source,length),length),length):type=="TRMA"?3*rma(source,length)-rma(rma(rma(source,length),length),length):type=="EMA"?ema(source,length):type=="SMA"?sma(source,length):type=="WMA"?wma(source,length):type=="RMA"?rma(source,length):type=="DEMA"?2*ema(source,length)-ema(ema(source,length),length):type=="DSMA"?2*sma(source,length)-sma(sma(source,length),length):type=="DWMA"?2*wma(source,length)-wma(wma(source,length),length):type=="DRMA"?2*rma(source,length)-rma(rma(source,length),length):type=="HMA"?hma(source,length):type=="DHMA"?2*hma(source,length)-hma(hma(source,length),length):type=="THMA"?3*hma(source,length)-hma(hma(hma(source,length),length),length):type=="FHMA"?4*hma(source,length)-hma(hma(hma(hma(source,length),length),length),length):ema(source,length)fast_ma = ma(src,fast_length,sma_source1)  slow_ma = ma(src,slow_length,sma_source2)macd = fast_ma - slow_ma //Differenza tra la media mobile veloce e quella lenta signal = ma(macd,signal_length,sma_signal) //usa o la SMA oppure la EMA sulla differenza tra la media mobile veloce e lentahist = macd - signal //Differenza tra la differenza precedente e la media mobile della differenza// Plot colorscol_grow_above = #26A69Acol_grow_below = #FFCDD2col_fall_above = #B2DFDBcol_fall_below = #EF5350col_macd = #0094ffcol_signal = #ff6a00use_stress=input(false,title="Use stress on recent bars",group="Stress")recent_stress=input(0.01,title="Stress on recent bars",group="Stress",step=0.01,minval=0.01,maxval=0.99)level=input(1,title="Level of stress",group="Stress")if use_stress     macd:=macd*(1/(1-recent_stress))    if not na(macd[1])        macd:=pow((macd*(recent_stress)),level)+(1-recent_stress*macd[1])use_ma= input(true,title="Use moving average (MACD)?",group="Moving Average")if use_ma    macd:=ma(macd,input(36,title="Length",group="Moving Average"),input(title="Type MA",defval="THMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="Moving Average"))use_linreg= input(true,title="Use linear regression (MACD)?",group="Linear Regression")if use_linreg    macd:=linreg(macd,input(10,title="Length",group="Linear Regression"),input(1,title="Offset",group="Linear Regression"))//macd == linea blu (differenza tra media mobile veloce e media mobile lenta)//signal == linea arancione (media mobile dell'macd)//hist == istogramma (differenza tra macd e media mobile)on_cross = input(false,title="Use cross macd and signal",group="Condition entry/exit")on_minmax = input(true,title="Use min/max macd",group="Condition entry/exit")aperturaLong = change(macd)>0//crossover(macd,signal)aperturashort=not (change(macd)>0)//crossunder(macd,signal)if on_cross    on_minmax:=false    aperturaLong := crossover(macd,signal)    aperturashort := crossunder(macd,signal)if on_minmax    on_cross:=false    aperturaLong := change(macd)>0//crossover(macd,signal)    aperturashort:=change(macd)<0//crossunder(macd,signal)//plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )plot(macd, title="MACD", color=change(macd)>0 and on_minmax?color.white:change(macd)<0 and on_minmax?color.purple:color.blue, transp=0)plot(on_cross?signal:na, title="Signal", color=col_signal, transp=0)rsiFilter = input(false,title="Use RSI filter?",group="RSI")rsiTP = input(true,title="Use RSI Take Profit?",group="RSI")len=input(14,title="RSI period",group="RSI")srcr=input(close,title="RSI source",group="RSI")rsi=rsi(srcr,len)ovb=input(90,title="Overbought height",group="RSI") ovs=input(44,title="Oversold height",group="RSI")okLong=rsi<ovb and change(macd)>0 and change(macd)[1]<=0okShort=rsi>ovs and change(macd)<0 and change(macd)[1]>=0if not rsiFilter    okLong:=true    okShort:=true    usiLong=input(true,title="Use long?")usiShort=input(true,title="Use short?")chiusuraShort=rsi<ovs or (aperturaLong)chiusuraLong=rsi>ovb or (aperturashort)if rsiTP    aperturaLong := change(macd)>0 and change(macd)[1]<=0 and rsi<ovb//crossover(macd,signal)    aperturashort:=change(macd)<0 and change(macd)[1]>=0 and rsi>ovs//crossunder(macd,signal)if not rsiTP    chiusuraShort:=okLong and aperturaLong    chiusuraLong:=okShort and aperturashort    if chiusuraShort     strategy.close("SHORTISSIMO")if usiLong and strategy.position_size<=0 and okLong and aperturaLong    strategy.entry("LONGHISSIMO",true)if chiusuraLong     strategy.close("LONGHISSIMO")if usiShort and strategy.position_size>=0 and okShort and aperturashort    strategy.entry("SHORTISSIMO",false)