Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Stoch-RSI 4h-1h-15min

A Pine Script v4 strategy built on CUM or Change ((change(close)) * volume), EMA (nv, avl) and RSI (av, l1). It has 10 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 100% of equity and pays 0.07% commission. 24 settings; defaults include Trading Pair (For reference only) DOGE, MACD/RVSI Confluence Resolution 15 and Timeframe RSI 5.

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 Stoch-RSI 4h-1h-15min repaint?
No
No repainting patterns were found in the source. The live replay was not measured: the script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script.
How did Stoch-RSI 4h-1h-15min 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 entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
Can Stoch-RSI 4h-1h-15min 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 Stoch-RSI 4h-1h-15min use a stop loss?
Yes
strategy.exit sets a stop on line 181, 206.
Does Stoch-RSI 4h-1h-15min run in Zeal Terminal?
Yes
It compiles in 52 ms and runs 1,000 bars in 119 ms, in the browser.

BTCUSDT · 1D · default settings

  • CUM
  • EMA
  • EMA
  • EMA
  • SMA
  • SMA
  • SMA
  • RMA
  • RMA
  • SMA
  • SMA
  • SMA
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOctRSI$100$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. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. Zeal Terminal's engine currently reads an order side written as long = strategy.long, long = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 176, 201) 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 15, BINANCE:BTCUSDT 5, BINANCE:BTCUSDT 60, which this page cannot load in your browser.

Needs BINANCE:BTCUSDT 15 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Needs BINANCE:BTCUSDT 5 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Needs BINANCE:BTCUSDT 60 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, $100 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

    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 80

    transp = on line 80. v5 folds the transparency into the colour with color.new(c, transp).

  • Note

    Uses long =, which v5 renamed line 176

    long = on line 176, 201. 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 cum → ta.cum, change → ta.change, ema → ta.ema, rsi → ta.rsi, security → request.security, sma → ta.sma, rma → ta.rma, max → math.max, min → math.min, crossunder → ta.crossunder, crossover → ta.crossover, stoch → ta.stoch.

v4 → v5

Not verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 5: input(type = input.string) → input.string()
  • Line 7: input(type = input.string) → input.string()
  • Line 8: input(type = input.string) → input.string()
  • Line 9: input(type = input.string) → input.string()
  • Line 10: input(type = input.string) → input.string()
45 more edits
  • Line 15: input(type = input.resolution) → input.timeframe()
  • Line 20: cum → ta.cum
  • Line 20: change → ta.change
  • Line 21: ema → ta.ema
  • Line 22: rsi → ta.rsi
  • Line 23: ema → ta.ema
  • Line 24: ema → ta.ema
  • Line 25: security → request.security
  • Line 26: security → request.security
  • Line 32: sma → ta.sma
  • Line 32: ema → ta.ema
  • Line 33: sma → ta.sma
  • Line 33: ema → ta.ema
  • Line 35: security → request.security
  • Line 36: sma → ta.sma
  • Line 36: ema → ta.ema
  • Line 37: security → request.security
  • Line 80: transp = 85 → color.new(bothSignalsCombined != 0? sessioncolor:na, 85)
  • Line 82: input(type = input.resolution) → input.timeframe()
  • Line 90: rma → ta.rma
  • Line 90: max → math.max
  • Line 90: change → ta.change
  • Line 91: rma → ta.rma
  • Line 91: min → math.min
  • Line 91: change → ta.change
  • Line 93: security → request.security
  • Line 94: sma → ta.sma
  • Line 98: crossunder → ta.crossunder
  • Line 100: crossover → ta.crossover
  • Line 137: input(type = input.resolution) → input.timeframe()
  • Line 142: input(type = input.float) → input.float()
  • Line 143: input(type = input.float) → input.float()
  • Line 144: input(type = input.float) → input.float()
  • Line 145: input(type = input.float) → input.float()
  • Line 152: input(type = input.float) → input.float()
  • Line 153: input(type = input.float) → input.float()
  • Line 154: stoch → ta.stoch
  • Line 155: sma → ta.sma
  • Line 156: sma → ta.sma
  • Line 157: security → request.security
  • Line 158: security → request.security
  • Line 176: long = strategy.long → direction = strategy.long
  • Line 182: crossunder → ta.crossunder
  • Line 201: long = strategy.short → direction = strategy.short
  • Line 207: crossover → ta.crossover
