Pine Script v4 · Strategy
RSI of MACD Strategy [Long only]
A Pine Script v4 strategy built on MACD (close, 12), RSI (macdLine, 14) and EMA (close, 21). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 20% of equity and pays no commission. 7 settings; defaults include Fast Length 12, Slow Length 21 and Signal Length 9.
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 RSI of MACD Strategy [Long only] repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did RSI of MACD Strategy [Long only] 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; it opened a long position that was still open on the last bar, so there is no result to report. On ETHUSDT 1D it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
- Can RSI of MACD Strategy [Long only] 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 RSI of MACD Strategy [Long only] use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does RSI of MACD Strategy [Long only] run in Zeal Terminal?
- Yes
- It compiles in 13 ms and runs 1,000 bars in 48 ms, in the browser.
BTCUSDT · 1D · default settings
- Overbought / Profit taking line
- Oversold / entry line
- Exit line
- rsiOfMACD
- Winning trade
- Losing trade
- Equity
- Buy and hold
- 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
- 31.26%
- −$3,125.70
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A long position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 33, 37, 39. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 34
transp = on line 34. v5 folds the transparency into the colour with color.new(c, transp).
-
Note
Uses long =, which v5 renamed line 33
long = on line 33. 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 macd → ta.macd, rsi → ta.rsi, ema → ta.ema, crossover → ta.crossover, abs → math.abs, tostring → str.tostring, crossunder → ta.crossunder.
- 3 strategy calls use the when = argument (line 33, 37, 39). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 4 trades and the same P&L on ETHUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 15: macd → ta.macd
- Line 16: rsi → ta.rsi
- Line 17: ema → ta.ema
- Line 33: long = true → direction = strategy.long
- Line 33: crossover → ta.crossover
13 more edits
- Line 33: crossover → ta.crossover
- Line 34: abs → math.abs
- Line 34: transp = 70 → color.new(abs(strategy.position_size)>=1 ? color.blue : na, 70)
- Line 35: abs → math.abs
- Line 35: crossover → ta.crossover
- Line 35: crossover → ta.crossover
- Line 35: abs → math.abs
- Line 37: tostring → str.tostring
- Line 37: abs → math.abs
- Line 37: crossunder → ta.crossunder
- Line 39: tostring → str.tostring
- Line 39: abs → math.abs
- Line 39: crossunder → ta.crossunder
⋯// © mohanee-//@version=4+//@version=5strategy(title="RSI of MACD Strategy[Long only]", shorttitle="RSIofMACD" , overlay=false, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000, currency=currency.USD) //default_qty_value=10, default_qty_type=strategy.fixed,⋯takeProfit=input(false, title="Take Profit")-[macdLine, signalLine, _] = macd(close, fastLen, slowLen, sigLen)+[macdLine, signalLine, _] = ta.macd(close, fastLen, slowLen, sigLen)-rsiOfMACD = rsi(macdLine, rsiLength)+rsiOfMACD = ta.rsi(macdLine, rsiLength)-emaSlow = ema(close, slowLen)+emaSlow = ta.ema(close, slowLen)//drawings⋯qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1-strategy.entry(id="RSIofMACD", long=true, qty=qty1, when = ( crossover(rsiOfMACD, 30) or crossover(rsiOfMACD, 35) ) and close>=emaSlow )+strategy.entry(id="RSIofMACD", direction = strategy.long, qty=qty1, when = ( ta.crossover(rsiOfMACD, 30) or ta.crossover(rsiOfMACD, 35) ) and close>=emaSlow )-bgcolor(abs(strategy.position_size)>=1 ? color.blue : na , transp=70)+bgcolor(color.new(math.abs(strategy.position_size)>=1 ? color.blue : na, 70) )-barcolor(abs(strategy.position_size)>=1 and ( crossover(rsiOfMACD, 30) or crossover(rsiOfMACD, 35) ) ? color.purple : abs(strategy.position_size)>=1 ? color.blue : na )+barcolor(math.abs(strategy.position_size)>=1 and ( ta.crossover(rsiOfMACD, 30) or ta.crossover(rsiOfMACD, 35) ) ? color.purple : math.abs(strategy.position_size)>=1 ? color.blue : na )//partial exit-strategy.close(id="RSIofMACD", comment="PExit Profit is "+tostring(close - strategy.position_avg_price, "###.##") , qty=strategy.position_size/3, when= takeProfit and abs(strategy.position_size)>=1 and close > strategy.position_avg_price and crossunder(rsiOfMACD,80) )+strategy.close(id="RSIofMACD", comment="PExit Profit is "+str.tostring(close - strategy.position_avg_price, "###.##") , qty=strategy.position_size/3, when= takeProfit and math.abs(strategy.position_size)>=1 and close > strategy.position_avg_price and ta.crossunder(rsiOfMACD,80) )//Close All-strategy.close(id="RSIofMACD", comment="Close All Profit is "+tostring(close - strategy.position_avg_price, "###.##"), when=abs(strategy.position_size)>=1 and crossunder(rsiOfMACD,15) ) //and close > strategy.position_avg_price )+strategy.close(id="RSIofMACD", comment="Close All Profit is "+str.tostring(close - strategy.position_avg_price, "###.##"), when=math.abs(strategy.position_size)>=1 and ta.crossunder(rsiOfMACD,15) ) //and close > strategy.position_avg_price )//Strategy Logic ⋯Same 4 trades and the same P&L on ETHUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.int()
- Line 12: input() → input.int()
- Line 13: input() → input.int()
4 more edits
- Line 14: input() → input.bool()
- Line 33: when = ( ta.crossover(rsiOfMACD, 30) or ta.crossover(rsiOfMACD, 35) ) and close>=emaSlow → if block
- Line 37: when = takeProfit and math.abs(strategy.position_size)>=1 and close > strategy.position_avg_price and ta.crossunder(rsiOfMACD,80) → if block
- Line 39: when = math.abs(strategy.position_size)>=1 and ta.crossunder(rsiOfMACD,15) → if block
⋯// MACD Inputs ///-fastLen = input(12, title="Fast Length")+fastLen = input.int(12, title="Fast Length")-slowLen = input(21, title="Slow Length")+slowLen = input.int(21, title="Slow Length")-sigLen = input(9, title="Signal Length")+sigLen = input.int(9, title="Signal Length")-rsiLength = input(14, title="RSI of MACD Length")+rsiLength = input.int(14, title="RSI of MACD Length")-riskCapital = input(title="Risk % of capital", defval=10, minval=1)+riskCapital = input.int(title="Risk % of capital", defval=10, minval=1)-stopLoss=input(3,title="Stop Loss",minval=1)+stopLoss=input.int(3,title="Stop Loss",minval=1)-takeProfit=input(false, title="Take Profit")+takeProfit=input.bool(false, title="Take Profit")[macdLine, signalLine, _] = ta.macd(close, fastLen, slowLen, sigLen)⋯qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1-strategy.entry(id="RSIofMACD", direction = strategy.long, qty=qty1, when = ( ta.crossover(rsiOfMACD, 30) or ta.crossover(rsiOfMACD, 35) ) and close>=emaSlow )+if ( ta.crossover(rsiOfMACD, 30) or ta.crossover(rsiOfMACD, 35) ) and close>=emaSlow+ strategy.entry(id="RSIofMACD", direction = strategy.long, qty=qty1 )bgcolor(color.new(math.abs(strategy.position_size)>=1 ? color.blue : na, 70) )⋯//partial exit-strategy.close(id="RSIofMACD", comment="PExit Profit is "+str.tostring(close - strategy.position_avg_price, "###.##") , qty=strategy.position_size/3, when= takeProfit and math.abs(strategy.position_size)>=1 and close > strategy.position_avg_price and ta.crossunder(rsiOfMACD,80) )+if takeProfit and math.abs(strategy.position_size)>=1 and close > strategy.position_avg_price and ta.crossunder(rsiOfMACD,80)+ strategy.close(id="RSIofMACD", comment="PExit Profit is "+str.tostring(close - strategy.position_avg_price, "###.##") , qty=strategy.position_size/3 )//Close All-strategy.close(id="RSIofMACD", comment="Close All Profit is "+str.tostring(close - strategy.position_avg_price, "###.##"), when=math.abs(strategy.position_size)>=1 and ta.crossunder(rsiOfMACD,15) ) //and close > strategy.position_avg_price )+if math.abs(strategy.position_size)>=1 and ta.crossunder(rsiOfMACD,15)+ strategy.close(id="RSIofMACD", comment="Close All Profit is "+str.tostring(close - strategy.position_avg_price, "###.##") ) //and close > strategy.position_avg_price )//Strategy Logic ⋯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: 4 before, 3 after on ETHUSDT 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.
⋯// © mohanee-//@version=5+//@version=6strategy(title="RSI of MACD Strategy[Long only]", shorttitle="RSIofMACD" , overlay=false, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000, currency=currency.USD) //default_qty_value=10, default_qty_type=strategy.fixed,⋯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 |
|---|---|---|---|
| Fast Length | 12 | int | macdLine signalLine |
| Slow Length | 21 | int | macdLine signalLine emaSlow |
| Signal Length | 9 | int | macdLine signalLine |
| RSI of MACD Length | 14 | int | rsiOfMACD |
| Risk % of capital | 10 | int · min 1 | qty1 |
| Stop Loss | 3 | int · min 1 | qty1 |
| Take Profit | false | bool | close RSIofMACD |
What it calculates
- MACD (
macd,ta.macdin v5)close, Fast Length (12), Slow Length (21), Signal Length (9)macdLine · line 15 - MACD (
macd,ta.macdin v5)close, Fast Length (12), Slow Length (21), Signal Length (9)signalLine · line 15 - RSI (
rsi,ta.rsiin v5)macdLine, RSI of MACD Length (14)rsiOfMACD · line 16 - EMA (
ema,ta.emain v5)close, Slow Length (21)emaSlow · line 17
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open RSIofMACD long | ( crossover(rsiOfMACD, 30) or crossover(rsiOfMACD, 35) ) and close>=emaSlow | On | 33 |
| Close RSIofMACD | takeProfit and abs(strategy.position_size)>=1 and close > strategy.position_avg_price and crossunder(rsiOfMACD,80) | On | 37 |
| Close RSIofMACD | abs(strategy.position_size)>=1 and crossunder(rsiOfMACD,15) | On | 39 |
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.
- 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 | 0.0% | +102.5% | 0 | 0% | — | 31.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 29.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −20.5% | +9.8% | 4 | 50% | 0.62 | 63.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +40.5% | +8.4% | 4 | 100% | — | 12.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −48.1% | +16.7% | 6 | 33% | 0.57 | 69.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +52.8% | +21.5% | 4 | 75% | 8.33 | 10.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +18.6% | +148.3% | 3 | 67% | 14.17 | 33.8% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +21.8% | +17.1% | 3 | 100% | — | 3.6% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
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 |
|---|---|---|---|---|---|
| RSI of MACD Strategy [Long only] this page | — | v4 strategy | 0.0% | 0 | 31.3% |
| Hulk Strategy x35 Leverage 5m chart w-Alerts by npietronuto1 | rsi macd ema | v5 strategy | No trades on this market | ||
| Short Swing Bearish MACD Cross (By Coinrule) by Coinrule | ema macd | v5 strategy | −6.9% | 8 | 6.9% |
| RSI Cross [xaurr] by livetrend | rsi ema | v4 strategy | +24.4% | 53 | 35.3% |
| MACD Trend Strategy by Zeal Terminal | macd ema | v5 strategy | −1.0% | 21 | 3.5% |
| Bitpanda Coinrule Template by joshuajcoop01 | rsi ema | v5 strategy | −2.8% | 4 | 4.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 13 ms | With a workaround 1,000 bars in 48 ms | Not measured |
| PineTS | No 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 33) 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.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © mohanee//@version=4strategy(title="RSI of MACD Strategy[Long only]", shorttitle="RSIofMACD" , overlay=false, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000, currency=currency.USD) //default_qty_value=10, default_qty_type=strategy.fixed, /////////////////////////////////////////////////////////////////////////////////// MACD Inputs ///fastLen = input(12, title="Fast Length")slowLen = input(21, title="Slow Length")sigLen = input(9, title="Signal Length")rsiLength = input(14, title="RSI of MACD Length")riskCapital = input(title="Risk % of capital", defval=10, minval=1)stopLoss=input(3,title="Stop Loss",minval=1)takeProfit=input(false, title="Take Profit")[macdLine, signalLine, _] = macd(close, fastLen, slowLen, sigLen)rsiOfMACD = rsi(macdLine, rsiLength)emaSlow = ema(close, slowLen)//drawings/////////////////////////////////////////////////////////////////////////////////obLevelPlot = hline(80, title="Overbought / Profit taking line", color=color.blue , linestyle=hline.style_dashed)osLevelPlot = hline(30, title="Oversold / entry line", color=color.green, linestyle=hline.style_dashed)exitLinePlot = hline(15, title="Exit line", color=color.red, linestyle=hline.style_dashed)plot(rsiOfMACD, title = "rsiOfMACD" , color=color.purple)//drawings///////////////////////////////////////////////////////////////////////////////////Strategy Logic ///////////////////////////////////////////////////////////////////////////////////Entry--//Echeck how many units can be purchased based on risk manage ment and stop lossqty1 = (strategy.equity * riskCapital / 100 ) / (close*stopLoss/100) //check if cash is sufficient to buy qty1 , if capital not available use the available capital onlyqty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1strategy.entry(id="RSIofMACD", long=true, qty=qty1, when = ( crossover(rsiOfMACD, 30) or crossover(rsiOfMACD, 35) ) and close>=emaSlow )bgcolor(abs(strategy.position_size)>=1 ? color.blue : na , transp=70)barcolor(abs(strategy.position_size)>=1 and ( crossover(rsiOfMACD, 30) or crossover(rsiOfMACD, 35) ) ? color.purple : abs(strategy.position_size)>=1 ? color.blue : na )//partial exitstrategy.close(id="RSIofMACD", comment="PExit Profit is "+tostring(close - strategy.position_avg_price, "###.##") , qty=strategy.position_size/3, when= takeProfit and abs(strategy.position_size)>=1 and close > strategy.position_avg_price and crossunder(rsiOfMACD,80) )//Close Allstrategy.close(id="RSIofMACD", comment="Close All Profit is "+tostring(close - strategy.position_avg_price, "###.##"), when=abs(strategy.position_size)>=1 and crossunder(rsiOfMACD,15) ) //and close > strategy.position_avg_price )//Strategy Logic /////////////////////////////////////////////////////////////////////////////////