⋯// © MoonFlag-//@version=4+//@version=5strategy(title="(Stoch/RSI/RVSI/MACD/TimeframeConfluence)", overlay=true, precision=2, initial_capital=100, commission_type=strategy.commission.percent, commission_value=0.07, default_qty_type = strategy.percent_of_equity, default_qty_value=100, pyramiding=1, calc_on_order_fills=false, calc_on_every_tick = false)-Pair      = input(title="Trading Pair (For reference only)",  type=input.string,  defval="DOGE")+Pair      = input.string(title="Trading Pair (For reference only)",  defval="DOGE")Wunderbit = input(title="Use strategy comments below (paste below for webhooks bots)",     defval=false)-Enter_Long     = input(title="Enter Long  ",  type=input.string,  defval="")+Enter_Long     = input.string(title="Enter Long  ",  defval="")-Exit_Long      = input(title="Exit Long   ",  type=input.string,  defval="")+Exit_Long      = input.string(title="Exit Long   ",  defval="")-Enter_Short    = input(title="Enter Short ",  type=input.string,  defval="")+Enter_Short    = input.string(title="Enter Short ",  defval="")-Exit_Short     = input(title="Exit Short  ",  type=input.string,  defval="")+Exit_Short     = input.string(title="Exit Short  ",  defval="")Longs   = input(title='Include Long  Trades', defval = true)⋯MACDonBuySell = true//input(title="MACDonBuySell", defval=true)-resolution    = input(title="MACD/RVSI Confluence Resolution", type=input.resolution, defval="15")+resolution    = input.timeframe(title="MACD/RVSI Confluence Resolution", defval="15")avl = 5⋯maSlow =10-nv = cum((change(close)) * volume)+nv = ta.cum((ta.change(close)) * volume)-av = ema(nv, avl)+av = ta.ema(nv, avl)-RVSI = rsi(av, l1)+RVSI = ta.rsi(av, l1)-xSlow = ema(RVSI, maSlow)+xSlow = ta.ema(RVSI, maSlow)-xFast = ema(RVSI, maFast)+xFast = ta.ema(RVSI, maFast)-xSlowR=security(syminfo.tickerid, resolution, xSlow)+xSlowR=request.security(syminfo.tickerid, resolution, xSlow)-xFastR=security(syminfo.tickerid, resolution, xFast)+xFastR=request.security(syminfo.tickerid, resolution, xFast)histRVSI_R = xFastR - xSlowR⋯sma_signal = false-fast_ma = sma_source ? sma(src, maFast) : ema(src, maFast)+fast_ma = sma_source ? ta.sma(src, maFast) : ta.ema(src, maFast)-slow_ma = sma_source ? sma(src, maSlow) : ema(src, maSlow)+slow_ma = sma_source ? ta.sma(src, maSlow) : ta.ema(src, maSlow)macd = fast_ma - slow_ma-macd_R = security(syminfo.tickerid, resolution, macd)+macd_R = request.security(syminfo.tickerid, resolution, macd)-signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)+signal = sma_signal ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)-signal_R = security(syminfo.tickerid, resolution, signal)+signal_R = request.security(syminfo.tickerid, resolution, signal)histMACD_R = macd_R - signal_R⋯    sellRVSIMACD := true//useMACDRVSI-bgcolor(bothSignalsCombined != 0? sessioncolor:na, title="MACD/RVSI Confluence", transp=85)+bgcolor(color.new(bothSignalsCombined != 0? sessioncolor:na, 85), title="MACD/RVSI Confluence")RSIclause    = input(title="RSI clause", defval=true)//, inline="RSI2", group="RSI2")-timeframeRSI = input(title="Timeframe RSI",  type=input.resolution,  defval="5" )+timeframeRSI = input.timeframe(title="Timeframe RSI",  defval="5" )rsi_Longs__Crossover   = 31//input(title="RSI Longs  Crossover  %", type=input.float, defval=31, maxval=100, minval=1, step=1)  // how much (percentage) can price fall before exiting the trade⋯RSIsmaLength2      = 3//input(title="RSI SMA Length", defval=3)//, inline="RSI2 sma", group="RSI2")-RSIup2   = rma(max(change(RSIsrc2), 0), RSIlength2)+RSIup2   = ta.rma(math.max(ta.change(RSIsrc2), 0), RSIlength2)-RSIdown2 = rma(-min(change(RSIsrc2), 0), RSIlength2)+RSIdown2 = ta.rma(-math.min(ta.change(RSIsrc2), 0), RSIlength2)RSI2     = RSIdown2 == 0 ? 100 : RSIup2 == 0 ? 0 : 100 - (100 / (1 + RSIup2 / RSIdown2))-RSIplot2 = security(syminfo.tickerid, timeframeRSI, RSI2[barstate.isrealtime ? 1 : 0], gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_off)[barstate.isrealtime ? 0 : 1]+RSIplot2 = request.security(syminfo.tickerid, timeframeRSI, RSI2[barstate.isrealtime ? 1 : 0], gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_off)[barstate.isrealtime ? 0 : 1]-RSIsma2  = sma(RSIplot2, RSIsmaLength2)+RSIsma2  = ta.sma(RSIplot2, RSIsmaLength2)var RSIprevious =0.⋯    RSIprevious:=-1-if crossunder (RSIsma2, rsi_Shorts_Crossunder) +if ta.crossunder (RSIsma2, rsi_Shorts_Crossunder)     RSIprevious:= -1-if crossover (RSIsma2, rsi_Longs__Crossover) +if ta.crossover (RSIsma2, rsi_Longs__Crossover)     RSIprevious:= 1⋯timeframe1 = timeframe.period//input(title="Fast Stoch Timeframe ",  type=input.resolution,  defval="15" )-timeframe2 = input(group="Stochastic",title="Slow Stoch Timeframe (should be approx 4X present timeframe",  type=input.resolution,  defval="60" )+timeframe2 = input.timeframe(group="Stochastic",title="Slow Stoch Timeframe (should be approx 4X present timeframe",  defval="60" )// get input ⋯i_d             = input(group="Stochastic", title="Stochastic %D", minval=1, defval=10)-i_sellThreshold_Longs  = input(group="Stochastic Buy/Sell", title="LONGS:  Stoch Sell/Close Threshold", type=input.float, defval=85.0, maxval=100, minval=0.0, step=5) +i_sellThreshold_Longs  = input.float(group="Stochastic Buy/Sell", title="LONGS:  Stoch Sell/Close Threshold", defval=85.0, maxval=100, minval=0.0, step=5) -i_buyThreshold_Longs   = input(group="Stochastic Buy/Sell", title="LONGS:  Stoch Buy/Open   Threshold", type=input.float, defval=40.0, maxval=100, minval=0.0, step=5) +i_buyThreshold_Longs   = input.float(group="Stochastic Buy/Sell", title="LONGS:  Stoch Buy/Open   Threshold", defval=40.0, maxval=100, minval=0.0, step=5) -i_sellThreshold_Shorts = input(group="Stochastic Buy/Sell", title="SHORTS: Stoch Sell/Close Threshold", type=input.float, defval=30.0, maxval=100, minval=0.0, step=5) +i_sellThreshold_Shorts = input.float(group="Stochastic Buy/Sell", title="SHORTS: Stoch Sell/Close Threshold", defval=30.0, maxval=100, minval=0.0, step=5) -i_buyThreshold_Shorts  = input(group="Stochastic Buy/Sell", title="SHORTS: Stoch Buy/Open   Threshold", type=input.float, defval=50.0, maxval=100, minval=0.0, step=5) +i_buyThreshold_Shorts  = input.float(group="Stochastic Buy/Sell", title="SHORTS: Stoch Buy/Open   Threshold", defval=50.0, maxval=100, minval=0.0, step=5) stopLossLine = input(group="Trade Settings",title='Ramp Stop Loss Line % per candle', step=0.01,defval = 0.15 )/100⋯stopLineLongLevel :=stopLineLongLevel[1]-i_trailStopPercent     = input(group="Trade Settings", title="Trailing Stop Percent", type=input.float, defval=3, maxval=100, minval=0.1, step=0.5)/100 +i_trailStopPercent     = input.float(group="Trade Settings", title="Trailing Stop Percent", defval=3, maxval=100, minval=0.1, step=0.5)/100 -i_takeProfit           = input(group="Trade Settings", title="Take Profit", type=input.float, defval=2.5, maxval=100, minval=0.1, step=0.5)/100  +i_takeProfit           = input.float(group="Trade Settings", title="Take Profit", defval=2.5, maxval=100, minval=0.1, step=0.5)/100  -sto = stoch(close, high, low, i_length)+sto = ta.stoch(close, high, low, i_length)-K   = sma(sto, i_k)+K   = ta.sma(sto, i_k)-D   = sma(K, i_d)+D   = ta.sma(K, i_d)-stoch_A        = security(syminfo.tickerid, timeframe1, D)+stoch_A        = request.security(syminfo.tickerid, timeframe1, D)-stoch_B        = security(syminfo.tickerid, timeframe2, D)+stoch_B        = request.security(syminfo.tickerid, timeframe2, D)stoch_A_upTrend      = stoch_A     >  stoch_A[1]⋯                    stopLineLongLevel :=long_stop_level-                    strategy.entry(id="Long", long=strategy.long, comment=BuyComment_Long)+                    strategy.entry(id="Long", direction = strategy.long, comment=BuyComment_Long)    if strategy.position_size > 0⋯        strategy.exit(id="Long", stop=trailStop, comment=SellCommentTrailStopLoss_Long)     //if (D[1] >= 80) and (D < 80)     //    strategy.close(id="Long", comment=SellCommentTrend)-        if crossunder(stoch_A, i_sellThreshold_Longs) // and barstate.isconfirmed and strategy.position_size > 0+        if ta.crossunder(stoch_A, i_sellThreshold_Longs) // and barstate.isconfirmed and strategy.position_size > 0            strategy.close(id="Long", comment=SellCommentTrend_Long)⋯                    stopLineLongLevel :=long_stop_level-                    strategy.entry(id="Short", long=strategy.short, comment=BuyComment_Short)+                    strategy.entry(id="Short", direction = strategy.short, comment=BuyComment_Short)    if strategy.position_size < 0⋯        strategy.exit(id="Short", stop=trailStop, comment=SellCommentTrailStopLoss_Short)-        if crossover(stoch_A, (i_sellThreshold_Shorts))+        if ta.crossover(stoch_A, (i_sellThreshold_Shorts))            strategy.close(id="Short", comment=SellCommentTrend_Short)⋯

Clean v5

Not verified

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

  • Line 6: input() → input.bool()
  • Line 11: input() → input.bool()
  • Line 12: input() → input.bool()
  • Line 13: input() → input.bool()
  • Line 81: input() → input.bool()
  • Line 139: input() → input.int()
4 more edits
  • Line 140: input() → input.int()
  • Line 141: input() → input.int()
  • Line 146: input() → input.float()
  • Line 147: input() → input.float()
⋯Pair      = input.string(title="Trading Pair (For reference only)",  defval="DOGE")-Wunderbit = input(title="Use strategy comments below (paste below for webhooks bots)",     defval=false)+Wunderbit = input.bool(title="Use strategy comments below (paste below for webhooks bots)",     defval=false)Enter_Long     = input.string(title="Enter Long  ",  defval="")⋯Exit_Short     = input.string(title="Exit Short  ",  defval="")-Longs   = input(title='Include Long  Trades', defval = true)+Longs   = input.bool(title='Include Long  Trades', defval = true)-Shorts  = input(title='Include Short Trades', defval = true)+Shorts  = input.bool(title='Include Short Trades', defval = true)-useMACDRVSI   = input(title="Use MACD/RVSI", defval=true)+useMACDRVSI   = input.bool(title="Use MACD/RVSI", defval=true)MACDonBuySell = true//input(title="MACDonBuySell", defval=true)⋯bgcolor(color.new(bothSignalsCombined != 0? sessioncolor:na, 85), title="MACD/RVSI Confluence")-RSIclause    = input(title="RSI clause", defval=true)//, inline="RSI2", group="RSI2")+RSIclause    = input.bool(title="RSI clause", defval=true)//, inline="RSI2", group="RSI2")timeframeRSI = input.timeframe(title="Timeframe RSI",  defval="5" )⋯// get input -i_length        = input(group="Stochastic", title="Stochastic Length", minval=1, defval=18)                                     +i_length        = input.int(group="Stochastic", title="Stochastic Length", minval=1, defval=18)                                     -i_k             = input(group="Stochastic", title="Stochastic %K", minval=1, defval=2)+i_k             = input.int(group="Stochastic", title="Stochastic %K", minval=1, defval=2)-i_d             = input(group="Stochastic", title="Stochastic %D", minval=1, defval=10)+i_d             = input.int(group="Stochastic", title="Stochastic %D", minval=1, defval=10)i_sellThreshold_Longs  = input.float(group="Stochastic Buy/Sell", title="LONGS:  Stoch Sell/Close Threshold", defval=85.0, maxval=100, minval=0.0, step=5) ⋯i_buyThreshold_Shorts  = input.float(group="Stochastic Buy/Sell", title="SHORTS: Stoch Buy/Open   Threshold", defval=50.0, maxval=100, minval=0.0, step=5) -stopLossLine = input(group="Trade Settings",title='Ramp Stop Loss Line % per candle', step=0.01,defval = 0.15 )/100+stopLossLine = input.float(group="Trade Settings",title='Ramp Stop Loss Line % per candle', step=0.01,defval = 0.15 )/100-long_sl_inp  = input(group="Trade Settings",title='Ramp Stop Loss Start %'          , step=0.1 ,defval = 3.5 )/100+long_sl_inp  = input.float(group="Trade Settings",title='Ramp Stop Loss Start %'          , step=0.1 ,defval = 3.5 )/100long_stop_level =0.0⋯

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.

⋯// © MoonFlag-//@version=5+//@version=6strategy(title="(Stoch/RSI/RVSI/MACD/TimeframeConfluence)", overlay=true, precision=2, initial_capital=100, commission_type=strategy.commission.percent, commission_value=0.07, default_qty_type = strategy.percent_of_equity, default_qty_value=100, pyramiding=1, calc_on_order_fills=false, calc_on_every_tick = false)⋯

Settings

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

SettingDefaultType and rangeFeeds
Trading Pair (For reference only)DOGEstringBuyComment_Long BuyComment_Short
Use strategy comments below (paste below for webhooks bots)falseboolline 125
Enter Long stringBuyComment_Long
Exit Long stringSellCommentTP_Long
Enter Short stringBuyComment_Short
Exit Short stringSellCommentTP_Short
Include Long Tradestrueboolline 166
Include Short Tradestrueboolline 191
Use MACD/RVSItrueboolentry Long entry Short line 170 line 195
MACD/RVSI Confluence Resolution15timeframe (written input.resolution)xSlowR xFastR macd_R signal_R
RSI clausetrueboolline 106 line 108 line 110
Timeframe RSI5timeframe (written input.resolution)RSIplot2
Stochastic
Slow Stoch Timeframe (should be approx 4X present timeframe60timeframe (written input.resolution)stoch_B
Stochastic Length18int · min 1sto
Stochastic %K2int · min 1K
Stochastic %D10int · min 1D
Stochastic Buy/Sell
LONGS: Stoch Sell/Close Threshold85.0float · min 0.0 · max 100 · step 5close Long line 182
LONGS: Stoch Buy/Open Threshold40.0float · min 0.0 · max 100 · step 5line 168
SHORTS: Stoch Sell/Close Threshold30.0float · min 0.0 · max 100 · step 5close Short line 207
SHORTS: Stoch Buy/Open Threshold50.0float · min 0.0 · max 100 · step 5line 193
Trade Settings
Ramp Stop Loss Line % per candle0.15float · step 0.01stopLineLongLevel
Ramp Stop Loss Start %3.5float · step 0.1long_stop_level
Trailing Stop Percent3float · min 0.1 · max 100 · step 0.5trailStop
Take Profit2.5float · min 0.1 · max 100 · step 0.5close Long close Short line 184 line 209

What it calculates

  • CUM / Change (cum, ta.cum in v5)(change(close)) * volumenv · line 20
  • EMA (ema, ta.ema in v5)nv, avlav · line 21
  • RSI (rsi, ta.rsi in v5)av, l1RVSI · line 22
  • EMA (ema, ta.ema in v5)RVSI, maSlowxSlow · line 23
  • EMA (ema, ta.ema in v5)RVSI, maFastxFast · line 24
  • SMA / EMA (sma, ta.sma in v5)src, maFastfast_ma · line 32
  • SMA / EMA (sma, ta.sma in v5)src, maSlowslow_ma · line 33
  • SMA / EMA (sma, ta.sma in v5)macd, signal_lengthsignal · line 36
  • RMA / Change (rma, ta.rma in v5)max(change(RSIsrc2), 0), RSIlength2RSIup2 · line 90
  • RMA / Change (rma, ta.rma in v5)-min(change(RSIsrc2), 0), RSIlength2RSIdown2 · line 91
  • SMA (sma, ta.sma in v5)RSIplot2, RSIsmaLength2RSIsma2 · line 94
  • Stoch (stoch, ta.stoch in v5)close, high, low, Stochastic Length (18)sto · line 154
  • SMA (sma, ta.sma in v5)sto, Stochastic %K (2)K · line 155
  • SMA (sma, ta.sma in v5)K, Stochastic %D (10)D · line 156

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

Order rules

OrderFires whenBy defaultLine
Open Long longuseMACDRVSI==false or (MACDonBuySell?buyRVSIMACD:(not sellRVSIMACD))On176
Exit Long stopstrategy.position_size > 0On181
Close Longcrossunder(stoch_A, i_sellThreshold_Longs)On183
Close Longclose > (entryPrice * (1+i_takeProfit))On185
Close Longclose < stopLineLongLevelOn189
Open Short shortuseMACDRVSI==false or (MACDonBuySell?sellRVSIMACD:(not buyRVSIMACD))On201
Exit Short stopstrategy.position_size < 0On206
Close Shortcrossover(stoch_A, (i_sellThreshold_Shorts))On208
Close Shortclose < (entryPrice * (1-i_takeProfit))On210
Close Shortclose > stopLineLongLevelOn213

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 measuredAn engine gap, not the scriptThe script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script. The answer comes from the checks on the source alone.
  • ClearHigher-timeframe data7 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 15, BINANCE:BTCUSDT 5, BINANCE:BTCUSDT 60, 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; 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
Stoch-RSI 4h-1h-15min this page—v4 strategy0.0%00.0%
Full CRYPTO pack macd, rsi, obv, ema strategy by SoftKill21ema sma rsi cumv4 strategyNo trades on this market
Kahlman HullMA - WT Cross Strategy by pigsqema sma rsi rmav5 strategy+1.0%5433.3%
RSI Mean Reversion Bot Strategy by Solutions1978rsi ema stoch smav4 strategyNo trades on this market
MACD, RSI, & RVOL Strategy by BobBarker42069rsi ema smav4 strategy+32.6%11.5%
IFR2 - RSI2 by jocker.soadrsi sma emav4 strategyNo trades on this market

Where it runs

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

Zeal Terminal's engine currently reads an order side written as long = strategy.long, long = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 176, 201) 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/// © MoonFlag//@version=4strategy(title="(Stoch/RSI/RVSI/MACD/TimeframeConfluence)", overlay=true, precision=2, initial_capital=100, commission_type=strategy.commission.percent, commission_value=0.07, default_qty_type = strategy.percent_of_equity, default_qty_value=100, pyramiding=1, calc_on_order_fills=false, calc_on_every_tick = false)Pair      = input(title="Trading Pair (For reference only)",  type=input.string,  defval="DOGE")Wunderbit = input(title="Use strategy comments below (paste below for webhooks bots)",     defval=false)Enter_Long     = input(title="Enter Long  ",  type=input.string,  defval="")Exit_Long      = input(title="Exit Long   ",  type=input.string,  defval="")Enter_Short    = input(title="Enter Short ",  type=input.string,  defval="")Exit_Short     = input(title="Exit Short  ",  type=input.string,  defval="")Longs   = input(title='Include Long  Trades', defval = true)Shorts  = input(title='Include Short Trades', defval = true)useMACDRVSI   = input(title="Use MACD/RVSI", defval=true)MACDonBuySell = true//input(title="MACDonBuySell", defval=true)resolution    = input(title="MACD/RVSI Confluence Resolution", type=input.resolution, defval="15")avl = 5l1  = 10maFast =3maSlow =10nv = cum((change(close)) * volume)av = ema(nv, avl)RVSI = rsi(av, l1)xSlow = ema(RVSI, maSlow)xFast = ema(RVSI, maFast)xSlowR=security(syminfo.tickerid, resolution, xSlow)xFastR=security(syminfo.tickerid, resolution, xFast)histRVSI_R = xFastR - xSlowRsrc = closesignal_length = 9sma_source = falsesma_signal = falsefast_ma = sma_source ? sma(src, maFast) : ema(src, maFast)slow_ma = sma_source ? sma(src, maSlow) : ema(src, maSlow)macd = fast_ma - slow_mamacd_R = security(syminfo.tickerid, resolution, macd)signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)signal_R = security(syminfo.tickerid, resolution, signal)histMACD_R = macd_R - signal_Rvar maxMACD =0.var maxRVSI =0.var minMACD =0.var minRVSI =0.if (maxRVSI < histRVSI_R)    maxRVSI := histRVSI_Rif (minRVSI > histRVSI_R)    minRVSI := histRVSI_Rif (maxMACD < histMACD_R)    maxMACD := histMACD_Rif (minMACD > histMACD_R)    minMACD := histMACD_Rif maxRVSI < -1*minRVSI    maxRVSI := -1*minRVSIif maxMACD < -1*minMACD    maxMACD := -1*minMACDbothSameSign = falseif ((histRVSI_R * histMACD_R) > 0)    bothSameSign := truebothSignalsCombined = bothSameSign?(((histRVSI_R/maxRVSI)+(histMACD_R/maxMACD))/2):navar maxBoth =0.var minBoth =0.if (maxBoth < bothSignalsCombined)    maxBoth := bothSignalsCombinedif (minBoth > bothSignalsCombined)    minBoth := bothSignalsCombinedif maxBoth < -1*minBoth    maxBoth := -1*minBothbuyBackground = color.greenregular = #0000FFsellBackground = color.red color notrading = nasessioncolor = regularbuyRVSIMACD = falsesellRVSIMACD = falseif (bothSignalsCombined > 0)    sessioncolor := buyBackground    buyRVSIMACD := true//useMACDRVSIif (bothSignalsCombined < 0)    sessioncolor := sellBackground    sellRVSIMACD := true//useMACDRVSIbgcolor(bothSignalsCombined != 0? sessioncolor:na, title="MACD/RVSI Confluence", transp=85)RSIclause    = input(title="RSI clause", defval=true)//, inline="RSI2", group="RSI2")timeframeRSI = input(title="Timeframe RSI",  type=input.resolution,  defval="5" )rsi_Longs__Crossover   = 31//input(title="RSI Longs  Crossover  %", type=input.float, defval=31, maxval=100, minval=1, step=1)  // how much (percentage) can price fall before exiting the tradersi_Shorts_Crossunder  = 69//input(title="RSI Shorts Crossunder %", type=input.float, defval=69, maxval=100, minval=1, step=1)  // how much (percentage) can price fall before exiting the tradeuseRSI2            = trueRSItimeframe2chart = falseRSIlength2         = 14//input(title="Length RSI", defval=14)//, inline="RSI2", group="RSI2")RSIsrc2            = closeRSIsmaLength2      = 3//input(title="RSI SMA Length", defval=3)//, inline="RSI2 sma", group="RSI2")RSIup2   = rma(max(change(RSIsrc2), 0), RSIlength2)RSIdown2 = rma(-min(change(RSIsrc2), 0), RSIlength2)RSI2     = RSIdown2 == 0 ? 100 : RSIup2 == 0 ? 0 : 100 - (100 / (1 + RSIup2 / RSIdown2))RSIplot2 = security(syminfo.tickerid, timeframeRSI, RSI2[barstate.isrealtime ? 1 : 0], gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_off)[barstate.isrealtime ? 0 : 1]RSIsma2  = sma(RSIplot2, RSIsmaLength2)var RSIprevious =0.if RSIprevious == 0.    RSIprevious:=-1if crossunder (RSIsma2, rsi_Shorts_Crossunder)     RSIprevious:= -1if crossover (RSIsma2, rsi_Longs__Crossover)     RSIprevious:= 1var RSIonUpwards = falsevar RSIonDownwards = falseRSIonUpwards  := falseRSIonDownwards := falseif RSIclause and RSIprevious ==  1    RSIonUpwards := trueif RSIclause and RSIprevious == -1    RSIonDownwards := trueif not RSIclause    RSIonUpwards   := true    RSIonDownwards := truelookback1     = 4//input(title="lookback 1",  type=input.integer,  defval=4)lookback2     = 8//input(title="lookback 2",  type=input.integer,  defval=8)BuyComment_Long                 = Pair + " Long"BuyComment_Short                = Pair + " Short"SellCommentTP_Long              = "Take Profit"SellCommentTP_Short             = "Take Profit"SellCommentTrend_Long           = "Trend Shift"SellCommentTrend_Short          = "Trend Shift"SellCommentTrailStopLoss_Long   = "Trail StopLoss"SellCommentTrailStopLoss_Short  = "Trail StopLoss"SellCommentRisingStopLoss_Long  = "Ramp StopLoss"SellCommentRisingStopLoss_Short = "Ramp StopLoss"if Wunderbit    BuyComment_Long       := Enter_Long    SellCommentTP_Long    := Exit_Long    BuyComment_Short      := Enter_Short    SellCommentTP_Short   := Exit_Short    SellCommentTrend_Long           := SellCommentTP_Long    SellCommentTrailStopLoss_Long   := SellCommentTP_Long    SellCommentRisingStopLoss_Long  := SellCommentTP_Long    SellCommentTrend_Short          := SellCommentTP_Short    SellCommentTrailStopLoss_Short  := SellCommentTP_Short    SellCommentRisingStopLoss_Short := SellCommentTP_Shorttimeframe1 = timeframe.period//input(title="Fast Stoch Timeframe ",  type=input.resolution,  defval="15" )timeframe2 = input(group="Stochastic",title="Slow Stoch Timeframe (should be approx 4X present timeframe",  type=input.resolution,  defval="60" )// get input i_length        = input(group="Stochastic", title="Stochastic Length", minval=1, defval=18)                                     i_k             = input(group="Stochastic", title="Stochastic %K", minval=1, defval=2)i_d             = input(group="Stochastic", title="Stochastic %D", minval=1, defval=10)i_sellThreshold_Longs  = input(group="Stochastic Buy/Sell", title="LONGS:  Stoch Sell/Close Threshold", type=input.float, defval=85.0, maxval=100, minval=0.0, step=5) i_buyThreshold_Longs   = input(group="Stochastic Buy/Sell", title="LONGS:  Stoch Buy/Open   Threshold", type=input.float, defval=40.0, maxval=100, minval=0.0, step=5) i_sellThreshold_Shorts = input(group="Stochastic Buy/Sell", title="SHORTS: Stoch Sell/Close Threshold", type=input.float, defval=30.0, maxval=100, minval=0.0, step=5) i_buyThreshold_Shorts  = input(group="Stochastic Buy/Sell", title="SHORTS: Stoch Buy/Open   Threshold", type=input.float, defval=50.0, maxval=100, minval=0.0, step=5) stopLossLine = input(group="Trade Settings",title='Ramp Stop Loss Line % per candle', step=0.01,defval = 0.15 )/100long_sl_inp  = input(group="Trade Settings",title='Ramp Stop Loss Start %'          , step=0.1 ,defval = 3.5 )/100long_stop_level =0.0long_stop_level :=long_stop_level[1]stopLineLongLevel = 0.stopLineLongLevel :=stopLineLongLevel[1]i_trailStopPercent     = input(group="Trade Settings", title="Trailing Stop Percent", type=input.float, defval=3, maxval=100, minval=0.1, step=0.5)/100 i_takeProfit           = input(group="Trade Settings", title="Take Profit", type=input.float, defval=2.5, maxval=100, minval=0.1, step=0.5)/100  sto = stoch(close, high, low, i_length)K   = sma(sto, i_k)D   = sma(K, i_d)stoch_A        = security(syminfo.tickerid, timeframe1, D)stoch_B        = security(syminfo.tickerid, timeframe2, D)stoch_A_upTrend      = stoch_A     >  stoch_A[1]stoch_A_downTrend    = stoch_A     <  stoch_A[1]stoch_B_upTrend      = (stoch_B[lookback1] >= stoch_B[lookback2])stoch_B_downTrend    = (stoch_B[lookback1] <= stoch_B[lookback2])var recentHigh  = 0.0var entryPrice    = 0.0var trailStop   = 0.0if Longs and barstate.isconfirmed    if strategy.position_size == 0        if (stoch_A < i_buyThreshold_Longs) and stoch_A_upTrend and stoch_B_upTrend             if RSIonUpwards                 if useMACDRVSI==false or (MACDonBuySell?buyRVSIMACD:(not sellRVSIMACD))                    entryPrice   := close                       recentHigh   := close                    trailStop    := (close * (1-i_trailStopPercent))                    long_stop_level := entryPrice * (1 - long_sl_inp)                    stopLineLongLevel :=long_stop_level                    strategy.entry(id="Long", long=strategy.long, comment=BuyComment_Long)    if strategy.position_size > 0        if close > recentHigh             recentHigh := close            trailStop  := (recentHigh * (1-i_trailStopPercent))        strategy.exit(id="Long", stop=trailStop, comment=SellCommentTrailStopLoss_Long)     //if (D[1] >= 80) and (D < 80)     //    strategy.close(id="Long", comment=SellCommentTrend)        if crossunder(stoch_A, i_sellThreshold_Longs) // and barstate.isconfirmed and strategy.position_size > 0            strategy.close(id="Long", comment=SellCommentTrend_Long)        if close > (entryPrice * (1+i_takeProfit)) //and barstate.isconfirmed and strategy.position_size > 0            strategy.close(id="Long", comment=SellCommentTP_Long)        //if strategy.position_size > 0        stopLineLongLevel := stopLineLongLevel* (1+ stopLossLine)        if close < stopLineLongLevel //and barstate.isconfirmed and strategy.position_size > 0            strategy.close(id="Long", comment=SellCommentRisingStopLoss_Long )//elseif Shorts and barstate.isconfirmed     if strategy.position_size == 0        if (stoch_A > i_buyThreshold_Shorts) and stoch_A_downTrend and stoch_B_downTrend             if RSIonDownwards                 if useMACDRVSI==false or (MACDonBuySell?sellRVSIMACD:(not buyRVSIMACD))                     entryPrice   := close                       recentHigh   := close                    trailStop    := (close * (1+i_trailStopPercent))                    long_stop_level := entryPrice * (1 + long_sl_inp)                    stopLineLongLevel :=long_stop_level                    strategy.entry(id="Short", long=strategy.short, comment=BuyComment_Short)    if strategy.position_size < 0        if close < recentHigh             recentHigh := close            trailStop  := (recentHigh * (1+i_trailStopPercent))        strategy.exit(id="Short", stop=trailStop, comment=SellCommentTrailStopLoss_Short)        if crossover(stoch_A, (i_sellThreshold_Shorts))            strategy.close(id="Short", comment=SellCommentTrend_Short)        if close < (entryPrice * (1-i_takeProfit))             strategy.close(id="Short", comment=SellCommentTP_Short)        stopLineLongLevel := stopLineLongLevel* (1 - stopLossLine)        if close > stopLineLongLevel             strategy.close(id="Short", comment=SellCommentRisingStopLoss_Short )plot(strategy.position_size != 0 ? stopLineLongLevel : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Ramp StopLoss")//plot(K, title="%K", color=color.blue, linewidth=1)//plot(stoch_A, title="Stoch A", color=color.orange, linewidth=1)//plot(stoch_B, title="Stoch B", color= stoch_B_upTrend ? color.green : color.red, style=plot.style_stepline)//upperBand  = hline(i_sellThreshold, title="Upper Limit", linestyle=hline.style_dashed)//middleBand = hline(50, title="Midline", linestyle=hline.style_dotted)//lowerBand  = hline(i_buyThreshold, title="Lower Limit", linestyle=hline.style_dashed)//fill(lowerBand, upperBand, color=color.purple, transp=75)//bgC = color.black//if strategy.position_size != 0//    bgC := color.green//bgcolor(bgC)